Method
1. The object method is a minus-
2. The Declaration of the object method must be written between @interface and @end
The implementation of the object method must be written between @implementation and @end
3. Object methods can only be called by objects
4. Object method collation \ Object All
Function
1. function can be written anywhere in the file (except between @interface and @end), function is file-owned
2. Function calls do not depend on the object
3. The member variable of an object cannot be accessed directly from the member variable name within the function
1: #import <Foundation/Foundation.h>
2:
3: @Interface Person:nsobject
4: @end
5:
6: @implementation Person
7: @end
8:
9: @Interface Car:nsobject
Ten: {//member variable \ instance variable
One : //int wheels = 4; not allowed to initialize here
: //static int wheels; You cannot use member variables as variables in C language arbitrarily.
: @ public
: int wheels;
: }
:
: -(void) run;
: -(void) fly;
: @end
:
+ : int main ()
: {
Max : //wheels = ten;
:/ *
: car *c = [car new];
: c->wheels = 4;
: //run ();
28:
: [C Run];
: * /
31:
: void test2 ();
33:
: test2 ();
35:
£ º return 0;
Panax Notoginseng :}
:
: @implementation Car
Max :
Double : -(void) fly
: {
43:
: }
:
* / *
A : void test2 ()
: {
A : NSLog (@ "called the Test2 function-%d", wheels);
}*/ :
Wuyi:
: void test ()
: {
Si : NSLog (@ "called the test Function");
: }
:
£ º -(void) run
The following :{
: test ();
: NSLog (@ "%d wheels of the car ran up", wheels);
A : }
+ : @end
Dark Horse programmer--"Dark Horse video Notes" The function and method of OC Language Foundation