Posts

Showing posts with the label ios

Understanding Anchor point in iOS

Image
Just to take notes for this regarding anchor point in iOS. This is taken from  developer.apple.com Specifying a Layer’s Geometry While layers and the layer-tree are analogous to views and view hierarchies in many ways, a layer's geometry is specified in a different, and often simpler, manner. All of a layer’s geometric properties, including the layer’s transform matrices, can be implicitly and explicitly animated. Figure 1  shows the properties used to specify a layer's geometry in context. Figure 1   CALayer geometry properties The  position  property is a  CGPoint  that specifies the position of the layer relative to its superlayer, and is expressed in the superlayer's coordinate system. The  bounds  property is a  CGRect  that provides the size of the layer ( bounds.size ) and the origin ( bounds.origin ). The bounds origin is used as the origin of the graphics context when you override a layer's drawing met...

objective-c: Do I have to release parameter objects or variable?

I was confused on this until I just realized that if the case is, -(NSString*)name:(NSString*) _name {     // I thought I need to do like [_name release];     return _name; } So instead, the _name paramater object anyway is being reference, so ideally, the releasing of the object from memory is outside, i.e. from the callers perspective. Like, NSString *stupid = @"Johnny Bravo"; [name setName:stupid]; [stupid release]; or I can do autorelease anyway.

Singleton implementation in iOS on Objective-C

Just read this very helpful article on implementing a singleton in iOS. Below is a simple snippet that is thread safe, and is indeed, faster than @synchorize when is executed. +(MyClass *)singleton { static dispatch_once_t pred; static MyClass *shared = nil; dispatch_once(&pred, ^{ shared = [[MyClass alloc] init]; }); return shared; } dispatch_once() function is indeed mentioned in Mac Developer Library that is useful in implementing singletons or global data. Hope you found this helpful.