Skip to content

Instantly share code, notes, and snippets.

View dejanskledar's full-sized avatar

Dejan Skledar dejanskledar

View GitHub Profile
UIView.animateKeyframes(withDuration: 5, delay: 0, animations: {
// Add animations
}, completion:{ _ in
print("I'm done!")
})
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: {
UIView.animate(withDuration: 1, animations: {
view.frame.origin.x += 200
}, completion: { _ in
UIView.animate(withDuration: 1, animations: {
view.backgroundColor = .green
})
})
UIView.animate(withDuration: 1) {
// Animate your views here
view.frame.origin.x += 1
}
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!)
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)
}
}
{
"length": 120,
"is_valyrian_steel": true,
"sword_name": "Oathkeeper"
}
let oathKeeper = Sword(name: "Oathkeeper", size: 120, isValyrianSteel: true)
let jsonData = try? JSONEncoder().encode(oathKeeper)
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)
}
}
extension Sword {
private enum CodingKeys: String, CodingKey {
case name = "sword_name"
case size = "length"
case isValyrianSteel = "is_valyrian_steel"
}
}