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
class HomeViewModel { | |
let isLoadingData: Driver<Bool> | |
let disposeBag = DisposeBag() | |
func doSomething() { ... } | |
} | |
class HomeViewController: UIViewController { | |
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
// Main target | |
class EnvObj: ObservableObject { | |
@Published var str: String | |
init(str: String) { | |
_str = .init(initialValue: str) | |
} | |
} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" | |
"http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>com.rsync.backup</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>open</string> |
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
protocol BinaryEquatable: Equatable { } | |
extension BinaryEquatable { | |
static func == (lhs: Self, rhs: Self) -> Bool { | |
withUnsafeBytes(of: lhs) { lhsBytes -> Bool in | |
withUnsafeBytes(of: rhs) { rhsBytes -> Bool in | |
lhsBytes.elementsEqual(rhsBytes) | |
} | |
} | |
} |
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
struct UIKitTestView: UIViewRepresentable { | |
typealias UpdateContext = UIViewRepresentableContext<UIKitTestView> | |
@Binding var flag: Bool | |
internal var didUpdate: () -> Void | |
func makeUIView(context: UpdateContext) -> UIView { | |
return UIView() | |
} |
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
struct DummyListRepository: ListRepository { | |
func loadList(completion: @escaping ([Item], Error?) -> Void) { | |
DispatchQueue.main.async { | |
let list = [ | |
Item(id: "1", name: "First item"), | |
Item(id: "2", name: "Second item") | |
] | |
completion(list, nil) | |
} | |
} |
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
struct RealListRepository: ListRepository { | |
func loadList(completion: @escaping ([Item], Error?) -> Void) { | |
// networking code | |
} | |
} |
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
protocol ListRepository { | |
func loadList(completion: @escaping ([Item], Error?) -> Void) | |
} |
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
class ListViewController: UIViewController { | |
var items: [Item] = [] | |
var tableView: UITableView? | |
override func viewDidLoad() { | |
let url = URL(string: "https://api.service.com/list")! | |
let request = URLRequest(url: url) | |
URLSession.shared.dataTask(with: request) { [weak self] (data, response, error) in | |
if let list = try? JSONDecoder().decode([Item].self, from: data ?? Data()) { |
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
extension Binding { | |
func dispatched(to state: CurrentValueSubject<AppState, Never>, | |
_ keyPath: WritableKeyPath<AppState, Value>) -> Self { | |
return .init(get: { () -> Value in | |
self.wrappedValue | |
}, set: { newValue in | |
self.wrappedValue = newValue | |
state.value[keyPath: keyPath] = newValue | |
}) | |
} |