[Pyobjc-dev] CoreData problem
                
                Brought to you by:
                
                    ronaldoussoren
                    
                
            
            
        
        
        
    | 
      
      
      From: Mark W. <ma...@ta...> - 2010-01-08 21:14:13
      
     | 
| I have the following code in both Objective-C (compiled as Cocoa tool) and Python as below, with the same input arguments both run to completion without error however the ObjectiveC version creates the sqlite3 db file and the python version doesn't. I'm stuck as to why and was planning on using python in this way to populate database for shipping in app bundle. Anyone got any clues?
Thanks
Mark
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
int main(int argc, char *argv[])
{
    printf("Using Managed Object Models from %s\n", argv[1]);
    printf("Creating sqlite database %s\n", argv[2]);
    
    NSError *err = Nil;
    NSAutoreleasePool *pool = [ [ NSAutoreleasePool alloc ] init ];
    
    // Load model
    NSBundle *bundle = [ NSBundle bundleWithPath:[ NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding ] ];
    NSArray *bundleArray = [ NSArray arrayWithObject:bundle ];
    NSManagedObjectModel *mom = [ NSManagedObjectModel mergedModelFromBundles:bundleArray ];
    if (!mom)
    {
        NSLog(@"Unable to load model");
        return 1;
    }
        
    // Setup persistent store
    NSURL *urlForDb = [ NSURL fileURLWithPath:[ NSString stringWithCString:argv[2] encoding:NSUTF8StringEncoding ] ];
    NSPersistentStoreCoordinator *psc = [ [ NSPersistentStoreCoordinator alloc ] initWithManagedObjectModel:mom ];
    NSPersistentStore *ps = [ psc addPersistentStoreWithType:NSSQLiteStoreType configuration:Nil URL:urlForDb options:Nil error:&err ];
    
    if (!ps)
    {
        NSLog(@"%@", err.description);
        return 1;
    }
            
    [ pool release ];
    
    return 0;
}
and...
#!/usr/bin/python2.6
from CoreData import *
from Foundation import *
import sys
        
if __name__ == '__main__':
    print 'Using Managed Object Models from', sys.argv[1]
    print 'Creating sqlite database', sys.argv[2]
    err = None
    
    pool = NSAutoreleasePool.alloc().init()
    
    # Load model
    bundle = NSBundle.bundleWithPath_(sys.argv[1])
    bundleArray = NSArray.arrayWithObject_(bundle)
    mom = NSManagedObjectModel.mergedModelFromBundles_(bundleArray)
    if mom is None:
        raise "Unable to load model"
        
    # Setup persistent store
    urlForDb = NSURL.fileURLWithPath_(sys.argv[2])
    psc = NSPersistentStoreCoordinator.alloc().initWithManagedObjectModel_(mom)
    ps = psc.addPersistentStoreWithType_configuration_URL_options_error_(NSSQLiteStoreType, None, urlForDb, None, err)
    if ps is None:
        raise err.description()
    pool.release()
 |