iPhone SDK/Objective C语法问题

Kop*_*ppo 2 iphone sdk objective-c

对所有人来说

我正在查看来自http://iphoneonrails.com/的示例项目,我看到他们使用了NSObject类并为SOAP调用添加了方法.

他们的示例项目可以从http://iphoneonrails.com/downloads/objective_resource-1.01.zip下载.

我的问题与我对以下语法缺乏了解有关,因为我还没有在iPhone项目中看到它.

有一个名为NSObject + ObjectiveResource.h的头文件,它们声明并更改NSObject以为该项目提供额外的方法.名称中的"+ ObjectiveResource.h"是否有特殊的语法,或者只是开发人员的命名约定.

最后在NSObject类中我们有以下内容

#import <Foundation/Foundation.h>

@interface NSObject (ObjectiveResource)


// Response Formats
typedef enum {
 XmlResponse = 0,
 JSONResponse,
} ORSResponseFormat;

// Resource configuration
+ (NSString *)getRemoteSite;
+ (void)setRemoteSite:(NSString*)siteURL;
+ (NSString *)getRemoteUser;
+ (void)setRemoteUser:(NSString *)user;
+ (NSString *)getRemotePassword;
+ (void)setRemotePassword:(NSString *)password;
+ (SEL)getRemoteParseDataMethod;
+ (void)setRemoteParseDataMethod:(SEL)parseMethod;
+ (SEL) getRemoteSerializeMethod;
+ (void) setRemoteSerializeMethod:(SEL)serializeMethod;
+ (NSString *)getRemoteProtocolExtension;
+ (void)setRemoteProtocolExtension:(NSString *)protocolExtension;
+ (void)setRemoteResponseType:(ORSResponseFormat) format;
+ (ORSResponseFormat)getRemoteResponseType;


// Finders
+ (NSArray *)findAllRemote;
+ (NSArray *)findAllRemoteWithResponse:(NSError **)aError;
+ (id)findRemote:(NSString *)elementId;
+ (id)findRemote:(NSString *)elementId withResponse:(NSError **)aError; 

// URL construction accessors
+ (NSString *)getRemoteElementName;
+ (NSString *)getRemoteCollectionName;
+ (NSString *)getRemoteElementPath:(NSString *)elementId;
+ (NSString *)getRemoteCollectionPath;
+ (NSString *)getRemoteCollectionPathWithParameters:(NSDictionary *)parameters;
+ (NSString *)populateRemotePath:(NSString *)path withParameters:(NSDictionary *)parameters;

// Instance-specific methods
- (id)getRemoteId;
- (void)setRemoteId:(id)orsId;
- (NSString *)getRemoteClassIdName;
- (BOOL)createRemote;
- (BOOL)createRemoteWithResponse:(NSError **)aError;
- (BOOL)createRemoteWithParameters:(NSDictionary *)parameters;
- (BOOL)createRemoteWithParameters:(NSDictionary *)parameters andResponse:(NSError **)aError;
- (BOOL)destroyRemote;
- (BOOL)destroyRemoteWithResponse:(NSError **)aError;
- (BOOL)updateRemote;
- (BOOL)updateRemoteWithResponse:(NSError **)aError;
- (BOOL)saveRemote;
- (BOOL)saveRemoteWithResponse:(NSError **)aError;


- (BOOL)createRemoteAtPath:(NSString *)path withResponse:(NSError **)aError;
- (BOOL)updateRemoteAtPath:(NSString *)path withResponse:(NSError **)aError;
- (BOOL)destroyRemoteAtPath:(NSString *)path withResponse:(NSError **)aError;

// Instance helpers for getting at commonly used class-level values
- (NSString *)getRemoteCollectionPath;
- (NSString *)convertToRemoteExpectedType;

//Equality test for remote enabled objects based on class name and remote id
- (BOOL)isEqualToRemote:(id)anObject;
- (NSUInteger)hashForRemote;

@end
Run Code Online (Sandbox Code Playgroud)

NSObject的()意味着什么是"ObjectiveResource"?是什么告诉Xcode和编译器发生了什么......?

之后,事情看起来很正常,因为它们有各种静态和实例方法.我知道通过这样做,从NSObject继承的所有用户类现在都拥有该项目的所有额外方法.

我的问题是在NSObject之后括号是做什么的.这是引用头文件,还是让编译器知道这个类被过度使用.

再次感谢,如果这是一个愚蠢的问题,我只是提前道歉,只是想了解我缺乏的东西.

Ale*_*yne 5

这是一个Category.它允许您扩展现有的类.代替

MyClass : MySuperclass
Run Code Online (Sandbox Code Playgroud)

它通过以下方式宣布:

MyClass (MyCategoryName)
Run Code Online (Sandbox Code Playgroud)

该文件的名称只是一个约定MyClass+MyCategory.h.文件名没有什么区别,但是这样可以很容易地告诉文件包含一类扩展特定类的方法.

请注意,您可以在类别中实现新方法,但不能添加实例变量.要在代码库中的其他位置使用类别,您只需导入类别标题,它所包含的所有方法都将在类别扩展的对象上可用.