//
Main.m
the difference between the methods of functions and objects
//
Created by Vic fan on 16/7/12.
copyright©2016 year Li Hongqiang . All rights reserved.
//
the difference between a function and an object method
Object Method :
-(void) run;
#import <Foundation/Foundation.h>
@interface person : nsobject{
@public
// Define instance variables
nsstring *_name; name
int _age; Age
}
declaration of the method ;
-(void) run; // Statement of the method of the person running
@end
implementation of the class
@implementation Person
implementation of the method
-(void) run{
NSLog(@ " Jay Chou's bedside Story ");
}
@end
int Main (int argc, const Char * argv[]) {
@autoreleasepool {
/**
* Create Objects
*/
person *p = [person new];
/**
* assigning values to instance variables
*/
p->_age = n;
p->_name = @ " Li Hongqiang ";
// call method
[P run];
// object method cannot call function
Object Method :
1 object methods begin with - the class method starts with a +
2 Object methods can only be called by Objects and cannot be called as functions
3 Object method collation / object All
4 The implementation of the object method can only be written in the @implementtation ... in @end
the declaration of an object method can only be written in @interface ... in @end
function :
1 All the functions are parallel.
2 when the function is used , it can be called directly
3 function does not exist affiliation
The 4 function cannot be written in the @interface , but
can be written in the @implation , and cannot be written in the main function.
5 function cannot access an instance variable in an object
}
return 0;
}
Li Hongqiang iOS Development oc[017] The difference between functions and methods