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
UIView.animateKeyframes(withDuration: 5, delay: 0, animations: { | |
// Add animations | |
}, completion:{ _ in | |
print("I'm done!") | |
}) |
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
UIView.animate(withDuration: 1, animations: { | |
view.frame.origin.x += 200 | |
}, completion: { _ in | |
UIView.animate(withDuration: 1, animations: { | |
view.backgroundColor = .green | |
}, completion: { _ in | |
UIView.animate(withDuration: 1, animations: { | |
view.frame.origin.y += 200 | |
}, completion: { _ in | |
UIView.animate(withDuration: 1, animations: { |
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
UIView.animate(withDuration: 1, animations: { | |
view.frame.origin.x += 200 | |
}, completion: { _ in | |
UIView.animate(withDuration: 1, animations: { | |
view.backgroundColor = .green | |
}) | |
}) |
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
UIView.animate(withDuration: 1) { | |
// Animate your views here | |
view.frame.origin.x += 1 | |
} |
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 json = """ | |
{ | |
"length": 120, | |
"is_valyrian_steel": true, | |
"sword_name": "Oathkeeper" | |
} | |
""" | |
let data = json.data(using: .utf8) | |
let sword = try? JSONDecoder().decode(Sword.self, from: 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 Sword { | |
init(from decoder: Decoder) throws { | |
let values = try decoder.container(keyedBy: CodingKeys.self) | |
name = try values.decode(String.self, forKey: .name) | |
size = try values.decode(Int.self, forKey: .size) | |
isValyrianSteel = try values.decode(Bool.self, forKey: .isValyrianSteel) | |
} | |
} |
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
{ | |
"length": 120, | |
"is_valyrian_steel": true, | |
"sword_name": "Oathkeeper" | |
} |
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 oathKeeper = Sword(name: "Oathkeeper", size: 120, isValyrianSteel: true) | |
let jsonData = try? JSONEncoder().encode(oathKeeper) |
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 Sword { | |
public func encode(to encoder: Encoder) throws { | |
var values = encoder.container(keyedBy: CodingKeys.self) | |
try values.encode(name, forKey: .name) | |
try values.encode(size, forKey: .size) | |
try values.encode(isValyrianSteel, forKey: .isValyrianSteel) | |
} | |
} |
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 Sword { | |
private enum CodingKeys: String, CodingKey { | |
case name = "sword_name" | |
case size = "length" | |
case isValyrianSteel = "is_valyrian_steel" | |
} | |
} |