How to post to Facebook and Twitter using Social Framework

It is extremely simple to bring up Facebook and Twitter Sheets in your app using the Social Framework. Once imported you can create a new instance of SLComposeViewController, initialise it with text, an image and a URL, and present it modally from your own view controller. You don’t have to specify anything other than which […]

How to test the size of a UIImage (in bytes)

We can use NSData’s length method for this. Imagine your UIImage is yourImage: NSData *imageData = UIImageJPEGRepresentation(yourImage, 1); NSLog(@”Size of your image is %d bytes”, [imageData length]) [imageData length] returns a double in bytes, which will be the size of your image. This is useful if you’d like to save something and you’re limited in […]

How to detect if your app is running on iOS 7

You can query the NSFoundationVersionNumber like so: if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { // you’re running iOS 6.1 or earlier } else { // you’re running iOS 7 or later } Note that if you’re compiling with an older SDK, the value you’re querying may not be defined – in which case, you must define it […]

How to covert an NSUInteger / NSInteger into an int value

Before the addition of 64bit in iOS it was possible to take an NSUInteger (or NSInteger) and put it into an int variable, like so: int arrayCount = [self.myArray count]; If you add 64bit support to your app you may notice a compiler warning when you do this: Implicit conversion loses integer precision: ‘NSInteger’ (aka […]