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 |
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 |
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 |
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 = "[email protected]" | |
emailField.text = "[email protected]" | |
model.likeKiwi = true | |
likeKiwiSwitcher.isOn = true | |
model.travel = false |
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 |
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 |
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! |
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) | |
} | |
} |
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, | |
] |
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