spotify logo github logo X logo dribbble logo
  • Home
  • My Work
  • Inspiration
  • Journal

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.

  • The lowest-level programing code is called Assembly
  • Programs without a graphical interface are called daemons
  • For if statements, when using && wrap both statements in parentheses. Ex if((truckWeight > 0)  && (truckWeight < 4000))
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:

  • float b*, c*; instead of float* b, c;
  • A variable with * in front of it is a pointer

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];
}
  • If you are sending messages and nothing is happening, make sure you are not sending messages to a pointer that has be set to nil
  • If you send a message to nil, the return value is meaningless and should be disregarded
  • If you are not sure what kind of object the pointer is referring to you can use an id. Ex below:

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 X

Need some work done? Say hi 👋 Or just tell me your best joke and I’ll send you back one of mine.

  • This field is for validation purposes and should be left unchanged.
spotify logo spotify logo
github logo github logo
X logo X logo
dribbble logo dribbble logo
  • Home
  • My Work
  • Inspiration
    • Inspiration Boards
    • Inspiring Websites
    • Design Links
    • Web Dev Links
    • Music
  • Journal