Fork me on GitHub

Alex Rupérez

Link: http://j.mp/11cTnHV
Published: 03 Jun 10:23
Alejandro Rupérez alexruperez pushed to master at alexruperez/iOS-Coding-Best-Practices http://j.mp/11cTnHV

iOS-Coding-Best-Practices
iOS-Coding-Best-Practices - iOS Coding Best...

View on GitHub


View README


iOS Coding Best Practices

File Structure

MyApp Files

MyModel.h

Description

MyModel header file. Header files contain class, type, function, properties, and constant declarations.

Documentation

Learning Objective-C: A Primer

NSObject Class Reference

NSObject Protocol Reference

MyModel.m

Description

MyModel source file. Source files can contain both Objective-C and C code, implement the methods declared in the header file and extended or inherited class methods.

Documentation

Learning Objective-C: A Primer

NSObject Class Reference

NSObject Protocol Reference

MyApp.xcdatamodeld

Description

Used by Core Data, groups versions of the model, each represented by an individual .xcdatamodel file, and an Info.plist file that contains the version information.

Documentation

Core Data Model Versioning and Data Migration Programming Guide

MyAppDelegate.h

Description

MyAppDelegate header file. Header files contain class, type, function, properties, and constant declarations.

Documentation

iOS App Programming Guide

UIApplication Class Reference

UIApplicationDelegate Protocol Reference

MyAppDelegate.m

Description

MyAppDelegate source file. Handle state transitions within the app. For example, this object is responsible for launch-time initialization and handling transitions to and from the background.

Documentation

iOS App Programming Guide

UIApplication Class Reference

UIApplicationDelegate Protocol Reference

Recommended code


//  MyAppDelegate.m
void uncaughtExceptionHandler(NSException *exception)
{
  NSLog(@"Exception: %@, %@", exception, [exception callStackSymbols]);
}

void signalHandler(int signal)
{
  NSLog(@"Signal: %d", signal);
}

- (void)setUncaughtExceptionHandler
{
  NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
}

- (void)setSignalHandler
{
  struct sigaction signalAction;
  memset(&signalAction, 0, sizeof(signalAction));
  signalAction.sa_handler = signalHandler;
  sigemptyset(&signalAction.sa_mask);
  signalAction.sa_flags = 0;
  sigaction(SIGABRT, &signalAction, NULL);
  sigaction(SIGILL, &signalAction, NULL);
  sigaction(SIGBUS, &signalAction, NULL);
  sigaction(SIGFPE, &signalAction, NULL);
  sigaction(SIGSEGV, &signalAction, NULL);
  sigaction(SIGTRAP, &signalAction, NULL);
  sigaction(SIGPIPE, &signalAction, NULL);
}

MyViewController.h

Description

MyViewController header file. Header files contain class, type, function, properties, and constant declarations.

Documentation

View Controller Programming Guide for iOS

UIViewController Class Reference

MyViewController.m

Description

MyViewController source file. Source files can contain both Objective-C and C code, implement the methods declared in the header file and extended or inherited class methods.

Documentation

View Controller Programming Guide for iOS

UIViewController Class Reference

MyStoryboard.storyboard

Description

A storyboard represents the screens in an app and the transitions between them.

Documentation

Your Second iOS App: Storyboards

UIStoryboard Class Reference

MyStoryboard-568h.storyboard

Description

A storyboard represents the screens in an app and the transitions between them. For 4-inch Retina Display.

Documentation

Your Second iOS App: Storyboards

UIStoryboard Class Reference

Recommended code


//  MyAppDelegate.m - application:didFinishLaunchingWithOptions:
NSString *storyboardName;
if ([[UIScreen mainScreen] bounds].size.height == 568) storyboardName = @"MyStoryboard-568h";
else storyboardName = @"MyStoryboard";

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[UIStoryboard storyboardWithName:storyboardName bundle:nil] instantiateInitialViewController];
[self.window makeKeyAndVisible];

Default.png

Description

To enhance the user’s experience at app launch, you must provide at least one launch image. iOS displays this image instantly when the user starts your app and until the app is fully ready to use. As soon as your app is ready for use, your app displays its first screen, replacing the launch placeholder image.

Documentation

iOS Human Interface Guidelines

Default@2x.png

Description

To enhance the user’s experience at app launch, you must provide at least one launch image. iOS displays this image instantly when the user starts your app and until the app is fully ready to use. As soon as your app is ready for use, your app displays its first screen, replacing the launch placeholder image. For Retina Display.

Documentation

iOS Human Interface Guidelines

Default-568h@2x.png

Description

To enhance the user’s experience at app launch, you must provide at least one launch image. iOS displays this image instantly when the user starts your app and until the app is fully ready to use. As soon as your app is ready for use, your app displays its first screen, replacing the launch placeholder image. For 4-inch Retina Display.

Documentation

iOS Human Interface Guidelines

Localizable.strings

Description

Default strings file. You can localize it in the Project Navigator and add new languages to your project.

Documentation

Resource Programming Guide

InfoPlist.strings

Description

Contains individual keys you want localized and the appropriately translated value.

Documentation

Information Property List Key Reference

MyApp.entitlements

Description

Set entitlement values in order to enable iCloud, push notifications, and App Sandbox.

Documentation

Entitlement Key Reference

MyApp-Info.plist

Description

App information property list file, comes preconfigured with keys that every information property list should have, like the app name.

Documentation

Information Property List Key Reference

main.m

Description

The main function in main.m calls the UIApplicationMain function within an autorelease pool.

Documentation

Start Developing iOS Apps Today

MyApp-Prefix.pch

Description

Add general imports or declare general project variables in this file.

Documentation

SDK Compatibility Guide

Defaults.plist

Description

You can declare the default values of NSUserDefaults on it.

Recommended code


//  MyAppDelegate.m - application:didFinishLaunchingWithOptions:
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Defaults" ofType:@"plist"]]];

Settings.bundle

Description

This bundle contains one or more Settings page files that describe the individual pages of preferences. It may also include other support files needed to display your preferences, such as images or localized strings.

Documentation

Preferences and Settings Programming Guide

MyAppTests.h

Description

MyAppTests header file. Header files contain class, type, function, properties, and constant declarations.

Documentation

Xcode Unit Testing Guide

MyAppTests.m

Description

MyAppTests source file. Source files can contain both Objective-C and C code, implement the methods declared in the header file and extended or inherited class methods.

Documentation

Xcode Unit Testing Guide

MyAppTests-Info.plist

Description

MyAppTests information property list file, comes preconfigured with keys that every information property list should have.

Documentation

Information Property List Key Reference

Recommended 3rd Party Frameworks

futuretap/InAppSettingsKit

Allows settings to be in-app in addition to being in the Settings app.

arashpayan/appirater

A utility that reminds your iPhone app's users to review the app.

ArtSabintsev/Harpy

Notify users when a new version of your iOS app is available, and prompt them with the App Store link.

a2/MKiCloudSync

Sync your NSUserDefaults to iCloud automatically. (Alexsander Akers fork)

AFNetworking/AFNetworking

A delightful iOS and OS X networking framework.

rs/SDWebImage

Asynchronous image downloader with cache support with an UIImageView category.

jdg/MBProgressHUD

Displays a translucent HUD with an indicator and/or labels while work is being done in a background thread.

myell0w/MTStatusBarOverlay

Custom status bar overlay seen in Apps like Reeder, Evernote and Google Mobile App. WARNING: iOS Human Interface Guidelines doesn't recommend an overlay on top of the UIStatusBar.

AlexBarinov/UIBubbleTableView

Cocoa UI component for chat bubbles with avatars and images support.

Moped/MPNotificationView

An in-app notification view that mimics the iOS 6 notification views which appear above the status bar.