Note that there are some explanatory texts on larger screens.

plurals
  1. POObjC: Alloc instance of Class and performing selectors on it leads to __CFRequireConcreteImplementation
    primarykey
    data
    text
    <p>I'm new to Objective-C and I'd like to abstract my database access using a model class like this:</p> <pre><code> @interface LectureModel : NSMutableDictionary { } -(NSString*)title; -(NSDate*)begin; ... @end </code></pre> <p>I use the dictionary methods <code>setValue:forKey:</code> to store attributes and return these in the getters. Now I want to read these models from a sqlite database by using the Class dynamically.</p> <pre><code> + (NSArray*)findBySQL:(NSString*)sql intoModelClass:(Class)modelClass { NSMutableArray* models = [[[NSMutableArray alloc] init] autorelease]; sqlite3* db = sqlite3_open(...); sqlite3_stmt* result = NULL; sqlite3_prepare_v2(db, [sql UTF8String], -1, &result, NULL); while(sqlite3_step(result) == SQLITE_ROW) { id modelInstance = [[modelClass alloc] init]; for (int i = 0; i &lt; sqlite3_column_count(result); ++i) { NSString* key = [NSString stringWithUTF8String:sqlite3_column_name(result, i)]; NSString* value = [NSString stringWithUTF8String:(const char*)sqlite3_column_text(result, i)]; if([modelInstance respondsToSelector:@selector(setValue:forKey:)]) [modelInstance setValue:value forKey:key]; } [models addObject:modelInstance]; } sqlite3_finalize(result); sqlite3_close(db); return models; } </code></pre> <p>Funny thing is, the <code>respondsToSelector:</code> works, but if I try (in the debugger) to step over <code>[modelInstance setValue:value forKey:key]</code>, it will throw an exception, and the stacktrace looks like:</p> <pre> #0 0x302ac924 in ___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___ #1 0x991d9509 in objc_exception_throw #2 0x302d6e4d in __CFRequireConcreteImplementation #3 0x00024d92 in +[DBManager findBySQL:intoModelClass:] at DBManager.m:114 #4 0x0001ea86 in -[FavoritesViewController initializeTableData:] at FavoritesViewController.m:423 #5 0x0001ee41 in -[FavoritesViewController initializeTableData] at FavoritesViewController.m:540 #6 0x305359da in __NSFireDelayedPerform #7 0x302454a0 in CFRunLoopRunSpecific #8 0x30244628 in CFRunLoopRunInMode #9 0x32044c31 in GSEventRunModal #10 0x32044cf6 in GSEventRun #11 0x309021ee in UIApplicationMain #12 0x00002988 in main at main.m:14 </pre> <p>So, what's wrong with this? Presumably I'm doing something really stupid and just don't see it...</p> <p>Many thanks in advance for your answers,<br> Arakyd :..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload