#import <Foundation/Foundation.h>
/**
默认的范围是protected
**/
@interface Animal :NSObject
{
int age;
NSString * name;
}
-(void)run:(int)speed;
@end
@implementation Animal
-(void)run:(int)speed{
NSLog(@"我的速度是%d",speed);
}
@end
int main(int argc, const char * argv[]) {
Animal* animal=[Animal new];
animal.run:44;
return 0;
}
貌似呼叫一個有參的方法就錯了。但是我記得好像可以呼叫無參的方法。是這樣的嗎?
天蓬老师2017-04-24 09:15:49
你問的是怎麼呼叫無參數的方法吧?
剛被Masonry的封裝震撼到,鍊式呼叫一氣呵成,優雅!完美!
@interface TestObject : NSObject
@property (nonatomic, readonly) dispatch_block_t function;
@end
@implementation TestObject
- (dispatch_block_t)function
{
return ^{
NSLog(@"function run !");
};
}
@end
TestObject * obj = [[TestObject alloc] init];
obj.function();