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

Advertisements

Simulate different network conditions on iOS simulator

When enabled, the Network Link Conditioner can change the network environment of the iPhone Simulator according to one of the built-in presets:
  • EDGE
  • 3G
  • DSL
  • WiFi
  • High Latency DNS
  • Very Bad Network
  • 100% Loss

You can control the internet downlink/uplink bandwidth. BitTorrent/UTorrent some times won’t respect the upload limit so network-link-conditioner will control it.

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

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

Warning: Backslash and Newline separated by space

Warning: Backslash and Newline separated by space

Solution: The backslash (\) character is used as the continuation character to continue #define statements and strings to the next line. GCC expects the backslash character to be the very last character on the line. This warning indicates that there is a space after the backslash. Delete the space and any other characters that come after the backslash.

Blogged with the Flock Browser

How to remove all .svn folder from source code in Linux / Mac?

Cited from: http://www.techiecorner.com/154/how-to-remove-all-svn-folder-in-linux-mac/

find ./ -name “.svn” | xargs rm -Rf

Blogged with the Flock Browser

Decoding a UTF-8 NSString