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 getOffsetForDate(date: Date) -> CGFloat { | |
| // dayViewHeight being the height of the view that containts the hour label and the line separator | |
| let components = Calendar.current.dateComponents([.minute, .hour], from: date) | |
| let hourOffset = CGFloat(components.hour ?? 0) * (dayViewHeight + Sizes.gridLineSeparation) | |
| let minuteOffset = ceilToPixelsAccuracy(CGFloat(components.minute ?? 0) / 60 * (dayViewHeight + Sizes.gridLineSeparation)) | |
| return hourOffset + minuteOffset + ceilToPixelsAccuracy(dayViewHeight / 2) | |
| } | |
| // Function to ceil according to the scaling factor |
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 getStartOffset(for event: CalendarEvent) -> CGFloat { | |
| return gridView.getOffsetForDate(date: event.startDate) | |
| } | |
| func getHeight(for event: CalendarEvent) -> CGFloat { | |
| let height = gridView.getOffsetForDate(date: event.endDate) - gridView.getOffsetForDate(date: event.startDate) | |
| return height > Sizes.minEventHeight ? height : Sizes.minEventHeight | |
| } |
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? |
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) |
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
| 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
| 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
| 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: 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
| 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 | |
| } |