Powered by
Powered by
HuntMyIdeas-Inspire You To Make It Happen
Follow
   Me
  • Blogs
  • About Me
  • Home

What are best practices that you use when developing projects in Objective-C ?

6/20/2016

0 Comments

 
Picture
My objective in this article  to explore some points regarding best coding practices in iOS projects to make it robust,scalable and easy for maintenance.
​

As an iOS developer,you guys are recommended to follow some good coding style first of all.
1.NAMING CONVENTION
​

First establish a naming convention for all the things for the method names, class names, project names, images, etc.
​

PROJECT NAME (Do not put space while naming a directory/folder or any classes or project name).
Read:
some key concepts for an iPhone developer to learn as a fresher

We should set the finalised title/name of the project . (Example: NetworkingView or GameCenterViewController or LeaderBoardViewController etc).

​HOW TO NAME A CLASS ?

You should use Pascal Case for the folders and classes.
You should add a prefix of abbreviation of your project name to all the classes in the project.

Apple's Library reference:

How apple developers name their classes?
​
Example:
NSInteger
NSUserdefaults
UIView or UIButton
etc.

All class names should start with a capital letter.
You should choose a meaningful class name that will be relevant to the functionality.  

Example:
Suppose your project name is "SolitaireGame" and you want to create a class as
"Solitaireviewcontroller".
Your Class or Scene or Controller name should be as 

"SGSolitaireViewController.h"
"SGSolitaireViewController.m"

OR
SGSolitaireViewController.h  (cocos2d-x)
SGSolitaireViewController.cpp (cocos2d-x)


Note:
  • You should skip this convention only if you are using any category like (UIView+Animations).
  • Never create a class name like "SolitaireVC" or "SolitaireSC" or "VC" or "A" 

HOW TO NAME A METHOD ?
  • Use Camel Case for methods, properties & variables start with a lowercase letter i.e setFirstName:, userPassword etc.
  • Your method name should be very specific to the functionality.
  • Method names should be meaningful,no matter how lengthy it appears.
  • It should start with a small letter.

Example:
- (void)setProgressWithDownloadProgressOfTask:(NSURLSessionDownloadTask *)task
                                     animated:(BOOL)animated

Notes:
  • Don’t abbreviate names of methods,just spell them out, even if they’re long.
  • Never put any method names like "abc" or "xyz" or "remove" or "add".
  • Avoid ambiguity in method names that could be interpreted in more than one way.
​
     Example:
         "displayName" or "removeScene" or "removePopup".
  • You should express the exact functionality with a method name.
  • Methods that do the same thing in different classes should have the same name. (consistency).Never use underscores, dashes or hyphen between the words of a method


HOW TO NAME A VARIABLE ?

Naming a property or variable in objective C or C++ is same as an instance method name
It should start with a small letter.

Example:
@property (nonatomic, assign) UInt64 currentMemoryUsage;

NAMING CONSTANTS 

const float VSSlotsConstants;

NAMING ENUMS

typedef enum _VSSlotsMatrixMode {
    VSRadioModeMatrix           = 0,
    VSHighlightModeMatrix       = 1,
    VSListModeMatrix            = 2,
     VSTrackModeMatrix           = 3
} VSMatrixMode;


USING SINGLETONS 

Apple’s Developer Library considers the singleton one of the “Cocoa Core Competencies".
Using singletons  that will create a global state in your app and a hassle free way to reuse your game states for every session.

It avoids extra memory usage and gives smooth user experience (No more object creation again and again).

Create all common and singleton objects in App Delegate and then expose them by UIResponder Category.

Example:

Creating "VSAppConfiguration.m" or "VSGameInAPPHelper.cpp"
Creating a singleton like "Music" OR "SoundHandlerClass".


FOLLOW BEST DESIGN PATTERN:

Example: 

MVC (Model View Controller).

Model → Data (Brain of the application- Data & calculations)
View → User Interface (window through which your users interact with your application)

Controller → Core Logic  (Bridge between the model and your Views).

Picture
Read:
Basic iOS interview Questions And Answers 
Top 5 Frequently Asked iOS Interview Questions And Answers.
Top  Interview Questions And Answers in Objective C
​
Most Important iPhone interview Questions and Answers

DIRECTORY STRUCTURE:

GLOBAL SCOPE (Constants,Global Helper Classes,Global Singletons,Global Variables,Global Resources like images,Utility Classes).

Keep the above resources in a common folder.

ISOLATED OR SEPARATE DIRECTORY (LOBBY,GAME CONROLLERS OR SCENES)
Make sure that all the resources are placed in specific folder 

Example:
  • Suppose you have designed a Lobby,all your resources (Model,Views,Images,sounds) used in Lobby design should be in a folder named " Lobby".
  • If you have designed a Slots Machine (Game logic,UI,Sound),all the resources (Models,Views or layers or scenes or controllers) should be in particular folder like "SpinTillYouWinMachine" as follows.
Picture
PLUGINS OR FRAMEWORKS IN SEPARATE FOLDERS 
  • Each Plugin folder should contain all corresponding models,singletons,Views or scenes ,images,sounds .
  • we should programme the plugins or Add-ons of our application as an isolated entity.

  • All the business logics and popup construction should be implemented within the plugin classes,what we need to do,just call a method it will show a popup fulfilling all conditions.

  • In future,if someone of our developer needs a plugin,you just have to share that folder and calling method,that's it.


USING COMMENTS AND PRAGMA MARK

Using comments or pragma marks,makes your code makes a project easy to understand and maintain further.

It puts very less stress on developers mind .


Picture
Some Important Points:

1)Use Automatic Reference Counting
Always use ARC. All new code should be written using ARC, and all
legacy code should be updated to use ARC

2)Create a property for every ivar and use self to access it Always create a @property for every data member and use “self.name”
to access it throughout your class implementation
Alway declare “atomic” or “nonatomic” attribute
Always use the “nonatomic” attribute on your properties, unless you are
writing a thread-safe class and actually need access to be atomic.


A lot more to understand in a long run.My objective of writing this article for helping you to some extent.

Suggested Reading:


Some important points About View Controller.
What Are The Main Responsibilities Of A View Controller ?
Explain The Difference Between loadView() And viewDidLoad() in iOS
How To Explain UIViewController Life Cycle in iOS ?


0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    Enter your email address:

    Delivered by FeedBurner

    RSS Feed

    Archives

    December 2019
    August 2018
    January 2018
    December 2017
    November 2017
    October 2017
    August 2017
    April 2017
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    December 2014
    November 2014
    October 2014
    September 2014
    August 2014
    July 2014
    June 2014


    ​​Categories

    All
    Affiliate Marketing
    Alexa Rank
    Apple's Latest Updates
    Blog Tips
    Cocos2d X
    Cocos2d-x
    Google AdSense Tips
    Grab-some-ultimate-ideas
    How-to-create-a-twinkling-star-background-effect-in-ios
    In-App Purchase Tutorial In Cocos2d-x (C++) Using SDKBOX
    Ios Interview Questions And Answers
    IOS Multiple Choice Questions And Answers
    Objective C
    Online Business
    Python
    Secrets To Effective IPhone App Marketing
    SEO Tips
    Swift Interview Questions
    Swift Tutorials
    Top 10 Articles Objective C
    Top 10 Articles-Objective-C
    Top 10 Popular Movies Ever
    Top 10 Popular Things To Know
    Top 10 Ultimate Issues Xcode
    Top 400 IOS Interview Questions
    Top IOS Sample Projects To Learn From
    Top Secrets To App Marketing
    UICollectionView
    Unity 3D
    Xcode

WELCOME TO HUNTMYIDEAS

Picture
I am Jitendra Gochhayat,an iOS Developer,Designer,blogger,
​from Odisha,India.
I write about ​​​blog tips and,
Make money online Tips,
​Objective C tutorials
SUSCRIBE TO NEWSLETTER

    Subscribe to this blog and receive notifications of new posts by email

Suscribe
Picture
Picture
Picture
Picture
Picture
HuntMyIdeas-2016 Powered By Weebly
Picture
Powered by Create your own unique website with customizable templates.
Powered by
Powered by