#6 open
Leicester

Active Record throws NSInvalidArgumentException on Device

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

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'

Comments and changes to this ticket

  • Fjölnir Ásgeirsson

    Fjölnir Ásgeirsson September 19th, 2008 @ 01:37 AM

    • 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)

  • Fjölnir Ásgeirsson

    Fjölnir Ásgeirsson September 19th, 2008 @ 10:38 AM

    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 ;)

  • Leicester

    Leicester September 20th, 2008 @ 05:25 PM

    There is no new version on github...

  • Fjölnir Ásgeirsson

    Fjölnir Ásgeirsson September 20th, 2008 @ 05:35 PM

    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.

  • Andy Blackwell

    Andy Blackwell February 11th, 2010 @ 06:36 AM

    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)

  • Andy Blackwell

    Andy Blackwell February 11th, 2010 @ 07:02 AM

    possibly just refactor to replace all

    [self className]

    with

    NSStringFromClass([self class])

    instead of the hacks

  • Fjölnir Ásgeirsson

    Fjölnir Ásgeirsson February 11th, 2010 @ 10:00 AM

    • 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

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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

ActiveRecord is an insanely easy to use database framework written in objective-c It's obviously "inspired" by (copying) the infamous ActiveRecord that comes with Rails(http://rubyonrails.org) But it tries to be more versatile when it comes to working with multiple connections.

Tags

Pages