isa is deprecated #79

Closed
trawor opened this Issue May 6, 2012 · 20 comments

Projects

None yet
@trawor
trawor commented May 6, 2012

I got lots of warning like this: /PATH/JSONKit.m:2602:11: Direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()

My Xcode is up to 4.4 DP4

@christo16

Same issue here, happened after upgrading.

@shannoga

Same issue on 4.4 DP5

@tknizam
tknizam commented Jun 13, 2012

This can be fixed by replacing

object->isa

with

object_getClass(object)

You will also need to replace

keyObject->isa

with

object_getClass(keyObject)

and

(id)keys[idx]->isa

with

object_getClass((id)keys[idx])
@shannoga

Thanks, When trying to replace I noticed this note on the file:

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.

Is it still O.K to change that ?
Thanks

@tknizam
tknizam commented Jun 14, 2012

You can still keep using object->isa, but eventually that will be dropped as it is deprecated, unless there's a faster way to do the same thing without using object_getClass(), it is the next best solution for now.

If you still wish to use object->isa, you can suppress the warnings.

@MSch
MSch commented Jun 14, 2012

Regarding the object->isa deprecation, once thing I'm not sure of:

Does isa return the NSNumber for the new NSNumbers that are implemented via tagged pointers? (AFAIK that's the reason isa is deprecated)

@johnezang johnezang closed this Jun 24, 2012
@johnezang johnezang was assigned Jun 24, 2012
@drekka
drekka commented Aug 7, 2012

I was researching this issue and found https://gist.github.com/2171491 which suggested to me that object_getClass() is no longer slower that isa.

@antonysastre

Still produces a deprecation warning:

array->isa      = _CDVJKArrayClass;

and

dictionary->isa      = _CDVJKDictionaryClass;

Any good solution to this?

@NielsKoole

Same here!

@SpacyRicochet

Those aren't solutions, they just hide away the warnings. Good enough for a quick fix (I'm using it, so thanks), but nothing near a real solution.

@marcdown
marcdown commented Apr 1, 2013

Since none of the Pull requests have been accepted I applied the fixes @tknizam suggested as well as used object_setClass(object, Class) to fix @antonysastre's warnings. I also explicitly cast the appropriate format arguments as unsigned long to remove those warnings as well.
Forked repo: https://github.com/creativemess/JSONKit
Podspec: https://gist.github.com/creativemess/5282955/raw/2a52cfd92f112f2a52669420c82c1bb1efd15d2a/JSONKit.podspec

@luketheobscure

@creativemess How do I reference your podspec?

@marcdown
marcdown commented Jun 6, 2013

@luketheobscure added the following to your Podfile:

pod 'JSONKit', :podspec => 'https://gist.github.com/creativemess/5282955/raw/2a52cfd92f112f2a52669420c82c1bb1efd15d2a/JSONKit.podspec'
@jhonyf
jhonyf commented Oct 16, 2013

Not sure what happened to @marcdown gist, but recreated it to point to his fork. Use this in your podfile and run pod install

pod 'JSONKit', :podspec => 'https://gist.github.com/jhonyf/7002734/raw/08fd7b28676b97af251b5dd5b375394eedc454f9/gistfile1.rb'
@marcdown

@jhonyf I updated my handle - here's the updated link:

pod 'JSONKit', :podspec => 'https://gist.github.com/marcdown/5282955/raw/2a52cfd92f112f2a52669420c82c1bb1efd15d2a/JSONKit.podspec'
@PhilTrailerPark

Thanks marcdown. Current JSONKit is still build failing with deprecations but your fork worked great for me. Thanks for saving me doing it by hand. Yeah cocoapods!

@xlarsx
xlarsx commented May 19, 2014

Thanks for the update!

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

CocoaPods #5

@cesarferreira

@marcdown thanks a lot for that line! :)

@zlc000190

i remove the jsonkit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment