•
Pretty simple. This call terminates the application and starts Mobile Safari browser with specified URL. [[UIApplication sharedApplication] openURL: [NSURL URLWithString: @”http://www.apple.com/”]];
•
There is no private or protected methods concept in Objective-C. I think it is related to the architecture of invoking method in Objective-C. Each method is invoked like [self method] style or [self performSelector:@selector(method)]. Internally, Objective-C runtime resolves method implementation by searching method name. This architecture gives flexibility to call method and also allows…
•
NSUserDefautls object automatically loads and saves small information. Along with primitive value like BOOL, integer or float, NSUserDefaults can handle objects like NSArray, NSData, NSDictionary, NSString. // Save a default [[NSUserDefaults standardUserDefaults] setObject:@”NO” forKey:@”ShowWarning”]; // Read BOOL warning value from NSUserDefaults BOOL showWarning = [[NSUserDefaults standardUserDefaults] boolForKey:@”ShowWarning”];
•
By combining UIGraphicsBeginImageContext() and -renderInContext in CALayer, you can draw contents into a image (UIImage) object. It is like screen capture. UIGraphicsBeginImageContext(view.frame.size); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
•
There is no border property in UIView…. classes but we can access CALayer class to set border. Since layer property is defined in the UIView class, all of UIView inherited class can use this property to set border. It needs to have #import <QuartzCore/QuartzCore.h> to access CALayer. view.layer.borderWidth = 1; view.layer.borderColor = [[UIColor grayColor]…
•
In Objective-C, a selector’s signature consists of: The name of the method (in this case it would be ‘myTest’) (required) A ‘;’ (colon) following the method name if the method has an input. A name and ‘:’ for every additional input.
•
AppDelegate object can access from any class in the same application like below. Methods or properties shared between controllers can be defined under application delegates. SomeAppDelegate *appDelegate = (SomeAppDelegate *)[[UIApplication sharedApplication] delegate];
•
Use NSSearchPathForDirectoriesInDomains(). First argument “NSDocumentDirecotry” is the key to specify special directory, in this case Document directory under the application. The method returns absolute path expression. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSLog(@”NSDocumentDirectory is %@”, documentsDirectory);
•
Apparently a UIColor is not necessarily a single color, but can be a pattern as well. Confusingly, this is not supported in Interface Builder. Instead you set the backgroundColor of the view (say, in -viewDidLoad) with the convenience method +colorWithPatternImage: and pass it a UI Image. For Instance:
•
Animation can be applied while its frame, bounds, center, transform, alpha… is being changed. The key is set start and end values between beginAnimations and commitAnimations, so called animation block.