This file contains 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 ComposableArchitecture | |
enum ViewState { | |
case initial | |
case loading | |
case success | |
case failure(any Error) | |
} |
This file contains 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 loggedIn: Bool = false | |
var body: some View { | |
switch loggedIn { | |
case false: | |
Button("Login") { | |
loggedIn = true |
This file contains 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 UIKit | |
class MyCollectionViewCell: UICollectionViewCell { | |
let label: UILabel = UILabel() | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
contentView.addSubview(label) |
This file contains 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
/// This was inspired by this... https://www.swiftbysundell.com/articles/type-safe-identifiers-in-swift/ | |
/// I wanted to try and find a way to have a type safe identifier that also allowed conformance to Identifiable | |
import Foundation | |
struct Identifier<Subject: Identified>: Hashable { | |
let value: Subject.IdentifierType | |
init(_ value: Subject.IdentifierType) { | |
self.value = value |
This file contains 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
/// This was inspired by this... https://www.swiftbysundell.com/articles/type-safe-identifiers-in-swift/ | |
/// I wanted to try and find a way to have a type safe identifier that also allowed conformance to Identifiable | |
import Foundation | |
struct Identifier<Subject: Identified>: Hashable { | |
let value: Subject.IdentifierType | |
init(_ value: Subject.IdentifierType) { | |
self.value = value |
This file contains 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
enum Foo<Wrapped> { | |
case no | |
case yes(Wrapped) | |
} | |
extension Foo: ExpressibleByNilLiteral { | |
init(nilLiteral: ()) { | |
self = .no | |
} | |
} |
This file contains 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 ComposableArchitecture | |
struct SearchableState: Equatable { | |
var searchText = "" | |
var names = ["Oliver", "Emily", "Jessica", "Dan", "Eva"] | |
var searchResults: [String] { | |
if searchText.isEmpty { | |
return names |
This file contains 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 | |
import SwiftUI | |
class SearchableViewModel: ObservableObject { | |
let names = ["Oliver", "Emily", "Jessica", "Daniel", "Eva"] | |
@Published var searchText: String = "" | |
var searchResults: [String] { | |
if searchText.isEmpty { |
This file contains 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 | |
import SwiftUI | |
struct VanillaSearchableView: View { | |
let names = ["Oliver", "Emily", "Jessica", "Daniel", "Eva"] | |
@State var searchText: String = "" | |
var body: some View { | |
NavigationView { | |
List { |
This file contains 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 UIKit | |
class BuyButton: UIView { | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
//MARK: - View | |
backgroundColor = UIColor(red: 180/255, green: 35/255, blue: 115/255, alpha: 1) | |
layer.cornerRadius = 3 |
NewerOlder