read more
You create an object in a two-step procedure called allocation and initialization.

When you want to include methods from other scripts, just import the header file like you do in C for stdin.h 

For creating a class, you use the @interface directive. Then class name. Then Colon. Then parent class (which could just inherit from the base class which is NSObject). So 

	@interface newClass : NSObject 
		int number; 
		id data; 
		NSString* name;
	- (id) initWithString:(NSString*)aName;
	+ (newClass*)createNewClassWithSTring:(NSString*)aName;

So between @interface and @end is where the class is defined. You have properties and method declarations. NOTE THAT THIS IS JUST FOR THE HEADER FILE, SO YOU ACTUALLY STILL HAVE TO WRITE THE IMPLEMENTATION OF THE CLASS IN .M

The minus sign means the method is an instance method (applies to an instance of that object) and the plus means it’s a class method (applies to the class, no particular instance). YOU HAVE TO USE CLASS METHODS TO CREATE A NEW INSTANCE OF THAT CLASS. 

You declare properties (presumably within a class?) in order to auto generate setters and getters for them. You can use the stuff in the parens to change the accessibility of that property (copy) (readonly) (weak), etc. Declare public properties in class header files. 

For writing the implementation of a class, you start with @implementation newClass. You always import the header file of the corresponding class at the top. Then you can implement the various methods. 

 Dynamic typing vs static typing: when using a variable that you know is going to just have one type, then static type it by saying “int” or “float”, or “newClass”, and then for dynamic typing you use “id”. Dynamic typing might be used when creating an array that has a collection that is not all of one type. The type “id” implies a pointer. 


Probably the most important diagram ever: 

Methods don’t have names…it’s just essentially what parameters they take. So the name of the above is “insertObject:atIndex:”. If no parameters, you just have one signature keyword and no colon. 

In order to call a method, they’re essentially saying you “message that object”. So to message an object, you use the square brackets. When sending a message you first specify the object you’re sending the message to, and then the parameters that it takes. So [myArray insertObject:anObject atIndex:0];
Would make the myArray object execute the method “insertObject:atIndex:”. 

Objective-C makes it easy to write smaller code by getting rid of temp variables. The way it does that is it allows you to nest messages inside each other. 

You can use dot notation to access the state of an object, so essentially change a property or something. By using the dot notation, you are essentially calling a setter on that property. 

[myAppObject.theArray insertObject:myAppObject.objectToInsert atIndex:0];

You probably want to use dot notation instead of messaging when you can, because I don’t really understand why you would have to have [myAppObject theArray] in brackets like that to get the equivalent result. 

Blocks…wtf. Okay they are essentially a block of code that you can execute at any time. They act sort of like a function. You define them by putting a carrot in front of a name. You specify return type, block name, parameter taken = parameter name, block body So you could make

int multiplier = 10; 

int (^myBlock)(int) = ^(int num) {return num * multiplier;};

Not useful to me right now. 


“ When your class implements the methods of a protocol, your class is said to conform to that protocol. From a practical perspective, a protocol defines a list of methods that establishes a contract between objects without requiring them to be instances of any specific class. This contract enables communication between those objects. One object wants to tell another object about the events it’s encountering, or perhaps it wants to ask for advice about those events.”

A protocol declares method that are not specific to a class, so any class can implement those methods. Things in brackets are protocols. 

Use “nil” when checking to make sure that most properties are defined. 

The first term, self, is a local variable that you can use within a message implementation to refer to the current object; it is equivalent to this in C++. SO YOU USE SELF WITHIN A METHOD IMPLEMENTATION, WHICH WILL NECESSARILY BE INSIDE OF A CLASS. SO EXACTLY LIKE “THIS” IN JAVA.