我有這樣的代碼,需要將它移植到電弧,但我不知道如何:如何在arc中替換class_createInstance?
case FIELDTYPE_OBJECT:
className = [fieldType substringWithRange:NSMakeRange(2, [fieldType length]-3)];
rel = class_createInstance(NSClassFromString(className), sizeof(unsigned));
Class theClass = [rel class];
if ([rel isKindOfClass:[DbObject class]]) {
//Load the record...
NSInteger Id = [rs intForColumn:[theClass relationName]];
if (Id==0) {
fieldValue = [rel init];
} else {
Db *db = [Db currentDb];
fieldValue = [db loadById: theClass theId:Id];
}
}
break;
的錯誤是:
error: 'class_createInstance' is unavailable: not available in automatic reference counting mode
怎麼更換呢?
我需要在運行時建立類對象。
這不會處理extraBytes參數class_createInstance –
使用alloc init時這仍然是必需的嗎? –
如果代碼使用額外的字節,是的。否則,沒有 –