Code snippet - Objective C - Properties on Snipplr
Developer tips and bits for iphone , mac and other application development.
Friday, January 22, 2010
Virtualization for Beginners
Virtualization for Beginners
Posted using ShareThis
A very good post about virtualisation is posted .Please check out
Posted using ShareThis
Saturday, January 16, 2010
Memory Management in iphone
Memory management with Iphone becomes mandatory , as the iphone OS donot handle garbage collection. Apple has not included the feature of memory management , with concern that , the burden on the IPhone OS will be more. The disadvatage of this is the application crashes from the user prespective . But the advantage with this is with the programmers to some extent, because the user will have the flexibility of playing around with memory.
Here are some of the possibilities that would lead to crash if memory is not mangaed properly.
1) First and foremost that an iphone programmer needs to know is how the retain count for the objects work.
Once you allocate an object then the retain count will be 1. If you retain the same for further computation then the retain count increases by 1 again . So totoally the retain count becomes 2.
Therefore before the scope ends , the object should be released twice.Here is the sample code snippet that explains the same.
NSString *string1=[[NSString alloc] init]; // retain count = 1
NSString *string1Copy = [string1 retain] ; // retain count = 2
2) Try using Instruments to check for any memory leaks . Visit the following the following site given by apple.
3) If the code block uses too much memory and if your not sure about the release use NSAutoReleasePool . Make sure u release this pool before the scope ends.
4) Try not using autorelease as much as possible
5) Handling of delegates : This is very important since , in the code if u assign an object to a delegate and u deallocate the object without clearing the reference , error is thrown as deallocated object is referenced , since the delegate references the object that is already released
Sunday, January 10, 2010
Animating the View in Iphone
Animation is an area that's into the world of technology for pleasing the user interface. Iphone is not less in this feature:
Here is a sample code for animating a view :
[UIView beginAnimations:nil context:NULL];
[UIView animationDuration:1.0f];
[UIView setAnimationTransito
Shake feature in iphone
IPhone is known for its fascinating features and shake feature is one of the kind.Iphone has 2 event features as touch and motion.
Lot of apps pertaining to the shake feature has successfully made its place in the app store, due to its effective utilisation.Here are the 3 methods that implements the shake feature:
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event;
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event;
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event;
As an example consider the following:
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"TEST"
message:@"Shake feature Implelmented" delegate:nil
cancelButtonTitle:@"Cancel "
otherButtonTitles:@" OK ",nil];
[alert show];
[alert release];
}
The above code snippet does nothing great , rather than displaying an alert notifying the use of Shake feature in iphone
Subscribe to:
Posts (Atom)