开发者

Able to build app onto iPhone but core data for app is missing

I just moved my first app to my iPhone for testing (yeah). But开发者_StackOverflow中文版 when I run the app on the iPhone no data appears in my tableviews. My NSLogs also show 0 rows returning from my ManagedObject query when it runs on my iPhone. However, I always have data appearing in this app when I've run it on the Mac simulator.

Is there something I need to do to also get the core data database over to my iPhone? Is there a way to check to see if the database made it to the iPhone? I don't get any errors when it runs but the data isn't showing up.

Yes, I'm a newbie - appreciate your help.


First, copy the sqlite database with the seed data into your bundle by dragging it into Xcode.

Then, in your app delegate where you set up your persistent store, add this to the persistentStoreCoordinatormethod:

if (![[NSFileManager defaultManager] fileExistsAtPath:[storeURL path]]) {
    NSString *defaultStorePath = [[NSBundle mainBundle] 
       pathForResource:@"dbname" ofType:@"sqlite"];
   if (defaultStorePath) {
     [[NSFileManager defaultManager] 
        copyItemAtPath:defaultStorePath toPath:[storeURL path] error:nil];
   }
}       
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜