I'm trying to se Activity Tracing in an iOS app, things have been working nicely up until I needed to print an Objective-C pointer.
In the slides for WWDC 14 Session 714 Apple mention that you can use %p
to print pointers:
But I can't find a reliable way to do so without up setting ARC (or myself).
I want to print the NSManagedObjectContext
associated with a NSManagedObject
, because I use multiple context I want to be able to see if I'm passing NSManagedObject
to unexpected contexts.
1st try: ARC forbids Objective-C objects in structs
os_trace("doing something with object in moc %p", object.managedObjectContext);
2nd try: Compiles but don't print what I want
NSManagedObjectContext *moc = invite.managedObjectContext;
os_trace("doing something with object in moc %p", &moc);
The resulting trace prints 0x16fd0e6d0
while (lldb) po invite.managedObjectContext
says that the pointer is 0x1741fce00
.
3rd try: I can't believe this is the only way
CFTypeRef moc = CFBridgingRetain(object.managedObjectContext);
os_trace("doing something with object in moc %p", moc);
CFRelease(moc);
This prints the address I'm expecting. But OMG having to manually retain/release something just to print the memory address is horrible.
What am I missing? There has to be a better way to do this.