Skip to content

Direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass() #106

Open
Whirlwind opened this Issue Nov 15, 2012 · 11 comments

7 participants

@Whirlwind

JSONKit.m:680:12: Direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()
JSONKit.m:931:17: Direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()
XCODE 4.6DP2

@vchav73
vchav73 commented Nov 25, 2012

I researched this. Seems isa holds the class for the object. The warnings can be eliminated by replacing the offending lines with:

object_setClass(dictionary, _JKDictionaryClass); // Dictionary case
object_setClass(array, _JKArrayClass); // Array case

Haven't tested this yet, but I did verify that the changes eliminate the warnings in Xcode 4.6 DP2.

@Bo98
Bo98 commented Dec 5, 2012

A fix is to probably to use something like this:

5663f2d

@Daij-Djan

how is silencing warnings 'ever' a fix... that setClass call looks cool.

@Bo98
Bo98 commented Jan 11, 2013

It's how johnezang did it.

@Daij-Djan

where? its not in the trunk.

@vchav73
vchav73 commented Jan 11, 2013

I have the object_setClass fix in production. I haven't measured the performance impact, but saw the notes below in the comments of JSONKit.m, which makes me believe that the change will hurt performance. For my application it's good enough.

// Why not just use object_getClass()? Because object->isa reduces to (typically) a single instruction. Calling object_getClass() requires
// that the compiler potentially spill registers, establish a function call frame / environment, and finally execute a "jump subroutine" instruction.
// Then, the called subroutine must spend half a dozen instructions in its prolog, however many instructions doing whatever it does, then half a dozen
// instructions in its prolog. One instruction compared to dozens, maybe a hundred instructions.
//

// Yes, that's one to two orders of magnitude difference. Which is compelling in its own right. When going for performance, you're often happy with
// gains in the two to three percent range.

@davidsielert

+1 for the above pull ..

@grichards-trulia

+1 for pull req #121

@vakulenkom

Can please someone explain me if i could still use JSONKit after Xcode auto-fix?

dictionary->isa = _JKDictionaryClass -------> object_setClass(dictionary, _JKDictionaryClass);

@Bo98
Bo98 commented Jul 22, 2013

Should do. I've not seen any breakages after applying the fix.

@ArtSeo ArtSeo referenced this issue in ArtSeo/Multiples Jun 8, 2014
Open

CocoaPods #5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.