Skip to content

Instantly share code, notes, and snippets.

View igroomgrim's full-sized avatar
🥶
Focusing

Anak Mirasing igroomgrim

🥶
Focusing
View GitHub Profile
@igroomgrim
igroomgrim / callbackNClosure
Created May 24, 2016 03:54
recieve callbacks and return closure
func buildDidCompleteCallback(callback: Callback?) -> (data: NSData?, response: NSURLResponse?, error: NSError?) {
}

Thoughts on Swift 2 Errors

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:

@igroomgrim
igroomgrim / introrx.md
Created April 5, 2016 11:39 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@igroomgrim
igroomgrim / TDTask_Sort.swift
Last active November 10, 2015 04:03
Sorting realm object with sorted function.
let predicate = NSPredicate(format: "done == %@", NSNumber(bool: true))
let tasks = realm.objects(TDTask).filter(predicate).sorted("created",ascending:false)
@igroomgrim
igroomgrim / TDTask_Predicate.swift
Created November 10, 2015 03:59
Filtering realm object with NSPredicate.
let predicate = NSPredicate(format: "done == %@", NSNumber(bool: true))
let tasks = realm.objects(TDTask).filter(predicate)
@igroomgrim
igroomgrim / TDTask_Predicatel.swift
Created November 10, 2015 03:59
Filtering realm object with NSPredicate.
let predicate = NSPredicate(format: "done == %@", NSNumber(bool: true))
let tasks = realm.objects(TDTask).filter(predicate)
@igroomgrim
igroomgrim / TDTask_Update.swift
Created November 10, 2015 03:53
Update/Edit to-do task object and show status in tableview.
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()
@igroomgrim
igroomgrim / TDTask_All.swift
Created November 10, 2015 03:51
Get all task from Realm database
let tasks = realm.objects
@igroomgrim
igroomgrim / TDTask_Save.swift
Created November 10, 2015 03:47
Example write Realm object to db
let task = TDTask()
task.title = titleTextField.text!
task.taskDescription = descriptionTextView.text
let realm = try! Realm()
realm.beginWrite()
realm.add(task)
try! realm.commitWrite()
@igroomgrim
igroomgrim / TDTask.swift
Created November 10, 2015 03:42
Realm Object - TDTask model
import RealmSwift
class TDTask: Object {
dynamic var title: String = ""
dynamic var taskDescription: String = ""
dynamic var done: Bool = false
dynamic var created: NSTimeInterval = NSDate().timeIntervalSince1970
}