要將所有,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的,我們中的()意味着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
什麼是 「ObjectiveResource」?什麼是告訴Xcode和編譯器有關正在發生的事情?
之後,事情看起來很正常,因爲他們有各種靜態和實例方法。我知道通過這樣做,從NSObject繼承的所有用戶類現在都擁有該項目的所有額外方法。
我的問題是NSObject後面的圓括號是什麼。那是引用一個頭文件,還是讓編譯器知道這個類正在被超載。
再次感謝和我的道歉提前,如果這是一個愚蠢的問題,但只是試圖瞭解我缺乏什麼。
標籤應該可能是'objective-c',而不是'客觀'和'c' – Davis 2010-04-13 23:52:12