Objective C Basics...
What is a Class?
2 - Methods: functions used to perform operations on the data
2 - control views
3 - accomplish many other purposes
- A Class is a data structure that contains:
2 - Methods: functions used to perform operations on the data
- A class is similar to "struct" in C but contains member functions to operate on data
- Classes are used in Objective-C to:
2 - control views
3 - accomplish many other purposes
Classes and Objects:
2 - Methods (action - what it does)
example: A dog (Object) is a specific Instance of an animal (Class)
- A Class is a template for an object and contains:
2 - Methods (action - what it does)
- A class nearly always inherits Properties and Methods from some other Class (called a "Superclass")
- In iOS the ultimate parents Class is NSOject
- An Object is a specific case (or Instance) of a Class
example: A dog (Object) is a specific Instance of an animal (Class)
- Declaring an Object is called "Instantiation"
Instantiating and Object:
~ always declare a pointer to an area of memory on the heap that will
hold the object
2 - Initialize the object using the Init Method
~ Alloc returns an Object
~ Use square bracket notation to call a method
- Two step process:
~ always declare a pointer to an area of memory on the heap that will
hold the object
2 - Initialize the object using the Init Method
- Syntax: ClassName *ObjectName = [[ClassName alloc] init];
~ Alloc returns an Object
~ Use square bracket notation to call a method
Instance Variables:
2 - defined in the Implementation File (.m) of a Class (@synthesize)
- Instance Variables are also called an "IVar"s
- An IVar is a variable declared in a Class that is accessed through an instance of that Class (an Object)
- In iOS 5, IVars are:
2 - defined in the Implementation File (.m) of a Class (@synthesize)
- Provide access to IVars through "getter" (accessor) Methods and "setter" (mutator) Methods via "dot notation"
- "getter" - member function (Method) that is used to access the value of an IVar
- "setter" - member function (Method) that is used to change the value of an IVar
Methods:
~ prefixed by a dash (-)
~ can be called from an Instance of a Class
2 - Class Methods:
~ prefixed by a plus (+)
~ can only be called from the Class itself
~ can NOT access IVars - IVars don't have scope until the instance is made
- Declared in the Classes Header file (.h)
- Defined in a Classes Implementation file (.m)
- Two types of Methods:
~ prefixed by a dash (-)
~ can be called from an Instance of a Class
2 - Class Methods:
~ prefixed by a plus (+)
~ can only be called from the Class itself
~ can NOT access IVars - IVars don't have scope until the instance is made
- Methods are the verbs that an Object/Class uses to modify or operate on the data within the Object/Class