View sync_coredata_from_paging_data.swift
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 CoreData | |
struct RemoteUser: Decodable { | |
var userId: Int | |
var name: String | |
} | |
class User: NSManagedObject { | |
@NSManaged public var userId: Int |
View new-mac-setup.sh
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
#!/bin/bash | |
set -e | |
# before re-install Mac system, keep in mind: | |
# 1. exporting key and certificate keychain | |
# 2. iPhone/iPad backup files | |
# 3. WeChat message backup file | |
# 4. ~/.ssh | |
# then change the following git config and run this script |
View ViewController_update.swift
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
let mapping = [\User.name: nameField, | |
\User.email: emailField, | |
\User.likeKiwi: likeKiwiSwitcher, | |
\User.travel: travelBtn, | |
\User.hiking: hikingBtn, | |
\User.reading: readingBtn] | |
func update(_ keypath: PartialKeyPath<User>, _ value: Any) { | |
model[keyPath: keypath] = value | |
mapping[keypath].value = value |
View ViewController_Change_VM.swift
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
model.name = "Tonny" | |
nameField.text = "Tonny" | |
model.email = "test@gmail.com" | |
emailField.text = "test@gmail.com" | |
model.likeKiwi = true | |
likeKiwiSwitcher.isOn = true | |
model.travel = false |
View ViewController_Tag_KeyPath.swift
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
let mapping = [1 : \User.name, | |
2 : \User.email, | |
3 : \User.likeKiwi, | |
4 : \User.travel, | |
5 : \User.hiking, | |
6 : \User.reading] | |
func viewChanged(_ field: Field) { | |
let path = mapping[sender.tag] | |
model[keyPath: path] = field.value |
View ViewController.swift
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
@IBAction func nameChanged(_ sender: UITextField) { | |
model.name = sender.text | |
} | |
@IBAction func emailChanged(_ sender: UITextField) { | |
model.email = sender.text | |
} | |
@IBAction func switchChanged(_ sender: UISwitch) { | |
model.likeKiwi = sender.isOn |
View ViewController.swift
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
@IBOutlet weak var nameField: UITextField! | |
@IBOutlet weak var emailField: UITextField! | |
@IBOutlet weak var likeKiwiSwitcher: UISwitch! | |
@IBOutlet weak var travelBtn: UIButton! | |
@IBOutlet weak var hikingBtn: UIButton! | |
@IBOutlet weak var readingBtn: UIButton! |
View DataBindingEx.swift
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 DataBinding { | |
public func update<Value>(_ keyPath: WritableKeyPath<M, Value>, _ value: Value) { | |
model[keyPath: keyPath] = value | |
_keyPathViews[keyPath]?.wrappedView?.setValue(value) | |
} | |
} |
View KeypathViewMapping.swift
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
let mapping = [ | |
\User.name: nameField, | |
\User.email: gmailField, | |
\User.address: addressField, | |
\User.travel: travelBtn, | |
\User.hiking: hikingBtn, | |
\User.reading: readingBtn, | |
] |
View User.swift
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 User { | |
var name, email: String? | |
var likeKiwi = false | |
var travel = false | |
var hiking = false | |
var reading = false | |
} |
NewerOlder