This file contains hidden or 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 UIKit | |
| final class StackViewController: UIViewController { | |
| private let stackView: UIStackView = { | |
| let stackView = UIStackView() | |
| stackView.axis = .vertical | |
| stackView.alignment = .fill | |
| stackView.distribution = .fill |
This file contains hidden or 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 UIKit | |
| final class ContainerViewController: UIViewController { | |
| private let imageController:UIViewController | |
| private let listController:UIViewController | |
| init(imageController:UIViewController, listController:UIViewController) { | |
| self.imageController = imageController |
This file contains hidden or 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
| enum AnimalType { | |
| case tiger | |
| case elephant | |
| case otter | |
| } | |
| struct Animal:Equatable { | |
| let name:String | |
| let type:AnimalType | |
| } |
This file contains hidden or 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 strings1 = ["a", "b", "c"] | |
| let strings2 = ["a", "b", "c"] | |
| var isEqual = strings1 == strings2 //true | |
| let strings1 = ["a", "b", "c"] | |
| let strings2 = ["a", "b", "d"] | |
| var isEqual = strings1 == strings2 //false | |
| let strings1 = ["a", "b", "c"] | |
| let strings2 = ["b", "c", "a"] |
This file contains hidden or 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
| /* create the image at original size */ | |
| let image = UIImage(named: "Landscape-1276x800.jpg")! | |
| /* | |
| * create bounding rect with largest possible height based on width | |
| * this will get you the aspect height for the speficied width | |
| */ | |
| let boundingRect = CGRect(x: 0, y: 0, width: 300, height:CGFloat.greatestFiniteMagnitude) | |
| /* |
This file contains hidden or 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 TestDecode:Codable { | |
| let updated:Date | |
| } | |
| let json = """ | |
| { | |
| "updated":"2019-2-21T02:02:55-08:00" | |
| } | |
| """ |
This file contains hidden or 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 dates = ["key_1":Date()] | |
| let encoder = JSONEncoder() | |
| encoder.dataEncodingStrategy = .base64 | |
| encoder.outputFormatting = [.sortedKeys, .prettyPrinted] | |
| let encoded = try? encoder.encode(object) | |
| print(String(data: encoded!, encoding: .utf8)!) | |
| //output | |
| { | |
| "key_1" : 574821298.18860102 |
This file contains hidden or 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 object = ["keyOne":"Bengal tiger", "keyTwo":"Siberian tiger", "keyThree ":"white rhino", "keyFour":"African elephant"] | |
| let encoder = JSONEncoder() | |
| encoder.keyEncodingStrategy = .convertToSnakeCase | |
| encoder.outputFormatting = [.sortedKeys, .prettyPrinted] | |
| let encoded = try? encoder.encode(object) | |
| print(String(data: encoded!, encoding: .utf8)!) | |
| //output | |
| { | |
| "key_four" : "African elephant", |
This file contains hidden or 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 object = ["key1":"Bengal tiger", "key2":"Siberian tiger", "key3 ":"white rhino", "key4":"African elephant"] | |
| let encoder = JSONEncoder() | |
| encoder.outputFormatting = [.sortedKeys, .prettyPrinted] | |
| let encoded = try? encoder.encode(object) | |
| print(String(data: encoded!, encoding: .utf8)!) | |
| //output | |
| { | |
| "key1" : "Bengal tiger", | |
| "key2" : "Siberian tiger", |
This file contains hidden or 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 object = ["key1":"bengal tiger", "key2":"siberian tiger", "key3":"white rhino", "key4":"african elephant"] | |
| let encoder = JSONEncoder() | |
| encoder.outputFormatting= .prettyPrinted | |
| let encoded = try? encoder.encode(object) | |
| print(String(data: encoded!, encoding: .utf8)!) | |
| //output | |
| { | |
| "key3" : "white rhino", | |
| "key1" : "bengal tiger", |
NewerOlder