iOS NSBundle:Xcode7中的动态加载包错误

时间:2016-03-13 02:17:24

标签: ios nsbundle

我已经通过Xcode7创建了一个包含一些额外类的自定义包。我想动态地将bundle加载到我的新Xcode项目中,以便我可以使用这些额外的类。但是,我遇到加载错误:无法加载捆绑包“CustomGreeter”,因为它不包含当前架构的版本。“有没有人对此有任何想法?代码是如下:

NSString *bundlePath = @"/Users/LAL/Library/Developer/Xcode/DerivedData/CustomGreeter-eclhcyzsdwgsynhbccujsftunknl/Build/Products/Debug/CustomGreeter.bundle";
NSBundle *greeterBundle = [NSBundle bundleWithPath:bundlePath];
if(greeterBundle == nil){
    NSLog(@"Bundle not found at path");
}
else{
    //Dynamically load bundle
    NSError *error;
    BOOL isLoaded = [greeterBundle loadAndReturnError:&error];
    if(!isLoaded){
        NSLog(@"loading Error =%@", [error localizedDescription]);
    }
    else{
        //bundle loaded, create an object using bundle and send it a message
        Class GreeterClass = [greeterBundle classNamed:@"CustomGreeter"];

        id<Greeter> greeter = [[GreeterClass alloc] init];
        NSLog(@"%@", [greeter greeting:@"Hello"]);

        //Done with dynamically loaded bundle, now unload it
        //First release any objects whose class is defined in the bundle!
        greeter = nil;
        BOOL isUnloaded = [greeterBundle unload];
        if(!isUnloaded){
            NSLog(@"Couldn't unload bundle");
        }
    }
}

0 个答案:

没有答案