Objective C Notes

August 17, 2017

Snippets

These are just raw notes on Objective C. They aren’t necessarily organized in any specific way, this is more of a board to place things I learn about the programming language. I used to have these unorganized within the notes app on my phone, but by placing them here I hope that someone else can use them too. If you have any questions on the notes or a question on a particular snippet feel free to reach out to me using the form at the bottom of this page.

int minutesPerPound;
if (isBoneless) {
   minutesPerPound = 15;
} else {
   minutesPerPound = 20;
}

is the same as:

int minutesPerPound = isBoneless ? 15 : 20;

? is the ternary operator

on printf, %s is a string, %d is a decimal

on printf /n is a new line

int x = 1;
x += 5 ;
is adding 5 to the variable x.

When declaring multiple variables as pointers make sure you do:

Class names usually begin with prefixes, for example NSLogs and NSDate are from the foundation framework. NS is short for NeXTSTEP, the platform for which Foundation was originally conceived.

In Objective-C you’ll see a lot of the following with is a check to see if the object has something in it:

if (fido != nil) {
   [fido goGetTheNewspaper];
}

NOT NSDate *expiration;
NSDate id expiration;

sleep(2); makes the program pause for 2 seconds before continuing

Hold down the option key and click on a method to see what it does

for (NSDate *d in dateList) {
   NSLog(@"Here is a date: %@", d);
}

The above is shorthand for looping through an array like:

NSUInteger dateCount = [dateList count];
for (int i = 0; i < dateCount; i++) {
   NSDate *d = dateList[i];
   NSLog(@"Here is a date: %@", d)
}

cmd + ctl + up arrow switches you between the header and implementation files of a class

when importing your custom class make sure to use “” marks instead of <>

An array of dictionaries with string keys and date objects is a property list (p-list)

@joekotlan on Twitter