Skip to content

Instantly share code, notes, and snippets.

Objective-C Coding Convention and Best Practices

Most of these guidelines are to match Apple's documentation and community-accepted best practices. Some are derived some personal preference. This document aims to set a standard way of doing things so everyone can do things the same way. If there is something you are not particularly fond of, it is encouraged to do it anyway to be consistent with everyone else.

This document is mainly targeted toward iOS development, but definitely applies to Mac as well.

Operators

NSString *foo = @"bar";
@jpwatts
jpwatts / xcode-git-version.sh
Created May 11, 2011 16:42
This Xcode 4 build phase script automatically sets the version and short version string of an application bundle based on information from the containing Git repository.
#!/bin/bash
# This script automatically sets the version and short version string of
# an Xcode project from the Git repository containing the project.
#
# To use this script in Xcode 4, add the contents to a "Run Script" build
# phase for your application target.
set -o errexit
set -o nounset
@chrismiles
chrismiles / random_funcs.c
Created June 6, 2011 07:05
Random number on iOS
/* Return a random integer number between low and high inclusive */
int randomInt(int low, int high)
{
return (arc4random() % (high-low+1)) + low;
}
/* Return a random BOOL value */
BOOL randomBool()
{
return (BOOL)randomInt(0, 1);
@jcsrb
jcsrb / gist:1081548
Created July 13, 2011 23:05
get avatar from google profiles, facebook, gravatar, twitter, tumblr
function get_avatar_from_service(service, userid, size) {
// this return the url that redirects to the according user image/avatar/profile picture
// implemented services: google profiles, facebook, gravatar, twitter, tumblr, default fallback
// for google use get_avatar_from_service('google', profile-name or user-id , size-in-px )
// for facebook use get_avatar_from_service('facebook', vanity url or user-id , size-in-px or size-as-word )
// for gravatar use get_avatar_from_service('gravatar', md5 hash email@adress, size-in-px )
// for twitter use get_avatar_from_service('twitter', username, size-in-px or size-as-word )
// for tumblr use get_avatar_from_service('tumblr', blog-url, size-in-px )
// everything else will go to the fallback
// google and gravatar scale the avatar to any site, others will guided to the next best version
@KATT
KATT / NSString+Distance.h
Created November 27, 2011 17:10
NSString+Distance category (using ARC)
//
// NSString+Distance.h
//
// Created by Alexander Johansson on 2011-11-27.
// Based on http://stackoverflow.com/q/5684973/590396
//
#import <Foundation/Foundation.h>
@interface NSString (Distance)
@djacobs
djacobs / automatedBuildAndUploadToTestflight.sh
Created April 18, 2012 04:20 — forked from amattn/automatedBuildAndUploadToTestflight.sh
Automated Xcode build and upload to TestFlight.
#!/bin/sh
# Current as working as of 2012/4/17
# Xcode 4.3.2
PROJECT_ROOT="$HOME/SomeDirWhereYourProjectLives/XXXXXXXX"
WORKSPACE="$PROJECT_ROOT/XXXXXXXX.xcodeproj/project.xcworkspace"
CONFIG="AdHoc"
SCHEME="XXXXXXXX"
@benvium
benvium / installMobileProvisionFile.sh
Created May 1, 2012 15:14
This script installs a .mobileprovision file via bash (no GUI session needed)
#!/bin/sh
# 2012 - Ben Clayton (benvium). Calvium Ltd
# Found at https://gist.github.com/2568707
#
# This script installs a .mobileprovision file without using Xcode. Unlike Xcode, it'll
# work over SSH.
#
# Requires Mac OS X (I'm using 10.7 and Xcode 4.3.2)
#
@seiji
seiji / jenkins-build-Unity-iPhone.sh
Created May 11, 2012 02:27
jenkins-build-Unity-iPhone-TestFlight
UNITY_APP_PATH=/Applications/Unity3.4/Unity.app/Contents/MacOS/Unity
UNITY_PROJECT_PATH=$WORKSPACE/Unity
UNITY_EDITOR_LOG_PATH=~/Library/Logs/Unity/Editor.log
XCODE_PROJECT_PATH=$WORKSPACE/Unity-iPhone
KEYCHAIN_LOCATION=~/Library/Keychains/login.keychain
XCODE_PROJECT_CONFIG_PATH=$XCODE_PROJECT_PATH/Unity-iPhone.xcodeproj
### EDIT AREA START
UNITY_BATCH_EXECUTE_METHOD=XXXXX
@orta
orta / ARSearchBar.h
Created May 12, 2012 17:25
Custom Search Bar
//
// ARSearchBar.h
// Artsy Folio
//
// Created by orta therox on 18/04/2012.
// Released under The MIT License
// http://www.opensource.org/licenses/mit-license.php
//
// Copyright (c) 2012 http://art.sy. All rights reserved.
//
@julianduque
julianduque / resize.sh
Created June 14, 2012 16:08
Bash script for resize and set quality to jpg images (works with sips on Mac OSX)
#!/bin/bash
for file in *.jpg
do
sips --resampleHeightWidthMax 1357 --setProperty formatOptions 80 $file
done;