Setting bool, int and other properties to a Parse object

Working with Parse is great. It’s quick, easy, scalable and for the most part, the documentation and community support is fantastic. I just want to share (more as a reference than anything else) a quick list detailing how to set certain property types like bool and ints to a PFObject in Objective-C. I’m also including how to set a Pointer to another PFObject, both automatically and manually. It’s really easy, but not immediately obvious the first time you have to do it. See below:


Declaring a block as a method parameter in Objective-C

Just a quick post as I came across an extremely helpful website dedicated to those of us who consistently need to declare Objective-C blocks in our applications. Most often, I require them when writing network operations and want to provide a callback once the operation has been completed (you could use NSOperation for this as well). Take the example below:

In the code above, we declare a callback block which takes one argument of type NSString. I think you’ll agree calling it is also quite easy.

Check this website out for more resource on objective-c block declarations.

Reading and writing NSArray into Core Data with Transformable types

Core Data is great, but coming to grips with it can be a bit of a headache for first time users. Out of the box, iOS allows you to declare model properties with a variety of types: String, Float, Date, Boolean, Int 16/32/64, but annoyingly, not arrays. Enter Transformable types.

With Transformable types, you can store anything as NSData and load it back to a format that’s useable for you. This includes, NSArrays.

This brief post assumes you already know how to get setup with Core Data, and how to create an NSManagedObject subclass of your own Entity.

Take the example below:

Above, we create a new Car entity which has an attribute named “wheels” of the Transformable type. We set this attribute to be the wheelsArray we declared earlier, and save.

How do we get this data back? All we do is initialise a new NSArray with the contents of car.wheels and we’re good to go. In a real application, we would have more code in place to perform various checks and error handling, but this should give you a good idea of what’s required: