This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension View { | |
| func withoutAnimation(action: @escaping () -> Void) { | |
| var transaction = Transaction() | |
| transaction.disablesAnimations = true | |
| withTransaction(transaction) { | |
| action() | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let formatter = ISO8601DateFormatter() | |
| // formatter.locale = Locale(identifier: "ko_KR") | |
| let date = formatter.date(from: "2022-06-14T10:44:00+0000")! | |
| date.formatted(.relative(presentation: .named)) // "yesterday", "2 days ago", "last week", "next week" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let formatter = PersonNameComponentsFormatter() | |
| // formatter.locale = Locale(identifier: "ko_KR") | |
| var components = PersonNameComponents() | |
| components.familyName = "Doe" | |
| components.givenName = "John" | |
| formatter.string(from: components) // "John Doe" for "en_GB" locale, but "Doe John" for "ko_KR" locale. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let formatter = LengthFormatter() | |
| formatter.numberFormatter.locale = Locale(identifier: "en_US") // Forcing a locale here just as an example. | |
| formatter.numberFormatter.maximumFractionDigits = 0 | |
| formatter.isForPersonHeightUse = true | |
| let height = Measurement<UnitLength>(value: 190, unit: .centimeters) // Use whichever unit you like here. | |
| let meters = height.converted(to: .meters) | |
| formatter.string(fromMeters: meters.value) // "6 ft, 3 in" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct RoundedCornerTestView: View { | |
| var body: some View { | |
| Rectangle() | |
| .frame(width: 100, height: 100) | |
| .cornerRadius(12, corners: [.bottomLeft, .bottomRight]) | |
| .foregroundColor(Color.red) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct L10nTestView: View { | |
| @EnvironmentObject var l10n: L10n | |
| let titleKey = "title_key" | |
| let nameKey = "name_key_%@" | |
| var body: some View { | |
| VStack { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct TestView: View { | |
| var body: some View { | |
| UIKitView<UILabel> { | |
| $0.numberOfLines = 0 | |
| $0.lineBreakMode = .byWordWrapping | |
| $0.preferredMaxLayoutWidth = 340 | |
| $0.text = "Test UIKitView UILabel" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .onScenePhaseChange(phase: .background) { | |
| // Do something when the app enters the background. | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// The build number of the app. | |
| var buildNumber: Int { | |
| Int(Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "0")! | |
| } | |
| /// The version string of the app, for example: "1.0.2" | |
| var versionNumber: String { | |
| Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @AppStorage("saved_array") var savedArray = ArrayTypeToSave() | |
| savedArray = ["Hello", "World"] |