Posts Tagged ‘snippet’

Memory management is arguably the most difficult concept for beginner programmers to grasp. When I decided to go back to school, I was required to take beginner programming classes since there is no option to test in to computer science courses. I witnessed the hair-pulling frustration of the beginner students when memory management was introduced for the first time. The hardest part of that course was when I was asked to act as a sort of student teacher-aid, going around helping trying to help other students learn memory management.

Luckily, an author going by r_adem has released an excellent article explaining proper memory management on iOS. There are several snippets with detailed explanations outlining when and why you would use certain memory management methods.

He shows the right way and the wrong way to manage memory, both with code snippets. Check it out, and thanks to John Dowa at ManiacDev for the link, which can be found below.

[Via: ManiacDev.com]
[Link: How to avoid memory leaks in iPhone applications]

Here is some iOS code that allows you to generate your own terrain in a 2d iPhone side-scrolling style game by simply dragging your finger up and down. The possible potential uses are endless. This code uses Cocos2D.




(more…)

Let’s say you have a view overlaying another view that you would like to close in a fancy fashion when the user click a button, thus displaying the view directly below it. Put this code as your button’s IBAction message handler and tell me that doesn’t spice up your app like crazy! I am not going to explain how it looks, just try it. You’ll love it. It’s a nice use of code blocks too. :)

-(IBAction)onButtonClick:(id)sender {
	[UIView transitionWithView:self.view duration:0.2 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
		self.view.frame = CGRectOffset(self.view.frame, 0, -self.view.frame.size.height);
	} completion:^(BOOL finished) {
		[self.view removeFromSuperview];
		[self release];
	}];
}

The learning curve of Cocoa can be steep depending on your background, but it’s a climb that is sure to leave a smile on your face every few steps of the way. Just enough to offset the hair pulling and cursing that is sure to ensue from jumping into Cocoa programming for the first time. One of the features that sweetened things up for me was Cocoa’s UIView animation capabilities. There is a lot to cover, and I just don’t have the time to even think about how to approach a lesson on all the animation features. I will give you an example of basic animation and a possible implementation and point you in the direction of Apple’s documentation so that you can build upon what you learned here.

For more information make sure to read Apple’s documentation on the UIView class. There is a lot more you can do with but let this be simply a foundation for you to learn the basic concept.


(more…)

Twitter Me