Monday, 15 February 2010

ios - Issue with custom NSManagedObject class core data in swift -



ios - Issue with custom NSManagedObject class core data in swift -

i start larn swift , want utilize info model class written in objective c. got weird bug when seek save info input boxes:

users.h

#import <foundation/foundation.h> #import <coredata/coredata.h> @interface users : nsmanagedobject @property (nonatomic, retain) nsstring * password; @property (nonatomic, retain) nsstring * username; - (nsstring *)tostring; - (void)addfunny:(nsstring *)prefix; @end

users.m

#import "users.h" @implementation users @dynamic password; @dynamic username; - (nsstring *)tostring { homecoming @"the username \(username) , password \(password)"; } - (void)addfunny:(nsstring *)prefix { self.username = [nsstring stringwithformat:@"%@%@", prefix, self.username]; } @end

here info model screenshot:

here save function:

@ibaction func btnsave_clicked(){ println("save \(txtusername.text)") allow appdel: appdelegate = uiapplication.sharedapplication().delegate appdelegate allow context: nsmanagedobjectcontext = appdel.managedobjectcontext allow ent = nsentitydescription.entityforname("users", inmanagedobjectcontext: context) var newuser = users(entity: ent, insertintomanagedobjectcontext: context) newuser.username = txtusername.text newuser.password = txtpassword.text context.save(nil) println(newuser) }

code lldb:

unresolved error error domain=nscocoaerrordomain code=134100 "the operation couldn’t completed. (cocoa error 134100.)" userinfo=0xb736c50 {metadata={ nspersistenceframeworkversion = 508; nsstoremodelversionhashes = { entity = <b2bc8535 3bcfcdf1 81eecadc d32d8511 cc030525 d4eb7d76 94d11d7c f5853918>; }; nsstoremodelversionhashesversion = 3; nsstoremodelversionidentifiers = ( "" ); nsstoretype = sqlite; nsstoreuuid = "0169c569-2a57-47f1-9ef6-684485cb1135"; "_nsautovacuumlevel" = 2; }, reason=the model used open store incompatible 1 used create store}, (error.userinfo)

this has nil swift. if update coredata model without defining merging / versioning rules mentioned in applee doc, need delete , reinstall application on device or simulator.

look @ error message:

the model used open store incompatible 1 used create store}

remove app simulator/or device , perform clean on project. should clear issues up. create sure not running in debugger when delete app or else won't delete properly.

if want sure gone (simulator), check directory

users/insert_your_user_here/library/application support/iphone simulator/ app's folder, under version you're running.

you can not expect changing installed model work on device no farther effort.

ios core-data swift

No comments:

Post a Comment