Posts

Showing posts from 2014

you should know what is the use of @property.

  @property offers a way to define the information that a class is intended to encapsulate. If you declare an object/variable using @property , then that object/variable will be accessible to other classes importing its class.   If you declare an object using @property in the header file, then you have to synthesize it using @synthesize in the implementation file.  Example: .h class @interface ExampleClass : NSObject @property (nonatomic, retain) NSString *name; @end .m class @implementation ExampleClass @synthesize name; @end Now the compiler will synthesize accessor methods for name . ExampleClass *newObject=[[ExampleClass alloc]init]; NSString *name1=[newObject name]; // get 'name' [obj setName:@“Tiger”]; List of attributes of @property : atomic. nonatomic. retain. copy. readonly. readwrite. assign. strong.   atomic : It is the default behaviour. If an object is declared as atomic then it becomes thread-safe

Filtering a NSArray using NSPredicate

In this post, i'll walk you through how to filter an NSArray using NSPredicates.  The first thing you'll need to decide is if you're filtering a number or a string. For strings, you can use any of the following filters: (NOTE: must be all caps) BEGINSWITH ENDSWITH LIKE MATCHES CONTAINS For numbers, you can use: != > >= < <= == Now that you know what kind of data you're going to filter on, we can build our predicate. Lets first assume we're filtering an array of strings: NSArray* data = @[@"Grapes", @"Apples", @"Oranges]; Using this array, lets filter on the letter "a" This means we'll want to use CONTAINS. So if we want to build a hard-coded string it would look something like: NSString* filter = @"%K CONTAINS %@"; We'll then take our filter string and create a predicate with it:  NSPredicate* predicate = [NSPredicate predicateWithFormat:filter, @&quo

what is appDelegate?

Image
The  AppDelegate  is sort of like the entry point for your application.  It implements  UIApplicationDelegate  and contains methods that are called when your application launches, when is going to the background (i.e. when you hit the home key), when it’s opened back up, and more.  The  AppDelegate  object is stored as a property on the  UIApplication  class and is accessible from anywhere in your objective-C classes.  The header and implementation file for your  AppDelegate  is generated when you create your project and you don’t have to make any modifications for it to work.  However, that doesn’t mean we can’t make changes and make use of the  AppDelegate .  We’re going to keep this simple and just add a new NSString  property to the delegate. AppDelegate is handling special UIApplication states. This lets you do initialization/cleanup of your app at the right time.So basically the delegate is responsible for monitoring when it is safe to open/close things, termina

Designated Initializers in Objective - C

Object construction in Objective C is a two phase procedure:---> 1.  First the object has to be allocated in memory, hence the ‘alloc’ message we always see when a object is invoked this way (and not for example via a ‘get…’, which would be a Factory): 2. Second phase involves object initialization which is quite similar to what would be a constructor in C++. When we implement method ‘init’ (which is just a convention) we have to take care on superclass designated initializer .   MyObject* obj1 = [[MyObject alloc] init]; Designated initializer :-->   Designated initializer is the method that best set up our object between all initializer methods. - ( id ) init: - ( id ) initWithColor:( NSColor *)color; - ( id ) initWithColor:( NSColor *)color andSize:( NSInteger )size; What method do you think is the most complete? Our third method includes two parameter while the other only one or none. Now, we got a pattern that you are going to see every time you