具有相同名称的 RLMObject 子类不能在同一目标中包含两次
RLMObject subclasses with the same name cannot be included twice in the same target
我在测试 Realm 时遇到问题。如果我将我的目标文件包含到测试目标中,我在执行测试时会收到此错误:
file:///path/project-iOS/project-iOS/DataManager.m: test failure: -
[SingleHouseDb_Test testPerformanceExample] failed: failed: caught
"RLMException", "RLMObject subclasses with the same name cannot be
included twice in the same target. Please make sure 'StringObject' is only linked
once to your current target."
但是如果我从目标中删除文件,它根本无法构建!
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_DVMap", referenced from:
objc-class-ref in DataManager.o
"_OBJC_CLASS_$_DVHouse", referenced from:
objc-class-ref in DataManager.o
"_OBJC_CLASS_$_DVReport", referenced from:
objc-class-ref in DataManager.o
objc-class-ref in ReportsViewController.o
"_OBJC_CLASS_$_DVReportPhoto", referenced from:
objc-class-ref in DataManager.o
"_OBJC_CLASS_$_DVUserProfile", referenced from:
objc-class-ref in DataManager.o
objc-class-ref in ReportsViewController.o
"_OBJC_CLASS_$_StringObject", referenced from:
objc-class-ref in DataManager.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是我的 Podfile:
platform :ios, '8.0'
use_frameworks!
target 'my-iOS' do
pod 'AFNetworking'
pod 'Realm'
pod 'SDWebImage'
end
target 'my-iOSTests', exclusive: true do
pod 'Realm/Headers'
end
target 'my-iOSUITests', exclusive: true do
pod 'Realm/Headers'
end
iOS 有两种不同的测试方法。
应用程序测试和逻辑测试。两者对您设置目标的方式都有不同的影响。你不能混合它们,你必须决定两者的一种范式。当你使用框架和领域时,你必须使用前者。
应用程序测试
它们通常链接到您的应用程序(由构建设置 BUNDLE_LOADER
识别)如果它是一个动态库,它将被链接到。在运行时,它们会加载测试主机 (TEST_HOST
),这通常是首先在模拟器中启动的应用程序可执行文件。他们通过 dyld
注入构建的测试包,以便您可以有效地使用每个符号,这些符号在您的应用程序中可传递地使用。如果您在 Xcode.
中设置新的测试目标,那么这是现在的默认设置
目标会员
要遵循此方法,您不得与测试目标共享应用目标代码的目标成员资格。但是你需要确保你所有的模型文件仍然是你的应用程序目标的成员。
因此文件 Object.swift
的目标成员可能如下所示:
或者这样:
CocoaPods
使用 CocoaPods,您的 Podfile 应该如下所示:
platform :ios, '8.0'
use_frameworks!
target 'my-iOS' do
link_to 'my-iOS', 'my-iOSTests', 'my-iOSUITests'
pod 'AFNetworking'
pod 'Realm'
pod 'SDWebImage'
end
header 子规范适用于使用静态链接时的 逻辑测试 方法。
另请查看 Realm 文档中关于 Avoid Linking Realm and Tested Code in Test Targets 的章节。
好的,@marius 回答有帮助,但我设法自己解决了。我搞混了,也许这会对其他人有所帮助。
你所有的 .m
文件应该只在你的主应用程序目标中,而不是在测试目标中
使用以下 podfile
结构:
platform :ios, '8.0'
use_frameworks!
target 'myPoject-iOS' do
pod 'AFNetworking'
pod 'Realm'
pod 'SDWebImage'
end
target 'myPoject-iOSTests', exclusive: true do
pod 'Realm/Headers'
end
target 'myPoject-iOSUITests', exclusive: true do
pod 'Realm/Headers'
end
在此之后一切都应该正常。
如果你有任何 Swift 文件,就像我一样,它会变得更狡猾。它告诉 someheader-Swift.h
未找到。它是自动生成的文件,每个目标都有自己的名称。所以你需要删除对它的所有引用,而是在预编译的 header 中使用 header,像这样:
- 从上面做所有事情
- 对于您的 swift 个文件,将文件添加到所有目标
- 如果您有预编译的 header,请使用它,或创建一个新的。使用这样的东西:
#if MAIN_TARGET==1
#import "myProject-Swift.h"
#elif TESTS_TARGET==1
#import "myProject_iOSTests-Swift.h"
#elif UI_TESTS_TARGET==1
#import "myProject_iOSUITests-Swift.h"
#endif
您需要 linker/compiler 才能在每个目标上使用正确的文件。为此,您需要向每个目标添加一些 defines/macros 到 Build Settings - Preprocessor Macros
。例如,将 MAIN_TARGET=1
添加到您的主要目标。
这对我有帮助。
我在测试 Realm 时遇到问题。如果我将我的目标文件包含到测试目标中,我在执行测试时会收到此错误:
file:///path/project-iOS/project-iOS/DataManager.m: test failure: -
[SingleHouseDb_Test testPerformanceExample] failed: failed: caught
"RLMException", "RLMObject subclasses with the same name cannot be
included twice in the same target. Please make sure 'StringObject' is only linked
once to your current target."
但是如果我从目标中删除文件,它根本无法构建!
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_DVMap", referenced from:
objc-class-ref in DataManager.o
"_OBJC_CLASS_$_DVHouse", referenced from:
objc-class-ref in DataManager.o
"_OBJC_CLASS_$_DVReport", referenced from:
objc-class-ref in DataManager.o
objc-class-ref in ReportsViewController.o
"_OBJC_CLASS_$_DVReportPhoto", referenced from:
objc-class-ref in DataManager.o
"_OBJC_CLASS_$_DVUserProfile", referenced from:
objc-class-ref in DataManager.o
objc-class-ref in ReportsViewController.o
"_OBJC_CLASS_$_StringObject", referenced from:
objc-class-ref in DataManager.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是我的 Podfile:
platform :ios, '8.0'
use_frameworks!
target 'my-iOS' do
pod 'AFNetworking'
pod 'Realm'
pod 'SDWebImage'
end
target 'my-iOSTests', exclusive: true do
pod 'Realm/Headers'
end
target 'my-iOSUITests', exclusive: true do
pod 'Realm/Headers'
end
iOS 有两种不同的测试方法。 应用程序测试和逻辑测试。两者对您设置目标的方式都有不同的影响。你不能混合它们,你必须决定两者的一种范式。当你使用框架和领域时,你必须使用前者。
应用程序测试
它们通常链接到您的应用程序(由构建设置 BUNDLE_LOADER
识别)如果它是一个动态库,它将被链接到。在运行时,它们会加载测试主机 (TEST_HOST
),这通常是首先在模拟器中启动的应用程序可执行文件。他们通过 dyld
注入构建的测试包,以便您可以有效地使用每个符号,这些符号在您的应用程序中可传递地使用。如果您在 Xcode.
目标会员
要遵循此方法,您不得与测试目标共享应用目标代码的目标成员资格。但是你需要确保你所有的模型文件仍然是你的应用程序目标的成员。
因此文件 Object.swift
的目标成员可能如下所示:
或者这样:
CocoaPods
使用 CocoaPods,您的 Podfile 应该如下所示:
platform :ios, '8.0'
use_frameworks!
target 'my-iOS' do
link_to 'my-iOS', 'my-iOSTests', 'my-iOSUITests'
pod 'AFNetworking'
pod 'Realm'
pod 'SDWebImage'
end
header 子规范适用于使用静态链接时的 逻辑测试 方法。
另请查看 Realm 文档中关于 Avoid Linking Realm and Tested Code in Test Targets 的章节。
好的,@marius 回答有帮助,但我设法自己解决了。我搞混了,也许这会对其他人有所帮助。
你所有的
.m
文件应该只在你的主应用程序目标中,而不是在测试目标中使用以下
podfile
结构:
platform :ios, '8.0'
use_frameworks!
target 'myPoject-iOS' do
pod 'AFNetworking'
pod 'Realm'
pod 'SDWebImage'
end
target 'myPoject-iOSTests', exclusive: true do
pod 'Realm/Headers'
end
target 'myPoject-iOSUITests', exclusive: true do
pod 'Realm/Headers'
end
在此之后一切都应该正常。
如果你有任何 Swift 文件,就像我一样,它会变得更狡猾。它告诉 someheader-Swift.h
未找到。它是自动生成的文件,每个目标都有自己的名称。所以你需要删除对它的所有引用,而是在预编译的 header 中使用 header,像这样:
- 从上面做所有事情
- 对于您的 swift 个文件,将文件添加到所有目标
- 如果您有预编译的 header,请使用它,或创建一个新的。使用这样的东西:
#if MAIN_TARGET==1
#import "myProject-Swift.h"
#elif TESTS_TARGET==1
#import "myProject_iOSTests-Swift.h"
#elif UI_TESTS_TARGET==1
#import "myProject_iOSUITests-Swift.h"
#endif
您需要 linker/compiler 才能在每个目标上使用正确的文件。为此,您需要向每个目标添加一些 defines/macros 到 Build Settings - Preprocessor Macros
。例如,将 MAIN_TARGET=1
添加到您的主要目标。
这对我有帮助。