IOS Coding Tips for Beginners

1. Create view objects in Interface builder not in source code.

2. Flower brackets always be there in if conditions or while loops, even it has single statement.

3. Give one line space between @implementation and @synthesize

4. Open flower bracket “{” should start in next line.

5. Give one line space above conditional or loop statements like if, while, for.

6. The method name itself should resembles its behavior.

7. Remove unnecessary methods which are created by the file templates.

8. Use Edit->Format->Re-Indent to re-indent the selection of statements.

9. Don’t use string literals as keys, make the string literal as constant and use that. Place all constants in a common file.

10. Try to use property directly than calling the accessory method. for example Object.memberVariable than [Object memberVariable];

11. Try to define all literals in common file.

12. Instead of using literals, create meaningful constants for them in common file and use them.

13. Always group the things like constants, statements, etc.

14. The format for method signature should be like
– (void) methodName:(id) sender;

15. One line space between logical group of statements and two lines between physical groups.

16. Try to eliminate autorelease objects, instead use retain and release.

17. If you are declaring a UI object, please suffix the type to the variable. For example, if you are declaring a UILabel object with name ‘userName’, then name it ‘userNameLabel’.

18. Maintain all image names in lowercase with underscore dividing the inline words.

19. Directly access the variable instead of using property in the same class. For example, don’t access

UITableView mTableView;
@Property () UITableView *tableView;
//To reload the table in the same class use
[mTableView reloadData]; // correct
[self.tableView reloadData]; //wrong

ARC: respondsToSelector Issue

Do either of the following.

[(NSObject*)self.delegate respondsToSelector:@selector(myClass:willDoSomething:)]

Or

@property (nonatomic, weak) NSObject<MyClassDelegate>* delegate;

Or

@protocol MyClassDelegate <NSObject>

Cited from http://stackoverflow.com/questions/9579337/self-delegate-respondstoselector-does-not-compile

How to get selected cell frame from UITableView

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
CGRect selectedCellFrame = [cell.superview convertRect:cell.frame toView:self.view];

IOS Coding Tips

1. Create view objects in Interface builder not in source code.

2. Flower brackets always be there in if conditions or while loops, even it has single statement.

3. Give one line space between @implementation and @synthesize

4. Open flower bracket “{” should start in next line.

5. Give one line space above conditional or loop statements like if, while, for.

6. The method name itself should resembles its behavior.

7. Remove unnecessary methods which are created by the file templates.

8. Use Edit->Format->Re-Indent to re-indent the selection of statements.

9. Don’t use string literals as keys, make the string literal as constant and use that. Place all constants in a common file.

10. Try to use property directly than calling the accessory method. for example Object.memberVariable than [Object memberVariable];

11. Try to define all literals in common file.

12. Instead of using literals, create meaningful constants for them in common file and use them.

13. Always group the things like constants, statements, etc.

14. The format for method signature should be like
        – (void) methodName:(id) sender;

15. One line space between logical group of statements and two lines between physical groups.

16. Try to eliminate autorelease objects, instead use retain and release.

17. If you are declaring a UI object, please suffix the type to the variable. For example, if you are declaring a UILabel object with name ‘userName’, then name it ‘userNameLabel’.

18. Maintain all image names in lowercase with underscore dividing the inline words.

19. Directly access the variable instead of using property in the same class. For example, don’t access

UITableView mTableView;
@Property () UITableView *tableView;
//To reload the table in the same class use
[mTableView reloadData]; // correct
[self.tableView reloadData]; //wrong

2010 in review

The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here’s a high level summary of its overall blog health:

Healthy blog!

The Blog-Health-o-Meter™ reads Fresher than ever.

Crunchy numbers

Featured image

A helper monkey made this abstract painting, inspired by your stats.

About 3 million people visit the Taj Mahal every year. This blog was viewed about 25,000 times in 2010. If it were the Taj Mahal, it would take about 3 days for that many people to see it.

 

In 2010, there were 10 new posts, growing the total archive of this blog to 69 posts.

The busiest day of the year was December 2nd with 155 views. The most popular post that day was How to disable UIWebView from user scrolling?.

Where did they come from?

The top referring sites in 2010 were d.hatena.ne.jp, discussions.apple.com, google.co.in, en.wordpress.com, and maltekraus.de.

Some visitors came searching, mostly for xul tooltip, iphone locale, backbarbuttonitem, nsurlconnection, and uiwebview disable scrolling.

Attractions in 2010

These are the posts and pages that got the most views in 2010.

1

How to disable UIWebView from user scrolling? April 2009
12 comments

2

UIScrollView: paging horizontally, scrolling vertically? October 2009
4 comments

3

How to get country name from iPhone locale settings March 2009
7 comments

4

How to rotate the image to it’s proper state July 2008
2 comments

5

Customize back bar button item title October 2009
2 comments