- //
- // main.m
- // TimeAfterTime
- //
- // Created by current on 9/18/15.
- // Copyright :copyright: 2015 current. All rights reserved.
- //
- #import <Foundation/Foundation.h>
- @interface Foo: NSObject
- {
- NSInteger uid;
- }
- -(void) init: (NSInteger) _id;
- -(void) Bar;
- +(void) Bar;
- @end
- @implementation Foo
- -(void) init: (NSInteger)_id
- {
- uid = _id;
- }
- -(void) Bar
- {
- NSLog(@"My id is %ld", uid);
- }
- +(void) Bar
- {
- NSLog(@"Bar from Foo, No uid.");
- }
- @end
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
- Foo *p = [[Foo alloc] init];
- [p Bar];
- [Foo Bar];
- }
- return 0;
- }
复制代码 +代表类方法,相当于C++里static
-是实例方法,在一个类被实例化后才可以被调用
|