而且支持 Code Completion.
喜欢的请赞一个。
Objective-C
#import <Foundation/Foundation.h>
@interface FileHelper : NSObject
@property (readonly) NSString* name;
@property (readonly) NSString* format;
-(NSFileHandle*) openFile: (NSString*) path;
-(NSFileHandle*) openFile: (NSString*) path
withPermissions: (NSString*) permissions;
@end
@implementation FileHelper
-(NSString*) name {
return @"Macintosh";
}
-(NSString*) format {
return @"HFS+";
}
-(NSFileHandle*) openFile: (NSString*) path {
return [NSFileHandle fileHandleForReadingAtPath: path];
}
-(NSFileHandle*) openFile: (NSString*) path
withPermissions: (NSString*) permissions {
NSFileHandle* handle = nil;
if ([permissions isEqualTo: @"readonly"] || [permissions isEqualTo: @"r"]) {
handle = [NSFileHandle fileHandleForReadingAtPath: path];
} else if ([permissions isEqualTo: @"readwrite"] || [permissions isEqualTo: @"rw"]) {
handle = [NSFileHandle fileHandleForUpdatingAtPath: path];
}
return handle;
}
@end
eero language:
#import <Foundation/Foundation.h>
interface FileHelper
String name {readonly}
String format {readonly}
openFile: String, [withPermissions: String], return FileHandle
end
implementation FileHelper
name, return String = 'Macintosh'
format, return String = 'HFS+'
openFile: String path, withPermissions: String = 'readonly', return FileHandle = nil
if permissions == 'readonly' or permissions == 'r'
return FileHandle.fileHandleForReadingAtPath: path
else if permissions == 'readwrite' or permissions == 'rw'
return FileHandle.fileHandleForUpdatingAtPath: path
end