(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| // | |
| // LocationService.swift | |
| // | |
| // | |
| // Created by Anak Mirasing on 5/18/2558 BE. | |
| // | |
| // | |
| import Foundation | |
| import CoreLocation |
| import RealmSwift | |
| class TDTask: Object { | |
| dynamic var title: String = "" | |
| dynamic var taskDescription: String = "" | |
| dynamic var done: Bool = false | |
| dynamic var created: NSTimeInterval = NSDate().timeIntervalSince1970 | |
| } |
| let task = TDTask() | |
| task.title = titleTextField.text! | |
| task.taskDescription = descriptionTextView.text | |
| let realm = try! Realm() | |
| realm.beginWrite() | |
| realm.add(task) | |
| try! realm.commitWrite() |
| let tasks = realm.objects |
| let realm = try! Realm() | |
| realm.beginWrite() | |
| task.title = titleTextField.text! | |
| task.taskDescription = descriptionTextView.text | |
| if statusSwitch.on { | |
| task.done = true | |
| } else { | |
| task.done = false | |
| } | |
| try! realm.commitWrite() |
| let predicate = NSPredicate(format: "done == %@", NSNumber(bool: true)) | |
| let tasks = realm.objects(TDTask).filter(predicate) |
| let predicate = NSPredicate(format: "done == %@", NSNumber(bool: true)) | |
| let tasks = realm.objects(TDTask).filter(predicate) |
| let predicate = NSPredicate(format: "done == %@", NSNumber(bool: true)) | |
| let tasks = realm.objects(TDTask).filter(predicate).sorted("created",ascending:false) |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
When Swift was first announced, I was gratified to see that one of the (few) philosophies that it shared with Objective-C was that exceptions should not be used for control flow, only for highlighting fatal programming errors at development time.
So it came as a surprise to me when Swift 2 brought (What appeared to be) traditional exception handling to the language.
Similarly surprised were the functional Swift programmers, who had put their faith in the Haskell-style approach to error handling, where every function returns an enum (or monad, if you like) containing either a valid result or an error. This seemed like a natural fit for Swift, so why did Apple instead opt for a solution originally designed for clumsy imperative languages?
I'm going to cover three things in this post: