RLMObject.allObjects() CRASH

93 views
Skip to first unread message

Pavel Serbajlo

unread,
Feb 16, 2015, 1:30:26 PM2/16/15
to realm...@googlegroups.com
Hi guys,

I'm experiencing weird crash with my first ever Realm experiment.

here's the code:

import Realm


class LogEntryType : RLMObject {

   dynamic var id = 0//DefaultLogEntryType.Unknown.rawValue

   dynamic var name: String! = ""

   override class func primaryKey() -> String {

       return "id"

   }


    class func getDefaultTypes() {

        let types = LogEntryType.allObject()


        if types.count == 0 {

         ...

        }

   }

}



whenever I call the class func getDefaultTypes, it crashes on the first line:









2015-02-16 10:22:52.694 Daily[432:115819] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'


*** First throw call stack:


(0x181d71e48 0x1924b00e4 0x181c5b3e0 0x1000e0e2c 0x100103ff8 0x1001038fc 0x10010385c 0x1000dc6f8 0x1000cb0ac 0x1000c4290 0x1000ca100 0x1000ca2c4 0x1000df338 0x1000ded44 0x10010dfb0 0x1924b0bd0 0x1924b89ac 0x1924c3db8 0x100103ef8 0x1001038fc 0x10010385c 0x1000c7ae0 0x1000c48cc 0x1000c28a8 0x1000c2904 0x1865550f8 0x18653e22c 0x186554a94 0x186554720 0x18654dc74 0x18652138c 0x1867c01b4 0x18651f8f4 0x181d2a0e8 0x181d2938c 0x181d2743c 0x181c551f4 0x18ade35a4 0x186586784 0x1000ce4b0 0x1000ce4f0 0x192b1ea08)


libc++abi.dylib: terminating with uncaught exception of type NSException


Also, the execution breaks on the AppDelegate class definition (the first line of code of that swift unit) in top_level_code. Any idea what's wrong? Removing the app and starting fresh is not helping.

Thanks for any pointers.


Samuel Giddins

unread,
Feb 16, 2015, 1:41:26 PM2/16/15
to Pavel Serbajlo, realm...@googlegroups.com
Hi Pavel,

Have you tried making the `name` property non-optional, that is, declaring it as `dynamic var name: String =""`? Realm does not currently support optional primitives (String, Bool, Int, Double, Float).

I hope that helps!

--
Samuel Giddins



--
You received this message because you are subscribed to the Google Groups "Realm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-cocoa...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-cocoa/c985947a-e041-4d21-9053-8aa6a5b1af9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



{#HS:72076516-518#}

Pavel Serbajlo

unread,
Feb 16, 2015, 1:53:25 PM2/16/15
to realm...@googlegroups.com, serb...@me.com, he...@realm.io
Good to know that. I tried it, but still experiencing the same crashes.

Samuel Giddins

unread,
Feb 16, 2015, 1:56:33 PM2/16/15
to Pavel Serbajlo, realm...@googlegroups.com
Hm. In that case, could you share the symbolicated exception backtrace so we can help you figure out what's going on?

--
Samuel Giddins
{#HS:72076516-518#}

Pavel Serbajlo

unread,
Feb 16, 2015, 2:18:46 PM2/16/15
to realm...@googlegroups.com, serb...@me.com, he...@realm.io
This particular exception wouldn't symbolicate for me. All I can see is above. Also Swift doesn't support catching exceptions directly, any advice?

Samuel Giddins

unread,
Feb 16, 2015, 2:29:18 PM2/16/15
to Pavel Serbajlo, realm...@googlegroups.com
Unfortunately, to be able to figure out where the exception is coming from, we'll need to be able to see the backtrace. Probably the easiest option (if the exception is being thrown while in development) would be to set an Exception Breakpoint in Xcode and then share the stack trace when that breakpoint gets hit. No need to catch the exception at all!

--
Samuel Giddins
{#HS:72076516-518#}

Pavel Serbajlo

unread,
Feb 16, 2015, 3:06:56 PM2/16/15
to realm...@googlegroups.com, serb...@me.com, he...@realm.io
I found the problem. Apparently, it's not a good idea to initialize RLMObject inside another RLMObject initialization when you have one-to-one relation between them (basically assigning a default RLMObject in init() of the parent one). When I got rid of this unrelated code, all was good. It looks like Realm is trying to init all the RLMObjects in the project first (probably to gather all the properties and init) so it collided hard.

Samuel Giddins

unread,
Feb 16, 2015, 3:59:24 PM2/16/15
to Pavel Serbajlo, realm...@googlegroups.com
Pavel,
I'm so happy to hear you were able to figure things out!
I'd be really interested to see the relevant code that caused the issue, as what you're trying to do might be something we should support.

Thanks!

--
Samuel Giddins




On Mon, Feb 16, 2015 at 8:07 PM UTC, Pavel Serbajlo <serb...@me.com> wrote:
I found the problem. Apparently, it's not a good idea to initialize
RLMObject inside another RLMObject initialization when you have one-to-one
relation between them (basically assigning a default RLMObject in init() of
the parent one). When I got rid of this unrelated code, all was good. It
looks like Realm is trying to init all the RLMObjects in the project first
(probably to gather all the properties and init) so it collided hard.



On Mon, Feb 16, 2015 at 7:29 PM UTC, Help <he...@realm.io> wrote:
Unfortunately, to be able to figure out where the exception is coming from, we'll need to be able to see the backtrace. Probably the easiest option (if the exception is being thrown while in development) would be to set an Exception Breakpoint in Xcode and then share the stack trace when that breakpoint gets hit. No need to catch the exception at all!

--
Samuel Giddins



On Mon, Feb 16, 2015 at 7:19 PM UTC, Pavel Serbajlo <serb...@me.com> wrote:
This particular exception wouldn't symbolicate for me. All I can see is
above. Also Swift doesn't support catching exceptions directly, any advice?



On Mon, Feb 16, 2015 at 6:56 PM UTC, Help <he...@realm.io> wrote:
Hm. In that case, could you share the symbolicated exception backtrace so we can help you figure out what's going on?

--
Samuel Giddins



On Mon, Feb 16, 2015 at 6:53 PM UTC, Pavel Serbajlo <serb...@me.com> wrote:
Good to know that. I tried it, but still experiencing the same crashes.



{#HS:72076516-518#}
Reply all
Reply to author
Forward
0 new messages