Posts

Showing posts from September, 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