Skip to content

Instantly share code, notes, and snippets.

@jkereako
Last active August 29, 2015 14:15
Show Gist options
  • Save jkereako/f825be2b1ea0814e1b2f to your computer and use it in GitHub Desktop.
Save jkereako/f825be2b1ea0814e1b2f to your computer and use it in GitHub Desktop.
Notes I've taken on iOS development

Sections

Glossary

On message sending

Objective-C sends messages to objects, it does not call functions. A function call has a section of code bound to the target object at compile time. A message is resolved to a pointer at runtime.

Static binding is the concept of associating data or code with an identifier at compile time. Late binding is associating data or code with an identifier at run time.

NSSets offer a performance benefit over NSArrays when checking for memebership.

NSNull is a singleton instance so checking for pointer equality (eg. (myObject == [NSNull null])) is sufficient

The Objective-C runtime caches memory locations of methods so other all caches are primed a function call is only slightly slower than a functions call (no idea what this means)

The variable _cmd is a runtime variable that denotes the current selector. It is like how self referrs to the current receiver.

Creating new threads can be an expensive operation so it is better practice to reuse threads (i.e. "pulling threads from a thread pool") and this is exactly what Grand Central Dispatch (GCD) does.

NSThread creates a new thread. GCD uses existing threads in the thread pool.

Cocoa will not put in locks and synchronization logic if a program does not use Cocoa's framework to create threads. An exaple is using the POSIX API for creating threads. You can use [NSThread isMultiThreaded] to check if Cocoa knows if the app is multithreaded or not.

Prefix.pch is a "pre-compiled header".

Each thread has itws own execution stack much like separate functions do. However, unlike functions threads can communicate with each other before completion or in a function's context, before the return statement.

Atomic operations can only be used with scalar data types and use the kernel to operate.

A good design minimizes communication between threads

Distributed objects is a method for communication between processes

The compiler directive @synchronize contains an implicit exception handler

To use POSIX threads with Cocoa, you must first put Cocoa in multi-threaded mode.

NSOperationQueue is always asynchronous. NSOperations themselves are synchronous by default

The four stages

  1. Pre-processer
  2. Compiler
  3. Assembler
  4. Linker

A 64-bit processer has 64-bit word sizes. Hence, the virtual address range is equivalent to 2^64 - 1 and likewise on 32-bit processors, 2^32 - 1, which is only 4GB of memeory.

Packages are intended for users while bundles are intended for developers

Use a Model View Vew-Model (MVVM) structure.

In ARM64, an int is 32-bits while a pointer is 64-bits.

IBOutlets and delegates ought to have weak references. IBOutlets ought to be declared in a class extension.

On Drawing

UIViews are rectangles, hence the method drawRect

Drawing views is an expensive process so reuse views whenever possible.

Virtual memory does not include the heap. Virtual memeory is not physical memeory.

Do not use NSZombie and the Allocations Instrument together because it will flag all zombies as leaks.

Dereferencing nil causes a crash.

Out parameters are autoreleased by default. An out-parameter is a pointer to a pointer. This is often seen when passing in an NSError.

Use the Static Analyzer to catch all bugs before running the app.

There are 2 categories of gestures: continuous and discrete.

Graphics

A graphics context is an opaque data type (CGContextRef) which encapsulates the information Quartz uses to draw images to an output device.

You can only obtain a graphics context from within the method drawRect. Before drawRect is called, the graphics context does not yet exist.

2 minutes video explaining Anti aliasing. When 4K is prevelant, anti-aliasing will be abandoned.

Glossary

  • Selector: A C-string which is the name of a method at run-time
/* File: usr/include/objc/objc.h */

typedef struct objc_selector *SEL;
  • Implementation: A pointer to a function
/* File: usr/include/objc/objc.h */

typedef id (*IMP)(id, SEL, ...); 
  • Method. A C-struct which encapsulates a selector and an implementation.
/* File: usr/include/objc/runtime.h */

typedef struct objc_method *Method;

struct objc_method {
    SEL method_name                                          OBJC2_UNAVAILABLE;
    char *method_types                                       OBJC2_UNAVAILABLE;
    IMP method_imp                                           OBJC2_UNAVAILABLE;
}                                                            OBJC2_UNAVAILABLE;
  • Dispatch table. The table which associates selectors with implementations.
  • Method swizzeling. To change the association between selector and implementation at run-time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment