使用核心数据启动时出错

时间:2013-11-23 03:49:30

标签: ios core-data

设置核心数据并添加对象后,我在启动时收到错误消息。在我添加下面的代码以添加对象之后,这开始发生了。任何帮助都会非常棒,非常感谢你!

这是我添加的代码 -

NSManagedObjectContext *context = [self managedObjectContext];
    TimeTravelFeed *timeTravelFeed = [NSEntityDescription
                                      insertNewObjectForEntityForName:@"TimeTravelFeed"
                                      inManagedObjectContext:context];
    timeTravelFeed.name = @"Test Bank";
    timeTravelFeed.city = @"Testville";
    timeTravelFeed.state = @"Testland";
    TimeTravelDetail *timeTravelDetails = [NSEntityDescription
                                            insertNewObjectForEntityForName:@"TimeTravelDetails"
                                            inManagedObjectContext:context];
    timeTravelDetails.closeDate = [NSDate date];
    timeTravelDetails.updateDate = [NSDate date];
    timeTravelDetails.zipCode = [NSNumber numberWithInt:12345];
    timeTravelDetails.feed = timeTravelFeed;
    timeTravelFeed.details = timeTravelDetails;
    NSError *error;
    if (![context save:&error]) {
        NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
    }

    // Test listing all FailedBankInfos from the store
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"TimeTravelFeed"
                                              inManagedObjectContext:context];
    [fetchRequest setEntity:entity];
    NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
    for (TimeTravelFeed *feed in fetchedObjects) {
        NSLog(@"Name: %@", feed.name);
        TimeTravelDetail *detail = feed.details;
        NSLog(@"Zip: %@", detail.zipCode);
    }

当我运行代码时,我在启动时遇到错误。任何帮助都会很棒!非常感谢你

以下是错误消息:

Ld /Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Products/Debug-iphonesimulator/Time\ Travel.app/Time\ Travel normal i386
    cd "/Users/mattmoss/Desktop/Time Travel"
    setenv IPHONEOS_DEPLOYMENT_TARGET 7.0
    setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk -L/Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Products/Debug-iphonesimulator -F/Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Products/Debug-iphonesimulator -F/Users/mattmoss/Desktop/Time\ Travel -filelist /Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Intermediates/Time\ Travel.build/Debug-iphonesimulator/Time\ Travel.build/Objects-normal/i386/Time\ Travel.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=7.0 -framework SystemConfiguration -framework CoreTelephony -framework AdSupport -framework Accelerate -framework CoreMedia -framework CoreData -framework AudioToolbox -framework AVFoundation -framework AssetsLibrary -framework StoreKit -framework Security -lz.1.1.3 -framework CoreLocation -framework CoreGraphics -framework CFNetwork -framework MediaPlayer -framework MobileCoreServices -framework QuartzCore -framework CoreImage -framework Social -framework Parse -framework MessageUI -framework UIKit -framework Foundation -Xlinker -dependency_info -Xlinker /Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Intermediates/Time\ Travel.build/Debug-iphonesimulator/Time\ Travel.build/Objects-normal/i386/Time\ Travel_dependency_info.dat -o /Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Products/Debug-iphonesimulator/Time\ Travel.app/Time\ Travel

duplicate symbol _OBJC_METACLASS_$_TimeTravelDetail in:
    /Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Intermediates/Time Travel.build/Debug-iphonesimulator/Time Travel.build/Objects-normal/i386/AppDelegate.o
    /Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Intermediates/Time Travel.build/Debug-iphonesimulator/Time Travel.build/Objects-normal/i386/TimeTravelFeed.o
duplicate symbol _OBJC_CLASS_$_TimeTravelDetail in:
    /Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Intermediates/Time Travel.build/Debug-iphonesimulator/Time Travel.build/Objects-normal/i386/AppDelegate.o
    /Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Intermediates/Time Travel.build/Debug-iphonesimulator/Time Travel.build/Objects-normal/i386/TimeTravelFeed.o
duplicate symbol _OBJC_METACLASS_$_TimeTravelDetail in:
    /Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Intermediates/Time Travel.build/Debug-iphonesimulator/Time Travel.build/Objects-normal/i386/AppDelegate.o
    /Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Intermediates/Time Travel.build/Debug-iphonesimulator/Time Travel.build/Objects-normal/i386/FeedViewController.o
duplicate symbol _OBJC_CLASS_$_TimeTravelDetail in:
    /Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Intermediates/Time Travel.build/Debug-iphonesimulator/Time Travel.build/Objects-normal/i386/AppDelegate.o
    /Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Intermediates/Time Travel.build/Debug-iphonesimulator/Time Travel.build/Objects-normal/i386/FeedViewController.o
duplicate symbol _OBJC_METACLASS_$_TimeTravelDetail in:
    /Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Intermediates/Time Travel.build/Debug-iphonesimulator/Time Travel.build/Objects-normal/i386/AppDelegate.o
    /Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Intermediates/Time Travel.build/Debug-iphonesimulator/Time Travel.build/Objects-normal/i386/TimeTravelDetail.o
duplicate symbol _OBJC_CLASS_$_TimeTravelDetail in:
    /Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Intermediates/Time Travel.build/Debug-iphonesimulator/Time Travel.build/Objects-normal/i386/AppDelegate.o
    /Users/mattmoss/Library/Developer/Xcode/DerivedData/Time_Travel-eetxmjagpmxeszasxhooqrxfizzk/Build/Intermediates/Time Travel.build/Debug-iphonesimulator/Time Travel.build/Objects-normal/i386/TimeTravelDetail.o
ld: 6 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

1 个答案:

答案 0 :(得分:1)

导入.m文件而非.h这就是运行程序的当前重复发生的原因