Posts

Showing posts from May, 2013

Difference between delegate and notification.

Short Answer:  You can think of delegates like a telephone call. You call up your buddy and specifically want to talk to them. You can say something, and they can respond. You can talk until you hang up the phone. Delegates, in much the same way, create a link between two objects, and you don't need to know what type the  delegate will be, it simply has to implement the protocol. On the other hand, NSNotifications are like a radio station. They  broadcast their message to whoever is willing to listen. Thee radio station can't receive feedback from it's l isteners (unless it has a telephone, or delegate). The listeners can ignore the message, or they can do something with it. NSNotifications allow you to send a message to any objects, but you won't have a link  between them to communicate back and forth. If you need this communication, you should probably  implement a delegate. Otherwise, NSNotifications are simpler and easier to use, but may get you into troub...

Macros for Objective-C

In Objective C #define IS_PAD [[ UIDevice currentDevice ] interfaceIdiom ] == UIUserInterfaceIdiomPad ) Now check  if ( IS_PAD ) { //iPad Stuff } else { //iPhone Stuff } Other useful Eg. #define ALERT(title, message) [[[UIAlertView alloc] initWithTitle:title\ message:message\ delegate:nil\ cancelButtonTitle:@"OK"\ otherButtonTitles:nil] show] #define GOBACK [self.navigationController popViewControllerAnimated:YES] #define DELEGATE_Is_OK(delegateMethod) [self.delegate respondsToSelector:@selector(yourDelegateMethod)] ________________________________________________________________________ Macros are preprocessor definitions. What this means is that before your code is compiled, the preprocessor scans your code and, amongst other things, substitutes the definition of your macro wherever it sees the name of your ...

What is the difference among nil, NULL, Nil in Objective-C?

They are all zeros, the difference lies in their types ->  The  NSNull  class defines a singleton object used to represent null values in collection objects (which don’t allow  nil  values). { NSNull  is a class for objects that represent null. } (https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSNull_Class/Reference/Reference.html#//apple_ref/occ/cl/NSNull) -> nil is an id. So its points to a non-existent objective-c object -> Nil is a non-existent objective-c class -> [NSNull null] is an object that’s meant to stand in for nil in situations where nil isn’t allowed. For example, you can’t have a nil value in an NSArray. So if you need to represent a “nil”, you can use [NSNull null] Also there is no ‘null’ in the objective c its ‘NULL’ not ‘null’. ‘null’ exist in Java or in C# not in Objective-C nil -> Null-pointer to objective- c object NIL -> Null-pointer to objective- c class ...

main.m :)

The  main  function in  main.m  calls the  UIApplicationMain  function within an autorelease pool: @autoreleasepool { return UIApplicationMain ( argc , argv , nil , NSStringFromClass ([ AppDelegate class ])); } The   @autoreleasepool   statement supports the Automatic Reference Counting (ARC) system. ARC provides automatic object-lifetime management for your app, ensuring that objects remain in existence for as long as they're needed and no longer. argc = argument count,-> It signifies how many arguments are being passed into the executable. argv = argument vector ->  It is a pointer to an array of characters. Or to think about it in another way, it is an array of C strings (since C strings are just arrays of characters). Link of document (http://stackoverflow.com/questions/4575801/objective-c-main-routine-what-is-int-argc-const-char-argv) UIApplicationMain The call to  UIApplicat...