3 Steps to fetch in Core Data (Swift)

1. Get the managed context:

    let managedObjectContext = (NSApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext!

//Change AppDelegate for the name of the class of your Application Delegate

 

2. Set a variable to store the data:

    var contentsOfTransactionFetchRequest = []

3. Fetch the data you need

        let fetchRequest = NSFetchRequest(entityName: “Whatever”)

        contentsOfTransactionFetchRequest = try! managedObjectContext.executeFetchRequest(fetchRequest)

Hope it helps, for me it’s good to have it summarized for later reference!

If you have any feedback I’m at @MarcMasVi

Marc

Working with NSUserDefaults in Swift 2

I was quite pleased to see than in Swift is even easier than in Objective-C. Here is how you do it:

Create a variable that can access them: 

 

    var userDefaults = NSUserDefaults.standardUserDefaults()

 

Add values to dictionary:

 

    userDefaults.setObject(“StringText”, forKey: “KeyInDictionary”)

 

Read values from dictionary:

 

    

    let textuserDefaults.objectForKey(“KeyInDictionary”) as! String

 

 

And that’s in a very simple way how it works. If you want to get into it deeper you can look into the documentation or read this great post

 

If you have any feedback I’m at @MarcMasVi

Marc