我在我的項目中使用KVC。KVC valueForKey返回一個__NSCFConstantString而不是一個__NSCFString
而且,在我班的一個,我寫的屬性:
@property (nonatomic, strong) NSString *notes;
我想提出一個的NSString對象在該屬性:
和設定值之前,我想測試目的地的班級名稱。
a = [ newContainer valueForKey:@"notes"];
if(a != nil && ![ b isKindOfClass:[ a class ] ])
// here b is the new NSString value
結果是xcode表示類不一樣!
(gdb) po [ b class ]
__NSCFString
(gdb) po [ a class ]
__NSCFConstantString
我讀了這不是很重要,__NSCFConstantString是NSString的私有子類。
但是,在我的情況下,我需要檢查我的對象的所有屬性,然後再更新它。
而且我不希望在我的代碼有:
// OK, classes aren't the same ...
// ---- BUT WE MUST test it again to know if a is a NSString and b a subclass of NSString or anything else ...
beurk!
有沒有人有同樣的問題?
非常感謝您的幫助!