【发布时间】:2020-07-31 14:42:20
【问题描述】:
用这个把我的手举到空中。我已经尝试过协议、前向声明的类、前向声明的协议,但我无法弄清楚有效的配置。我将列出有问题的头文件,以便您查看正在导入的内容,但我肯定问题是循环加载导入。
错误是:
Ld /Users/eamonwhite/Library/Developer/Xcode/DerivedData/maggie-govvbppylostlwaashtkbcuawqzc/Build/Products/Debug-iphoneos/maggie.app/maggie 正常 arm64(在项目“maggie”的目标“maggie”中) cd /用户/eamonwhite/maggie/maggie /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target arm64-apple-ios13.4 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.4.sdk -L/Users/eamonwhite/Library/Developer/Xcode/DerivedData/maggie-govvbppylostlwaashtkbcuawqzc/Build/Products/Debug-iphoneos -F/Users/eamonwhite/Library/Developer/Xcode/DerivedData/maggie-govvbppylostlwaashtkbcuawqzc/Build/Products/Debug-iphoneos -filelist /Users/eamonwhite/Library/Developer/Xcode/DerivedData/maggie-govvbppylostlwaashtkbcuawqzc/Build/Intermediates.noindex/maggie.build/Debug-iphoneos/maggie.build/Objects-normal/arm64/maggie.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/eamonwhite/Library/Developer/Xcode/DerivedData/maggie-govvbppylostlwaashtkbcuawqzc/Build/Intermediates.noindex/maggie.build/Debug-iphoneos/maggie .build/Objects-normal/arm64/maggie_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -fembed-bitcode-marker -fobjc-arc -fobjc-link-runtime -Xlinker -dependency_info -Xlinker /Users/eamonwhite/Library/Developer/Xcode/DerivedData/maggie-govvbppylostlwaashtkbcuawqzc/Build/Intermediates .noindex/maggie.build/Debug-iphoneos/maggie.build/Objects-normal/arm64/maggie_dependency_info.dat -o /Users/eamonwhite/Library/Developer/Xcode/DerivedData/maggie-govvbppylostlwaashtkbcuawqzc/Build/Products/Debug-iphoneos /maggie.app/maggie
重复符号“_OBJC_CLASS_$_PersistentContainer”在: /Users/eamonwhite/Library/Developer/Xcode/DerivedData/maggie-govvbppylostlwaashtkbcuawqzc/Build/Intermediates.noindex/maggie.build/Debug-iphoneos/maggie.build/Objects-normal/arm64/AppDelegate.o /Users/eamonwhite/Library/Developer/Xcode/DerivedData/maggie-govvbppylostlwaashtkbcuawqzc/Build/Intermediates.noindex/maggie.build/Debug-iphoneos/maggie.build/Objects-normal/arm64/ViewController.o 重复符号 '_OBJC_METACLASS_$_PersistentContainer' 在: /Users/eamonwhite/Library/Developer/Xcode/DerivedData/maggie-govvbppylostlwaashtkbcuawqzc/Build/Intermediates.noindex/maggie.build/Debug-iphoneos/maggie.build/Objects-normal/arm64/AppDelegate.o /Users/eamonwhite/Library/Developer/Xcode/DerivedData/maggie-govvbppylostlwaashtkbcuawqzc/Build/Intermediates.noindex/maggie.build/Debug-iphoneos/maggie.build/Objects-normal/arm64/ViewController.o ld:架构 arm64 的 2 个重复符号 clang:错误:链接器 命令失败,退出代码为 1(使用 -v 查看调用)
在错误的底部,它说明了哪些文件是重复的:
_OBJC_CLASS_$_PersistentContainer(又名PersistentContainer.h,或者它的前向声明,我不确定)
_OBJC_METACLASS_$_PersistentContainer(同样,我不知道METACLASS和CLASS有什么区别,我假设METACLASS是一个前向声明,就像@class一样)。
从错误中看来,该文件在AppDelegate.o(又名AppDelegate.h)和ViewController.o(ViewController.h 的编译版本)中都存在重复 - 以下是这些文件的相关部分:
AppDelegate.h:
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@end
AppDelegate.m:
#import "AppDelegate.h"
#import "PersistentContainer.h"
@interface AppDelegate ()
@property (strong, nonatomic) NSManagedObjectContext* managedObjectContext;
@property (strong, nonatomic) NSPersistentStoreCoordinator* persistentStoreCoordinator;
@property (strong, nonatomic) NSPersistentStoreAsynchronousFetchResultCompletionBlock callback;
@property (nonatomic, strong) PersistentContainer *persistentContainer;
- (PersistentContainer*)persistentContainer;
@end
@implementation AppDelegate
...
ViewController.h:
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@class PersistentContainer;
@protocol ViewControllerDelegate <NSObject>
- (PersistentContainer*)getPersistentContainer;
@end
@interface ViewController : UIViewController <CLLocationManagerDelegate, ViewControllerDelegate>
@property (weak, nonatomic) id<ViewControllerDelegate> delegate;
@end
ViewController.m:
#import "ViewController.h"
#import "HeaderCollection.h"
#import "PersistentContainer.h"
@interface ViewController ()
@property (nonatomic, strong) CLLocationManager* locationManager;
@property (nonatomic) UILabel* heading_label;
@property (nonatomic) UILabel* location_label;
@property (nonatomic) UILabel* loc_timestamp_label;
@property (nonatomic) UILabel* heading_accuracy_label;
@property (nonatomic) UILabel* mag_heading_label;
@property (nonatomic) UILabel* true_heading_label;
@property (nonatomic) UILabel* heading_timestamp_label;
@property (nonatomic) PersistentContainer* persistentContainer;
- (PersistentContainer*)getPersistentContainer;
@end
@implementation ViewController
...
HeaderCollection.h 不相关,它们只是 CoreData 模型的标头。
这里是PersistentContainer.h:
#import <CoreData/CoreData.h>
@interface PersistentContainerProtocol : NSPersistentContainer
- (void)saveContext;
@end
@interface PersistentContainer : NSPersistentContainer
- (void)saveContext;
@end
@implementation PersistentContainer
- (void)saveContext {
NSManagedObjectContext *context = [self viewContext];
NSError *error = nil;
if ([context hasChanges] && ![context save:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, error.userInfo);
abort();
}
}
@end
PersistentContainer 没有 .m 文件 - 一切都在头文件中。
我通常可以自己得到这种东西,但这个东西让我厌烦了一整天,是时候寻求一种新的眼光,或者一种新的策略......谢谢。如果您需要查看其他文件,请告诉我,我意识到这是一个循环导入问题,问题可能出在另一个文件中。谢谢。
【问题讨论】:
标签: ios objective-c xcode duplicates clang