Creating string enumerations in Objective-C (The ultimate solution)

A while ago I wrote on my blog about a solution to one of the most common questions asked by Objective-C programmers which is “How can I create string enumerations?”. Well, the solution that I’ve given has immediately become one of the top subjects that attracts developers to my blog, as I can see in my stats. I thought I should now take it to a whole other level and get rid of the limitations that I had presented in the old solution, and come up with a fresh perspective.

The following video is the result of my work on this subject. I hope you’ll enjoy watching it.

Learn iOS programming

Giving private and group iOS development lessons

Hello internet. After writing many many books and developing iOS apps for 6+ years, I feel I am now ready to take on a new challenge. To start teaching iOS development to people who are interested in transforming or perfecting their career.

I am available for teaching iOS development to you ANYWHERE in the world you are in. If you are in London or in Brighton in the UK, we can have face to face lessons. If anywhere else in the world, I can teach you over Skype.

Classes will be tailor made to suite your free times, abilities, etc. If you are interested, get in touch by sending me an email at: vandad.np@gmail.com

 

iOS 7 Programming Cookbook’s Source Code

As you know, my recent book is now published, titled “iOS 7 Programming Cookbook”. You can purchase it here:

http://shop.oreilly.com/product/0636920031031.do

All the source codes written for this book are now available on Github at the following location:

https://github.com/vandadnp/ios-7-programming-cookbook-source-codes

If you have any questions, please let me know.

Compiling C files for Mach-O ARM architecture, in OS X Lion

Yesterday I wanted to compile a .c code for ARM architecture using the iOS SDK on my Lion machine. I wanted to create object files and executable files that I can install on my jailbroken iPhone 4. I have explained the process here for you. I hope it will be of help.

We are going to be using the LLVM-GCC compiler. In OS X Lion, this compiler sits here:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc-4.2

Also we need to pass the path to our iOS SDK, to the compiler so that it knows where to get the libraries and frameworks from. In OS X Lion with iOS SDK 5.1 installed, the path of the iOS SDK would be here:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk

So if your SDK version is different, you need to modify that path. Now let’s write a simple Hello World C code in a file named hello.c

#include <stdio.h>

int main(void){
printf(“Hello, World!\n”);
}

Now let’s go to Terminal and change your current working directory to the directory that contains the above hello.c file. Now let’s tell Terminal where our compiler and SDK folders are:

COMPILER=”/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc-4.2″
SDKDIR=”/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk”

Now we are going to attempt to compile the hello.c source file for armv7 CPU architecture:

$COMPILER hello.c -o hello.o -c -arch armv7 -isysroot $SDKDIR

Now if you get an ls -la on your folder, you will also see an object file called hello.o. If you do the following:

file hello.o

You should see an output like this:

hello.o: Mach-O object arm

So now we have the object file. If you want to link this object file into an executable file, then you can do this:

LINKER=$COMPILER
$LINKER hello.o -o hello -arch armv7 -isysroot $SDKDIR

Note: the linker and compiler are both llvm-gcc-4.2 but we pass the -c to it to compile and if we skip -c, we will link, producing the final executable file.

Now you have 3 files

  • hello.c
  • hello.o
  • hello
The first one is your source file, the second one is the compiled file and the third one is the linked (executable) file. So now do this:
file hello
You should be able to see the following output:
hello: Mach-O executable arm

That’s it. If you have any questions, let me know in the comment section below.

Git Repositories for 4 of My Books

I have set up 4 GitHub repositories for my four books:

iOS 4 Programming Cookbook
Repo: git@github.com:vandadnp/iOS-4-Programming-Cookbook.git
Web: https://github.com/vandadnp/iOS-4-Programming-Cookbook

Concurrent Programming in Mac OS X and iOS
Repo: git@github.com:vandadnp/Concurrent-Programming-in-Mac-OS-X-and-iOS.git
Web: https://github.com/vandadnp/Concurrent-Programming-in-Mac-OS-X-and-iOS

Writing Game Center Apps in iOS
Repo: git@github.com:vandadnp/Writing-Game-Center-Apps-in-iOS.git
Web: https://github.com/vandadnp/Writing-Game-Center-Apps-in-iOS

Graphics and Animation on iOS
Repo: git@github.com:vandadnp/Graphics-and-Animation-on-iOS.git
Web: https://github.com/vandadnp/Graphics-and-Animation-on-iOS

Enjoy :-)

Xcode 4 Refactoring Features – Part 1

In this video, you will learn about Rename, Extract, Create Superclass, and Move Up refactoring facilities in Xcode 4, Apple’s latest and greatest development environment for iOS and Mac OS X. If you have any questions, or comments, leave them down here.