[英]Why am I getting “unrecognized selector” errors when subclassing GDataEntryBase from Google Data Objective-C Client Library?
我已經構建了Google數據API Objective-C客戶端庫,並將其鏈接並與我的應用程序(包括GTMOAuth2)一起使用,並可以將數據拉回來。 我需要使用Provisioning API (仍然只支持XML),因此我在自己的應用程序中構建了我需要的附加功能。 我想我終於想出了所有這些是如何工作的,我非常接近閱讀自定義元素,但我遺漏了一些東西。
我已經將GDataServiceGoogle
, GDataEntryBase
和GDataFeedBase
子類GDataServiceGoogle
,並且正在獲取正確的數據。 我從一個簡單直接的元素類型開始: quota
。 在Users Feed中,quota元素如下所示:
<apps:quota limit="2048"/>
所以,我添加了以下值構造:
@interface GDataQuotaProperty : GDataValueConstruct <GDataExtension>
+ (NSString *)extensionElementURI;
+ (NSString *)extensionElementPrefix;
+ (NSString *)extensionElementLocalName;
@end
@implementation GDataQuotaProperty
+ (NSString *)extensionElementURI { return kGDataNamespaceGApps; }
+ (NSString *)extensionElementPrefix { return kGDataNamespaceGAppsPrefix; }
+ (NSString *)extensionElementLocalName { return @"quota"; }
@end
我已經將以下方法添加到我的GDataEntryBase
子類中:
- (GDataQuotaProperty *)quota;
- (void)setQuota:(GDataQuotaProperty *)val;
實施如下:
- (GDataQuotaProperty *)quota {
return [self objectForExtensionClass:[GDataQuotaProperty class]];
}
- (void)setQuota:(GDataQuotaProperty *)val {
[self setObject:val forExtensionClass:[GDataQuotaProperty class]];
}
正如GDataObject.h
中的注釋中記錄的那樣 (我一直在使用GDataServiceGoogleCalendar
, GDataEntryCalendar
和GDataFeedCalendar
作為參考實現),在我的GDataBaseEntry
子類中,我實現了addExtensionDeclarations
,如下所示:
- (void)addExtensionDeclarations {
[super addExtensionDeclarations];
Class entryClass = [self class];
// User extensions
[self addExtensionDeclarationForParentClass:entryClass
childClasses:[GDataQuotaProperty class], nil];
}
但是,當我嘗試在回調中調用如下quota
方法時:
GDataTextConstruct *titleTextConstruct = [user title];
NSString *title = [titleTextConstruct stringValue];
GDataQuotaProperty *quotaConstruct = [user quota];
NSString *quota = [quotaConstruct stringValue];
我得到一個例外,這個錯誤:
2012-11-19 12:42:22.667 Google Apps Open Directory Sync[47679:903] -[GDataEntryBase quota]: unrecognized selector sent to instance 0x2836d0
在上面的例子中,我確實正確地返回了用戶名(元素的title
)而沒有錯誤。 此外, user
對象實際上是我的類型GDataEntryBase
子,不GDataEntryBase
本身(在調試器驗證),加上classForEntries
在我的方法GDataFeedBase
子類正確返回類我的子類的GDataEntryBase
),所以這兩者的之間它真的必須是正確的班級。 我的GDataEntryBase
子類的quota
方法有一個斷點,它永遠不會被觸發,所以我在這里缺少什么?
如上所述,我一直在與Calendar的Service / Feed / Entry實現進行比較(特別是accessLevel
和color
元素和方法),我只是沒有看到我缺少的東西。
提前感謝您提供的任何幫助。
雖然我已經在我的GDataFeedBase
子類中實現了classForEntries
方法,並正確地從它返回我的GDataEntryBase
子類的類,如下所示:
- (Class)classForEntries {
return [GDataEntryUser class];
}
我錯過了同一個GDataFeedBase
子類中的standardKindAttributeValue
的實現,該子類應該返回相應的類別模式URL(對於Google Provisioning API User,“http://schemas.google.com/apps/2006#user”)飼料)。 所以,我實現如下(雖然我實際上使用常量):
+ (NSString *)standardKindAttributeValue {
return @"http://schemas.google.com/apps/2006#user";
}
一旦addExtensionDeclarations
, classForEntries
和standardKindAttributeValue
全部正確實現, GDataEntryBase
就能夠正確地確定我的子類應該用於feed中的對象,因此我的選擇器被識別。
非常感謝Google的Greg Robbins 在Google Data API Objective-C客戶端庫討論組的這個主題中指出了正確的方向。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.