Skip to content

Instantly share code, notes, and snippets.

@pocketkk
Created July 27, 2014 17:51
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pocketkk/db5895d64a212a6e9ea1 to your computer and use it in GitHub Desktop.
Save pocketkk/db5895d64a212a6e9ea1 to your computer and use it in GitHub Desktop.
Swift - Sort objects by date field
@objc(Note)
class Note: NSManagedObject {
@NSManaged var content: String
@NSManaged var date: NSDate
@NSManaged var business: Business
@NSManaged var coldcall: ColdCall
@NSManaged var contact: Contact
}
let notes : [Note] = //array of notes
// sort a collection of notes by date
notes.sort({$0.date.timeIntervalSinceNow > $1.date.timeIntervalSinceNow})
@ginahagg
Copy link

thanks... just what i needed :)

@bsantanas
Copy link

Awesome! simple and effective

@gargDigrt
Copy link

It showing error
Binary operator '<' cannot be applied to two 'TimeInterval?' (aka 'Optional') operands
what to do ?

Copy link

ghost commented Feb 9, 2018

@avidzha17
Copy link

👍

@miladgolchinpour
Copy link

Thank you so muccch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment