editfmah / sharkorm

Shark ORM for iOS/macOS/tvOS/watchOS
http://sharkorm.com
Other
247 stars 39 forks source link

SRKObjects not viewable / hackable in lldb debugger #111

Open MeteC opened 6 years ago

MeteC commented 6 years ago

Pausing on breakpoints in Xcode, I can't do anything useful with any SRKObject subclasses any longer.

e.g. using p mPerson, po mPerson, or anything like p mPerson.name (where mPerson is a Person SRKObject data class) gives:

error: instance method 'Id' has incompatible result types in different translation units ('id' vs. 'NSNumber *')
instance method 'Id' also declared here
declared here with type 'NSNumber *'

No lldb expressions work at all on any part of the SRKObject objects, they seem to get immediately hung up on this issue. And I've no idea where the "here" is that the second line refers to...

editfmah commented 6 years ago

Is this an XCode 10 thing? * just need to know where to focus energy.

MeteC commented 6 years ago

No I've had this in XCode 9 too.

I remember not having this problem with the first cut of SharkORM I used a couple of years ago..

editfmah commented 6 years ago

Okay, so here is a pure swift implementation and I can po the objects. Can you take a look at it and see if there is anything/ obviously different? or indeed if you yourself still cannot see the detail.

srktest.zip

editfmah commented 6 years ago

Also, this is what I see.

screenshot 2018-09-18 at 15 02 00
MeteC commented 6 years ago

Right, that is working as expected on my setup too.

In my project all Shark objects are Obj-C implemented, although the project is mixed Swift / Obj-C.. I'll try to investigate this some more creating new projects.

MeteC commented 6 years ago

Ok so I played with a couple of different new projects, and in the end I can reproduce this error doing the following:

  1. Create new iOS project (Objective-C based)
  2. Introduce SharkORM using CocoaPods
  3. Create a simple Obj-C implementation of an SRKObject data class
  4. Instantiate one of those objects, check it in LLDB - po etc fail

It wasn't necessary to create a mixed Swift / ObjC project in the end (although those also fail on me in the same way.)

MeteC commented 6 years ago

More investigation:

I found out that actually, in those new projects I mentioned, I was getting this error because I'd neglected to open the database in AppDelegate. Opening the database cleared out the problems there.

But that's odd, because I'm certainly opening the database in my original project.

I went back to my original project, created an empty Swift Shark object for the heck of it, and found out that I could debug that object. I can also now debug those original Obj-C Shark objects, just by having a Swift Shark object in my project!

Kind of weird.. It's not quite completely fixed my problem, i.e.:

po myObject

returns

<object returned empty description>

While

po myObject.fileName

returns the correct value. And now I'm not sure how to reproduce this...

editfmah commented 6 years ago

That is so odd. I don't think Swift should have anything to do with it. But it could be a lifecycle thing. Swift objects potentially get initialised earlier than obj-c if they are defined and used prior to starting the ORM. When used as an var property on the initial view controller, this is referenced before any app delegate call. Obj-c behaves itself a little bit more, as it's just a pointer with no type, so doesn't +init the object until it's actually used.

MeteC commented 6 years ago

Really odd, no? Quick question - are all the old swift issues ironed out these days? In other words, would you recommend I port across my Obj-C implementations to Swift ones and be done with it?

editfmah commented 6 years ago

Humm, it's not exactly perfect because you need to still use obj-c compatible properties, but we use it in all our apps and it works fine. The only bug which still exists is the setting of property values in the init() func, which then gets unset afterwards. It's still present in Swift 4.x, and the radar has just been marked as really complicated to fix!

editfmah commented 6 years ago

But we catered for that with the initWithProperties method instead.

MeteC commented 6 years ago

Small update, just an FYI really, I recoded one of my shark subclasses into swift to see what would happen, and it didn't change the behaviour - the debugger output is still not quite right. And in certain places, despite that weird hack I mentioned above, I've found I am still getting the error: instance method 'Id' has incompatible result types... error when calling po myObject. But it's only some of my shark classes, and only in some sections of code. I'll update here if I find anything more useful at any stage...