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
| internal var oldImageUrl: URL? { | |
| return URL(string: carImageUrl ?? "") | |
| } | |
| internal var newImageUrl: URL? { | |
| let urlString = Constants.URL.images | |
| .replacingOccurrences(of: "{modelIdentifier}", with: modelIdentifier ?? "") | |
| .replacingOccurrences(of: "{color}", with: color ?? "") | |
| return URL(string: urlString) |
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
| init(date: Date, frame: CGRect) { | |
| super.init(frame: frame) | |
| // Do stuff with Date | |
| } |
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
| func setup(date: Date) { | |
| self.date = date | |
| updateInterface() // Setup view with strings, colours, etc. | |
| } |
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
| Alamofire.request(requestURL, method: .get, parameters: parameters, encoding: URLEncoding.default).responseData { response in | |
| if let data = response.result.value { | |
| let decoder = JSONDecoder() | |
| do { | |
| let apiResponse = try decoder.decode(ApiResponse.self, from: data) | |
| // Do stuff | |
| } catch { | |
| NSLog("Error while decoding") | |
| // Error handling | |
| } |
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 ApiResponse: Codable { | |
| let errorCode: Int | |
| let name: String | |
| let age: Int | |
| } |
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 ErrorCode: Int, Error, Codable { | |
| case noError = 0 | |
| case noConnection = 401 | |
| case userNotFound = 404 | |
| // ... | |
| var localizedDescription: String? { | |
| switch self { | |
| case .noError: | |
| return nil |
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 ApiResponse: Codable { | |
| let errorCode: ErrorCode | |
| let name: String | |
| let age: Int | |
| } |
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 ApiResponse: Codable { | |
| let errorCode: ErrorCode | |
| let name: String | |
| let age: Int | |
| private enum CodingKeys: String, CodingKey { | |
| case errorCode = "errorcode" | |
| case name = "firstname" | |
| case age = "userage" | |
| } |
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 myCollectionView = UICollectionView() | |
| // ... things go on until I have a frame and a layout... | |
| myCollectionView = UICollectionView(frame: myFrame, collectionViewLayout: myCollectionViewLayout) |
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
| lazy var collectionView = setupCollectionView() | |
| private func setupCollectionView() -> UICollectionView { | |
| let layout = UICollectionViewFlowLayout() | |
| layout.minimumInteritemSpacing = 0 | |
| layout.itemSize = CGSize(width: 50, height:50) | |
| // Perform any other customizing to your layout/UICollectionView | |
| return UICollectionView(frame: .zero, collectionViewLayout: layout) |
OlderNewer