Comments (21)
Schema are created for any objects which derive from RLMObject in your binary. Are you compiling the 3 object classes you wish to test in your test binary? It's hard to tell from the callstack.
from realm-cocoa.
We have our application, which is a target dependency in our Tests.
The compile Sources in the Tests just contain the tests. When we debug and have a breakpoint on the defaultRealm, in the application code, we see that the schema contains all data.
The defaultRealm called in the tests has no schema. So I guess we have 2 different realms here. The question would be how we can access the application realm out of the tests?
Would we need some kind of bridging which would expose the data?
from realm-cocoa.
You need to compile your object classes into your tests as well. Once you do this your tests with have the same schema as your application.
from realm-cocoa.
Hello, when we add the object classes to be compiled we get this error:
Terminating app due to uncaught exception 'RLMException', reason: 'Property of type 'MPRCompany' must descend from RLMObject'
To clarify, MPRCompany is a property (relation) from another object.
The weird thing is that the problem only occurs in the tests. Everything is working fine in the app, objects, relations, reading, writing, etc.
from realm-cocoa.
I tried to reproduce the issue you are seeing but haven't been able to do
so - I created two model objects, one which has the other as a property and
as an array, and successfully compiled and used the objects both in an app
and in tests.
If you could share a full callstack I might be able to better narrow down
the issue. Sharing your data models might also be helpful.
On Wed, Jul 30, 2014 at 12:46 AM, Adria Jimenez [email protected]
wrote:
Hello, when we add the object classes to be compiled we get this error:
Terminating app due to uncaught exception 'RLMException', reason:
'Property of type 'MPRCompany' must descend from RLMObject'
To clarify, MPRCompany is a property (relation) from another object.The weird thing is that the problem only occurs in the tests. Everything
is working fine in the app, objects, relations, reading, writing, etc.—
Reply to this email directly or view it on GitHub
#690 (comment).
from realm-cocoa.
We created a simple test project where we can reproduce the issue. You can take a look here: https://github.com/ajimix/realm-test
Thanks
from realm-cocoa.
Hi @ajimix, there were a number of CocoaPods-related issues in your sample code project, which I've fixed in a PR: realm-test#1. Let me know if that works for you.
from realm-cocoa.
Hello @jpsim thank you for your time, we tried persisting and we have the initial issue that @martintsch described. I pushed an example again here: https://github.com/ajimix/realm-test
Thank you
from realm-cocoa.
Looks like the issue is that both the application and the tests are linking in Realm and ending up with separate copies that only see the models defined in their own target. For now you can work around this by removing -framework Realm from Pods.xcconfig and adding it to RealmTest's linker flags (and not RealmTestTests's), and I'll take a look at fixing the podspec.
from realm-cocoa.
Thank you it worked! But anytime we do pod install we have to manually remove again the line from Pods.xconfig
We will be waiting for a fix :)
Thanks!
from realm-cocoa.
An ugly but less annoying workaround is to add the following to the bottom of your Podfile:
post_install do |installer_representation|
# Replace -ObjC by -force_load
path = installer_representation.sandbox_root + 'Pods.xcconfig'
tmp = path.to_s + '.tmp'
File.open(path, "r") do |f|
File.open(tmp, "w") do |g|
f.each_line do |line|
line.sub! '-ObjC', '-force_load $(TARGET_BUILD_DIR)/libPods.a'
g.puts line
end
end
end
File.rename(tmp, path)
# Remove target dependency from Pods target
installer_representation.project.targets.each do |target|
target.dependencies.select! { |d| d.target.name != 'Pods-Realm' }
end
end
(Based on code from CocoaPods/CocoaPods#712)
from realm-cocoa.
Thanks, it works but it's a bit ugly. We'll be waiting for #735 to be merged.
from realm-cocoa.
Hi all,
with the 0.84.0 release we thought that this issue is gone but unfortunately it is not.
😿
The example here with the update: https://github.com/ajimix/realm-test is still valid.
Maybe we keep doing stuff wrong?
from realm-cocoa.
Ah, I forgot to actually document what #761 did. There's now a Realm.Headers subspec which includes only the public headers for Realm so that you can use Realm in your test targets without linking in a second copy of Realm, which you can use as follows:
target :MyApp do
pod 'Realm'
end
target :MyAppTests do
pod 'Realm.Headers'
end
CocoaPods's switch to dynamic libraries (to support Swift) should fix the issue entirely, but for now I think this is the best we can do.
from realm-cocoa.
I forgot to update. That with the Headers everything started to work fine!
Thank you very much!
from realm-cocoa.
I get
[!] Unable to find a specification for Realm.Headers
.
I have tried to replace with 'Realm/Headers'. Then pod install no longer complains, but now I get lots of duplicate symbol errors during linking....
I'm back with the 'ugly workaround' suggested by tgoyne earlier. After some struggle I managed to get that working again....
from realm-cocoa.
Hello @bofrese I work with @martintsch and what we did was to use Realm in the app target and Realm/Headers (not Realm.Headers) in the test target.
What we also did was to set both targets as exclusive so each pod is linked exclusively with each target.
So we ended up with something like...
target 'MyApp', exclusive: true do
pod 'Realm', '~> 0.84.0'
end
target 'MyAppTests', exclusive: true do
pod 'Realm/Headers', '~> 0.84.0'
end
I hope this helps.
from realm-cocoa.
@ajimix i have tried to setup my Podfile as descriped but the compilation of the test projected failed with the error: ld library not found for -ltightdb-ios
any suggestion would could be wrong with my setup?
from realm-cocoa.
Then I'm sorry but I don't have any idea, perhaps @tgoyne can help here.
from realm-cocoa.
Make sure that Other Linker Flags contains $(inherited)
. Xcode helpfully doesn't add it by default, which results in the linker flags set in the podspec not having any effect if you've ever touched it.
from realm-cocoa.
@tgoyne I've also spent a good few hours in debugging and building a sample until I found this issue. Solution provided by @ajimix works perfectly. Probably should highlight the cocoapods testing recipe in README or realm docs?
Tip. Since CocoaPods uses Xcodeproj, this small script might be useful to separate test targets from app targets:
proj = Xcodeproj::Project.open('YouProj.xcodeproj')
all_targets = proj.targets.map {|t| t.name}
test_targets = all_targets.select {|name| name.downcase.include? "test"}
app_targets = all_targets - test_targets
from realm-cocoa.
Related Issues (20)
- Automatic logout due to an expired refresh token does not trigger UI observers
- Exception realm::sync::network::ssl::ProtocolNotSupported: SSL/TLS protocol not supported on visionOS HOT 1
- AsyncOpen() with Flexible Sync: Progress Indication HOT 11
- @AutoOpen offline doesn't work when upgrading to latest version. HOT 4
- Firebase Crashlytics collectioned massive crashes HOT 1
- Memory overflow in Swift, exceeding the size limit of 12MB. HOT 2
- Object Change Observers: Partial-KeyPaths Broken for Multi-Level Properties HOT 4
- Incorrect mime type for .css files after uploading docs to S3
- Add support for progress notifications during bootstrap
- Need realm-swift-10.46.0/15.0 (xcode 15.0) HOT 4
- Add sync tests for geo queries
- Add withoutNotifying support for asyncWrite / writeAsync HOT 1
- Devise public API to trigger client reset for a Realm file
- baseUrl Change
- Crash in app launch ios 14 and earlier HOT 4
- @AutoOpen doesn't work HOT 1
- Repeative Crash HOT 9
- Crash when launch HOT 9
- Crash with in query when comparing with empty collection
- Sectioned Results with Empty Sections HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from realm-cocoa.