Posts

Showing posts with the label example

Static variable in Objective-C

From time to time you will want to declare a static object which hold your data and won't be changed when your app is still running. In iOS SDK, there's no easy way to get your variable to static, however, you can you singleton design-pattern and set its instance to be static. Below are a code snippet for Static Object IOS Static:  //DataClass.h       @interface DataClass : NSObject  {         NSString *str;      }     @property(nonatomic,retain)NSString *str;     +(DataClass*)getInstance;     @end   //DataClass.m     @implementation DataClass     @synthesize str;     static DataClass *instance =nil;     +(DataClass *)getInstance     {         @synchronized(self)         {             if(instance==nil)       ...