JSONKit icon indicating copy to clipboard operation
JSONKit copied to clipboard

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

Open Whirlwind opened this issue 13 years ago • 11 comments

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

Whirlwind avatar Nov 15 '12 01:11 Whirlwind

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.

vchav73 avatar Nov 25 '12 19:11 vchav73

A fix is to probably to use something like this:

https://github.com/johnezang/JSONKit/commit/5663f2db4664998c5235e1b5a02c70f745177ad3

Bo98 avatar Dec 05 '12 08:12 Bo98

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

Daij-Djan avatar Jan 11 '13 13:01 Daij-Djan

It's how johnezang did it.

Bo98 avatar Jan 11 '13 13:01 Bo98

where? its not in the trunk.

Daij-Djan avatar Jan 11 '13 13:01 Daij-Djan

5663f2d

Bo98 avatar Jan 11 '13 15:01 Bo98

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.

vchav73 avatar Jan 11 '13 16:01 vchav73

+1 for the above pull ..

davidsielert avatar Apr 13 '13 17:04 davidsielert

+1 for pull req #121

grichards-trulia avatar Apr 15 '13 22:04 grichards-trulia

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

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

vakulenkom avatar Jul 22 '13 13:07 vakulenkom

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

Bo98 avatar Jul 22 '13 13:07 Bo98