3

The following code indicates the warning as

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

Code

  if(object->isa == encodeState->fastClassLookup.stringClass)     
  { isClass = JKClassString;     }
  else if(object->isa == encodeState->fastClassLookup.numberClass)     
  { isClass = JKClassNumber;     }
  else if(object->isa == encodeState->fastClassLookup.dictionaryClass) 
  { isClass = JKClassDictionary; }
  else if(object->isa == encodeState->fastClassLookup.arrayClass)      
  { isClass = JKClassArray;      }
  else if(object->isa == encodeState->fastClassLookup.nullClass)       
  { isClass = JKClassNull;       }
  else 
  {
     if([object isKindOfClass:[NSString     class]]) 
  { encodeState->fastClassLookup.stringClass     = object->isa; isClass = JKClassString;                    }
  else if([object isKindOfClass:[NSNumber     class]]) { encodeState->fastClassLookup.numberClass     = object->isa; isClass = JKClassNumber;     }
  else if([object isKindOfClass:[NSDictionary class]]) { encodeState->fastClassLookup.dictionaryClass = object->isa; isClass = JKClassDictionary; }
  else if([object isKindOfClass:[NSArray      class]]) { encodeState->fastClassLookup.arrayClass      = object->isa; isClass = JKClassArray;      }
  else if([object isKindOfClass:[NSNull       class]]) { encodeState->fastClassLookup.nullClass       = object->isa; isClass = JKClassNull;       }

What change should i want to clear that warning?please help me out.

Globas techn
  • 95
  • 1
  • 6

2 Answers2

9

The isa field on any object is a reference to the class of that object; it's part of the ObjC runtime's internal mechanisms, and dereferencing the object pointer to grab that field is functional but fragile and breaks encapsulation.

The compiler is telling you right there in the warning that you can use object_getClass, which is a function in the ObjC runtime to retrieve the same thing.

The code snippet you show is avoiding the standard -class method on every NSObject and instead appears to be grabbing the isa with the intention of getting a performance benefit from doing so. This would have to be some incredibly performance sensitive code to warrant that, but if it is, then object_getClass looks to be not much slower.

Ben Zotto
  • 70,108
  • 23
  • 141
  • 204
9

Include <objc/runtime.h>.

Replace everything like array->isa = _JKArrayClass; with object_setClass(array, _JKArrayClass)

And everything like class = array.isa with class = object_getClass(array)

See : iOS 7 : 'isa' is deprecated

Community
  • 1
  • 1
Divya Bhaloidiya
  • 5,018
  • 2
  • 25
  • 45