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 Array where Element: CodingKey { | |
| var keyPath: String { | |
| return map { $0.intValue == nil ? $0.stringValue : "[\($0.intValue!)]" } | |
| .joined(separator: ".") | |
| .replacingOccurrences(of: ".[", with: "[") | |
| } | |
| } |
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 ContentView: View { | |
| @State private var currentIndex = 0 | |
| private let colors: [Color] = [.red, .white, .blue, .green, .yellow] | |
| private var whiteIsSelected: Bool { | |
| colors[currentIndex] == .white | |
| } | |
| var body: some View { |
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
| @main | |
| struct MyApp: App { | |
| enum Sheet { case first, second } | |
| @State var sheet: Sheet? = nil | |
| var body: some Scene { | |
| WindowGroup { | |
| VStack { | |
| Button("First") { sheet = .first } |
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
| # Created by https://www.toptal.com/developers/gitignore/api/swiftpackagemanager,swift,xcode,macos | |
| # Edit at https://www.toptal.com/developers/gitignore?templates=swiftpackagemanager,swift,xcode,macos | |
| ### macOS ### | |
| # General | |
| .DS_Store | |
| .AppleDouble | |
| .LSOverride |
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
| class UploadTaskPublisher { | |
| typealias UploadProgress = (bytesSent: Int64, expectedTotalBytes: Int64) | |
| typealias ProgressSubject = CurrentValueSubject<UploadProgress, Never> | |
| typealias CompletionSubject = PassthroughSubject<URLSession.DataTaskPublisher.Output, URLSession.DataTaskPublisher.Failure> | |
| var progress = ProgressSubject((0, 0)) | |
| var completion = CompletionSubject() | |
| } |
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
| // Original article here: https://www.fivestars.blog/code/section-title-index-swiftui.html | |
| import SwiftUI | |
| let database: [String: [String]] = [ | |
| "iPhone": [ | |
| "iPhone", "iPhone 3G", "iPhone 3GS", "iPhone 4", "iPhone 4S", "iPhone 5", "iPhone 5C", "iPhone 5S", "iPhone 6", "iPhone 6 Plus", "iPhone 6S", "iPhone 6S Plus", "iPhone SE", "iPhone 7", "iPhone 7 Plus", "iPhone 8", "iPhone 8 Plus", "iPhone X", "iPhone Xs", "iPhone Xs Max", "iPhone Xʀ", "iPhone 11", "iPhone 11 Pro", "iPhone 11 Pro Max", "iPhone SE 2" | |
| ], | |
| "iPad": [ | |
| "iPad", "iPad 2", "iPad 3", "iPad 4", "iPad 5", "iPad 6", "iPad 7", "iPad Air", "iPad Air 2", "iPad Air 3", "iPad Mini", "iPad Mini 2", "iPad Mini 3", "iPad Mini 4", "iPad Mini 5", "iPad Pro 9.7-inch", "iPad Pro 10.5-inch", "iPad Pro 11-inch", "iPad Pro 11-inch 2", "iPad Pro 12.9-inch", "iPad Pro 12.9-inch 2", "iPad Pro 12.9-inch 3", "iPad Pro 12.9-inch 4" |
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 KeypadCell: View { | |
| let key: String | |
| var body: some View { | |
| ZStack { | |
| Color.primary.opacity(0.1) | |
| .cornerRadius(12) | |
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 ContentView: View { | |
| @State var selectedIndex: Int? = nil | |
| let options: [String] = ["Option1", "Option2"] | |
| var body: some View { | |
| PickerField("Select an option", data: self.options, selectionIndex: self.$selectedIndex) | |
| } | |
| } |
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 | |
| let colors = [ | |
| Color.pink, | |
| Color.blue, | |
| Color.green, | |
| Color.orange, | |
| Color.purple, | |
| Color.black, | |
| ] |