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 SampleView: View { | |
var texts = ["SwiftUI", "A new declarative UI framework", "Let us try to understand how SwiftUI renders its views"] | |
@State var selected = 0 | |
@State var textFieldValue = "" | |
@State var isSwitchOn = false | |
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 Foundation | |
public protocol Imitable: Codable { | |
var copy: Self? { get } | |
} | |
extension Imitable { | |
public var copy: Self? { | |
guard let data = try? JSONEncoder().encode(self) else { return nil } | |
return try? JSONDecoder().decode(Self.self, from: data) |
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 Foundation | |
public extension Equatable where Self: Codable { | |
static func ==(lhs: Self, rhs: Self) -> Bool { | |
lhs.jsonData == rhs.jsonData | |
} | |
} | |
public extension Person: Equatable { } |
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 | |
// import Introspect | |
public struct PasscodeField: View { | |
var maxDigits: Int = 4 | |
var label = "Enter One Time Password" | |
@State var pin: String = "" | |
@State var showPin = false |
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
@objc class SuperClassA: NSObject { | |
public required override init() { } | |
public static var shared: SuperClassA { | |
if let instance = _shared { | |
return instance | |
} | |
return instance |
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 | |
/// An iOS style TabView that doesn't reset it's childrens navigation stacks when tabs are switched. | |
struct UIKitTabView: View { | |
var viewControllers: [UIHostingController<AnyView>] | |
@State var selectedIndex: Int = 0 | |
init(_ views: [Tab]) { | |
self.viewControllers = views.map { | |
let host = UIHostingController(rootView: $0.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
class UserSettings: ObservableObject { | |
@Published var score = 0 | |
} | |
struct ContentView: View { | |
@EnvironmentObject var settings: UserSettings | |
var body: some View { | |
NavigationView { | |
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
class UserSettings: ObservableObject { | |
private init() { } | |
static let shared = UserSettings() | |
@Published var score = 0 | |
} |
OlderNewer