Better syntax when using shared resources in SwiftUI #751
alobaili
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone,
I wanted to share a technique to make using moko resources in SwiftUI more readable using Swift's
KeyPath
.I created this Swift file in my iOS project to contain the helper code, currently I'm only using strings and colors, I can already see myself using these a helper file like this in all my projects.
I'm assuming that the shared module is called
shared
and the resources module is calledSharedRes
.KMPHelpers.swift
This will allow you to initialize
Text
and use theforegroundStyle
or any modifier that takeShapeStyle
by passing aKeyPath
to the string or color resource. You don't even have to importshared
!Let me know what you think! Can we somehow expand this or integrate it in mako-resources so that everyone can have convenience helpers similar to this? Otherwise, feel free to share any helper code that can make using moko-resources in SwiftUI more readable.
Beta Was this translation helpful? Give feedback.
All reactions