Showing posts with label iPhone/iPad. Show all posts
Showing posts with label iPhone/iPad. Show all posts

How to check empty NSString

Checking empty string

NSString *string1=@"";
NSString *string2=@" ";
NSString *string3=@"  \n ";



string1 is an empty string.

string2 is not empty having empty whitespace
[[string2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

string3 is not empty having empty whitespace and new line character
[string3 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

all the above string can be checked with @"" to test empty string.

how to create singleton object

Singleton object are created only once in the life cycle of the app.

Singleton object can be accessed using [ClassName sharedInstance].

+(id)sharedInstance{
    static MyClassManager *sharedMyClassManager = nil;
    static dispatch_once_t onceToken;
     dispatch_once(&onceToken, ^{
          sharedMyClassManager = [[self alloc] init];
     });
     retrun sharedMyClassManager;
}

WebRep
currentVote
noRating
noWeight

@property types

Objects have properties to access for public.
Types of attributes

atomic - can be accessed only by one thread at a time.
non-atomic - can be accessed by any number of threads.
readonly - having access for readonly for object.
readwrite - having access for read and write object.
retain - will increase the retain count of the object. This is called as shallow copy. This will not create new memory reference.

copy - will create new memory location and copy all data to the newly created object. This is called as Deep copy.
assign - This will neither create new reference nor increase the retain count of the object. All delegate properties are assign.


How to install xcode


Download Xcode from https://developer.apple.com/xcode/ 
Drag and drop to applications.
Then open Xcode from Applications.