Objective-C中是没有private 和public之分的
写类方法时,通常为 +(void)
(官方文档中说道,类也是一个对象)
写实例调用方法 通常为 -(void)
例子:
Say.h
#import <Foundation/Foundation.h>
@interface Say : NSObject
- (void)sayHello:(int)value1 :(int)value2;
+ (void)printHello;
@end
Say.m
#import "Say.h"
@implementation Say
-(void)sayHello:(int)value1 :(int)value2{
NSLog(@"%d%d",value1,value2);
}
+(void)printHello{
NSLog(@"Hello");
}
@end
添加鼠标按钮事件调用方法
- (IBAction)ClickBtn:(id)sender {
Say *say = [[Say alloc]init];
[say sayHello:1 :2];
[Say printHello];
}
以NSString为例
+ (id)string; |
+ (id)stringWithString:(NSString *)aString; |
+ (id)stringWithFormat:(NSString *)format, …; |
+ (id)stringWithContentsOfFile:(NSString *)path encoding:(NSStringEncoding)enc error:(NSError **)error; |
+ (id)stringWithCString:(const char *)cString encoding:(NSStringEncoding)enc; |