Errors on JSONKit implement
Asked Answered
S

3

7

The Errors

Upon importing the JSONKit.h and JSONKit.m files into my project , i get the following errors. I have browsed and browsed but none seems to have encountered these problems ?

All i did was import the files and build and then i get this

Is it something i forgot to import or ...??????

Sporocyte answered 4/4, 2012 at 12:0 Comment(0)
F
15

You can disable ARC(automatic reference count) in JSONKit files.

Generally step is :

  1. Go to your project settings, under Build Phases > Compile Sources
  2. Select the files you want ARC disabled and add -fno-objc-arc compiler flags. You can set flags for multiple files in one shot by selecting the files then hitting "Enter" key.

Please refer to this post: iOS 5 Best Practice (Release/retain?) for more details.

Hope it helps.

Edit

After discussion, we also have some other options to solve the problem. For example, you can convert JSONKit to ARC compatible. But according to Mike Weller's statement, it will be very hard to convert because JSONKit uses malloc to manage memory.

I think use -fno-objc-arc compiler flag is a low-risk and convenient way to solve the problem.

Ferrigno answered 4/4, 2012 at 12:7 Comment(1)
@ParthBhatt Yes, I agree. There must be some other methods can solve this problem. For example, we can change the JSONKit to some other json lib which supports GCD. Using -fno-objc-arc compiler flags is a low-risk way to solve this problem in my opinion.Ferrigno
G
1

tangqiaoboy's answer will resolve those errors but you can also consider using the class NSJSONSerialization. It makes it really easy do convert NSDictionarys and NSArrays to JSON and vice-versa.

Good luck!

Gilbertina answered 4/4, 2012 at 12:17 Comment(1)
As far as I know, NSJSONSerialization only exist in ios5. If we want to support ios4, we have to use 3rd part lib.Ferrigno
R
-2

You can convert your project into ARC compatible, by following steps

Go to Edit menu -> Refactor -> Convert to Objective-C ARC...

Or If you do not want to use ARC in your current project then follow tangqiaoboy 's steps.

Radiometeorograph answered 4/4, 2012 at 12:18 Comment(7)
JSONKit does not work with ARC because of it's custom memory management.Listed
@MikeWeller : I am currently using JSONKit with ARC without any problem ?? I dont think you have ever tried JSONKit with ARC !!Radiometeorograph
Because JSONKit explicitly does not support it. It uses malloc and free internally to allocate object memory. ARC does not work with custom object allocation.Listed
@Radiometeorograph You can use JSONKit in an ARC project. You cannot compile or convert JSONKit as ARC-enabled code, as this answer was suggesting. You need to change the compiler settings for the JSONKit files.Listed
@MikeWeller You can replace those with _bridged and strong keywords to work on custom allocations. Correct me if I am wrong.Radiometeorograph
JSONKit allocates the memory for objective-c objects using malloc. Under ARC, you must allocate objects using alloc. Otherwise ARC will attempt to deallocate JSONKit objects assuming they have been allocated by the system. This will not work.Listed
I think after effort, JSONKit can be converted to ARC compatible.But It will have update problem when JSONKit has new patch. Using -fno-objc-arc compiler flags is a low-risk way to solve this problem.Ferrigno

© 2022 - 2024 — McMap. All rights reserved.