Giter Site home page Giter Site logo

Comments (21)

alazier avatar alazier commented on September 28, 2024

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.

martintsch avatar martintsch commented on September 28, 2024

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.

alazier avatar alazier commented on September 28, 2024

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.

ajimix avatar ajimix commented on September 28, 2024

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.

alazier avatar alazier commented on September 28, 2024

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.

ajimix avatar ajimix commented on September 28, 2024

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.

jpsim avatar jpsim commented on September 28, 2024

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.

ajimix avatar ajimix commented on September 28, 2024

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.

tgoyne avatar tgoyne commented on September 28, 2024

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.

ajimix avatar ajimix commented on September 28, 2024

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.

tgoyne avatar tgoyne commented on September 28, 2024

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.

ajimix avatar ajimix commented on September 28, 2024

Thanks, it works but it's a bit ugly. We'll be waiting for #735 to be merged.

from realm-cocoa.

martintsch avatar martintsch commented on September 28, 2024

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.

tgoyne avatar tgoyne commented on September 28, 2024

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.

martintsch avatar martintsch commented on September 28, 2024

I forgot to update. That with the Headers everything started to work fine!

Thank you very much!

from realm-cocoa.

bofrese avatar bofrese commented on September 28, 2024

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.

ajimix avatar ajimix commented on September 28, 2024

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.

faken avatar faken commented on September 28, 2024

@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.

ajimix avatar ajimix commented on September 28, 2024

Then I'm sorry but I don't have any idea, perhaps @tgoyne can help here.

from realm-cocoa.

tgoyne avatar tgoyne commented on September 28, 2024

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.

rbaulin avatar rbaulin commented on September 28, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.