Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Active Record throws NSInvalidArgumentException on Device

#6

Hi, today I set up a new project to give active record a try. I think it rocks. But only on the simulator :-(

When I deploy my project on a iPod it terminates with an error (see below).

The device is an iPod with software 2.1(5F137) installed.

My database looks like this:


CREATE TABLE people(id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR);
INSERT INTO "people" VALUES(1,'foo');
INSERT INTO "people" VALUES(2,'bar');

My class is:


//Person.h
@interface Person : ARBase {
}
@property(readwrite, assign) NSString *name;
@end

//Person.m
#import "Person.h"
@implementation Person
	@dynamic name;
@end

In the code I (try to) retrieve the rows of the table "people" like this:


ARSQLiteConnection *sqliteConnection = [[ARSQLiteConnection alloc]initWithConnectionInfo:[NSDictionary dictionaryWithObject:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"db"] forKey:@"path"] error:nil];
	[ARBase setDefaultConnection:sqliteConnection];

	NSArray *people = [Person find:ARFindAll];
	for(Person *p in people){
		NSLog(@"NAME: %@",  [p name]);
	}

The application terminates somewhere in [Person find].


2008-09-18 17:27:01.755 MyApp[1289:20b] *** +[Person className]: unrecognized selector sent to class 0x24e78
2008-09-18 17:27:01.762 MyApp[1289:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[Person className]: unrecognized selector sent to class 0x24e78'
2008-09-18 17:27:01.773 MyApp[1289:20b] Stack: (
    808221155,
    806100820,
    808224973,
    807957065,
    807851584,
    85773,
    76543,
    76033,
    75777,
    75681,
    21633,
    8629,
    816142796,
    816178484,
    812207357,
    807837135,
    807834471,
    827655876,
    816145636,
    816184028,
    8381,
    8244
)
terminate called after throwing an instance of 'NSException'

Reported by Leicester · September 18th, 2008 @ 04:47 PM

State: open
Milestone: none
Assigned to: Fjölnir Ásgeirsson Fjölnir Ásgeirsson

Activity

  1. Fjölnir Ásgeirsson
    Fjölnir Ásgeirsson
    • Assigned user set to Fjölnir Ásgeirsson
    • State changed from new to resolved
    • Tag set to iphone

    Hi, this is because the iPhone, doesn't implement -className. I've written a workaround for this and it's in the repository :) Downloading the latest version of active record should fix it. If not, please submit a comment on this ticket and I'll reopen it. (Maybe attaching your project)

    September 19th, 2008 @ 01:37 AM

  2. Fjölnir Ásgeirsson
    Fjölnir Ásgeirsson

    Turns out, I made a stupid error in my iphone workaround and you were completely right! I've fixed it and now it should work fine ;)

    September 19th, 2008 @ 10:38 AM

  3. Leicester
    Leicester

    There is no new version on github...

    September 20th, 2008 @ 05:25 PM

  4. Fjölnir Ásgeirsson
    Fjölnir Ásgeirsson

    Actually, I committed my changes about 3 minutes before posting my reply :) Just download the source again and you'll get the changes

    If you're using an old version of the iPhone template, you'll need to drag NSObject+iPhoneHacks.h & NSObject+iPhoneHacks.m into your project for the workarounds to be included.

    September 20th, 2008 @ 05:35 PM

  5. Andy Blackwell
    Andy Blackwell

    This may need revisiting. The only way I got activerecord to not crash in the simulator was by deleting the if statements that prevented these hacks from being added if build target was the simulator. Everything worked fine with them included.

    Using
    MAC OSX 10.6.2
    iPhone Simulator 3.1.2
    activerecord master

    deleted this if statement where I found it

    if (TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR)

    February 11th, 2010 @ 06:36 AM

  6. Andy Blackwell
    Andy Blackwell

    possibly just refactor to replace all

    [self className]

    with

    NSStringFromClass([self class])

    instead of the hacks

    February 11th, 2010 @ 07:02 AM

  7. Fjölnir Ásgeirsson
    Fjölnir Ásgeirsson
    • State changed from resolved to open

    well that's what NSObject (iPhoneHacks) does (Source/Utilities/iPhone Hacks/) try changing #if (TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR) to #if (TARGET_OS_IPHONE) and see if that makes it work.
    Back when I wrote that there was an inconsistency so [NSObject className] worked in the simulator but not on the device. They may have fixed that in the newer SDKs.
    If that fix works please make a patch and upload it here

    February 11th, 2010 @ 10:00 AM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.