Objective C Cheat Sheet



The mulle-objc Community:

#MakeObjCGreatAgain

View on GitHub

+[mulle-objc about]

mulle-objc enables you to write in Objective-C on various platforms. It consists of the following parts:

Introduction To Objective-C Programming Language. Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. It was the main programming language used by Apple for the OS X and iOS operating systems, and their respective application programming interfaces (APIs): Cocoa and Cocoa Touch prior to the introduction of Swift. Except for the compiler and the debugger all these mulle-objc components are licensed under BSD terms.mulle-gdb is GPL3 licensed. Mulle-clang uses the llvm license. All of these are Open Source licenses. Takes care of own needs appropriately 2. Establishes and sustains positive relationships a. Forms relationships with adults b. Responds to emotional cues c. Interacts with peers d. Makes friends 3. Participates cooperatively and constructively in group situations a. Balances needs and rights of self and others b. Solves social problems.

Developer GuideDe Re mulle-objc
Cheat Sheetmulle-objc Cheat Sheet
Class libraryMulleFoundation
MulleWeb
Runtime and Root classesMulleObjC
C librariesmulle-c
mulle-concurrent
mulle-core
Toolsmulle-sde
Craftinfoscraftinfo
Compilermulle-clang
Debuggermulle-gdb

Except for the compiler and the debugger all these mulle-objc components are licensed under BSD terms. mulle-gdb is GPL3 licensed. mulle-clang uses the llvm license. All of these are Open Source licenses.

+[mulle-objc join]

Objective C Cheat Sheet Support the project by becoming a public member of mulle-objc and to get a nice logo for your github profile:

+[mulle-objc goals]

  • Improve and maintain Objective-C for use in the next decades
  • Run everywhere C runs
  • Everything faster than everyone else
  • Enable static linking
  • Enable massive threading
  • The runtime should be completely unloadable
  • Should work in real time applications
  • No magic
  • Keep the Spirit of C

See 'About mulle-objc' for more in-depth information and technical background.

+[mulle-objc install]

There is a variety of install methods available:
PlatformMethod
MacOSbrew
Linuxapt
DockerDockerfile
Unix/MinGWInstallation script

See foundation-developer for installation instructions.

Read the latest release announcement for version 0.18 for what's new.

class

Declares class as known without having to import the class’ header file.

Marks end of the class, protocol or interface declaration.

protocol

Marks the start of a protocol declaration.

Get a protocol object by name:

Methods following are required (default).

Methods following are optional. Classes making use of the protocol must test Optional protocol methods for existence:

C Programming Cheat Sheet Pdf

interface

Marks the start of a class or category declaration. Objective-C classes should derive from NSObject directly or indirectly. Use @interface to declare that the class conforms to protocols.

Category declaration - Objective-C category cannot add instance variables. Can to conform to (additional) protocols. CategoryName can be omitted if in implementation file making methods “private”.

Declares instance variables after @public directive as publicly accessible. Read and modified with pointer notation:

Declares instance variables after @package directive as public inside the framework that defined the class, but private outside the framework. Applies only to 64-bit systems, on 32- bit systems @package has the same meaning as @public.

Default. Declares instance variables after @protected directive as accessible only to the class and derived classes.

Declares the instance variables following the @private directive as private to the class. Not even derived classes can access private instance variables.

Declares a property which accessible with dot notation. @property can be followed by optional brackets within which property modifiers specify the exact behavior of the property. Property modifiers: readwrite (default), readonly – Generate both setter & getter methods (readwrite), or only the getter method (readonly).

assign (default), retain, copy – For properties that can safely cast to id. Assign assigns passed value – retain sends release to an existing instance variable, sends retain to the new object, assigns the retained object to the instance variable – copy sends release to the existing instance variable, sends copy to the new object, assigns the copied object to the instance variable. In latter two cases you are responsible for sending release (or assigning nil) to the property on dealloc.

atomic (default), nonatomic – Atomic properties are thread-safe. Nonatomic properties are not thread-safe. Nonatomic property access is faster than atomic and often used in single- threaded apps, or cases where you’re absolutely sure the property will only be accessed from one thread.

strong (default), weak – Available if automatic reference counting (ARC) is enabled. The keyword strong is synonymous to retain, while weak is synonymous to assign, except a weak property is set to nil if instance is deallocated.

Returns the selector type SEL of the given Objective-C method. Generates compiler warning if the method isn’t declared or doesn’t exist.

Objective C To Swift Cheat Sheet

implementation

Marks start of a class’ or category implementation.

Class implementation:

Category implementation:

Generate setter and getter methods for a comma separated property list according to property modifiers. If instance variable is not named exactly like @property, you can specify instance variable name after the equals sign.

Tells the compiler the setter and getter methods for the given (comma separated) properties are implemented manually, or dynamically at runtime. Accessing a dynamic property will not generate a compiler warning, even if the getter/setter is not implemented. You will want to use @dynamic in cases where property getter and setter methods perform custom code. @end – Marks end of class implementation.

Encapsulates code in mutex lock ensuring that the block of code and locked object are only accessed by one thread at a time.

Declares a constant NSString object. Does not need to be retained or released.

Used for handling and throwing exceptions. Throwing and Handling exceptions:

In an ARC (automatic reference counting) enabled about 6x faster than NSAutoreleasePool and used as a replacement. Avoid using a variable created in an @autoreleasepool after the autoreleasepool block.

Returns the character string encoding of a type.

Sets alias name for an existing class. First parameter is the alias, second the actual class name. @compatibility_alias AliasClassName ExistingClassName After this you can use AliasClassName in place of ExistingClassName.

C Code Cheat Sheet

Notes

C Programming Cheat Sheet

  • Based on a cheat sheet by Chaosky