iOS Tips and Tricks
I will be adding content to this page over time. Hopefully this will start to become a good resource to others starting out in iOS.
Enjoy!
^Organize with Pragma Marks
Pragma Marks are simple directives that you can add to your source code to help with organization. They can be added to both xcode header and implementation files and provide easier navigation to your function drop-downs.
^Use Macros
Using Macros in your application brings several benefits. They make your code less verbose in addition to providing a central location for code shortcuts.
Take a look at how to add this useful tool to your projects…
^Reverse ordered collections quickly
You can easily and quickly reverse a ordered collection with the code below.
orderedCollection = [[orderedCollection reverseObjectEnumerator ] allObjects ];
Learn More about reversing collections
^Use Fast Enumeration
Fast Enumeration provides better performance when running through collections and is less verbose.
for/in loop
for( id obj in collection ) // your code for each object
Block Enumeration
[NSArray enumerateObjectsAtIndexes:(NSIndexSet *)
options:(NSEnumerationOptions)
usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
// Your code here...
} ];
Learn More about Fast Enumeration
^Use shadowPaths for CALayer shadows
This will improve performance when you add CALayer Shadows to elements in your application.
[UIElement.layer setShadowPath:[[UIBezierPath bezierPathWithRect:shadowBorder.bounds ] CGPath ] ];
Learn More about CALayer shadows
^Use Should Rasterize
Use the CALayer shouldRasterize property on objects that are static. Setting this to YES on an elements layer will tell it to render as a bitmap before compositing.
[UIElement.layer setShouldRasterize:YES ];
