3

I am trying to include SBJsonlibrary in my project that does not use ARC. Since I cannot include source files, I've followed the steps described: here. However I end up with the same problems described in this SO question.

When I add libsbjson-ios.a to my project, it is shown in red, which I assume means the library is missing. enter image description here

Although the compiling of the project goes fine, when I try to add #import "SBJson.h" I get "SBJson.h: no such file or directory" error.

How do I solve this? My project is too large and I cannot change everyting to use ARC.

Community
  • 1
  • 1
Maggie
  • 7,823
  • 7
  • 45
  • 66
  • Try that library as **optional** instead of **Required**. – Kumar KL Dec 31 '13 at 09:41
  • Nope, still the same. The problem is not compiling itself, project compiles fines as long as I don't make any attempt to use the actual files. – Maggie Dec 31 '13 at 09:46
  • have u worked before with ASIHTTP ? – Aklesh Rathaur Dec 31 '13 at 10:02
  • The red line may also mean the simulator architecture is missing. Does your project build and link correctly if you build for the *device*? – Michael Dautermann Dec 31 '13 at 10:06
  • @MichaelDautermann yes, it builds fine. I can see the lib in /Library/Developer/Xcode/DerivedData product folder of my app's folder. – Maggie Dec 31 '13 at 10:11
  • so this just doesn't work when you build for simulator? – Michael Dautermann Dec 31 '13 at 10:15
  • try [this answer](http://stackoverflow.com/questions/5439845/how-to-add-json-module-in-three20?answertab=votes#tab-top). – johnMa Dec 31 '13 at 10:20
  • Please read my question again. Build goes fine, I don't get any errors, library appears in Products folder, but is shown in red in XCode. When I try to actually USE it, by adding #import statement to my controller, I get an error that no such file exists. – Maggie Dec 31 '13 at 10:21
  • Why not just use NSJSONSerialization? It's built into the system. – Abizern Dec 31 '13 at 12:56
  • @Abizern because it is supported from iOS5 onwards, and I have to support 4.3 as well. – Maggie Dec 31 '13 at 13:10
  • You can older non ARC version of SBJSON https://github.com/stig/json-framework/tree/v2.3 – Abhishek Dec 31 '13 at 10:50

2 Answers2

1

you simply need to drag all the files into your project rather than importing the library. i suggest to see https://github.com/stig/json-framework/ and follow the read me file to install in your project.

to use this in your projects

  1. download the zip file from above link.
  2. In the Finder, navigate into the src/main/objc folder.
  3. Select all the files and drag-and-drop them into your Xcode project.
  4. Tick the Copy items into destination group's folder option.
  5. Use #import "SBJson.h" in your source files.
  • Source files need to be compiled with ARC – Maggie Dec 31 '13 at 11:14
  • you can use fobjc-arc to enable ARC -fno-fobjc-arc to disable ARC for a perticular class in your project. refer http://stackoverflow.com/questions/6448874/disable-automatic-reference-counting-for-some-files –  Dec 31 '13 at 11:23
  • or you can use the older non ARC version as suggested by @Undercover developer –  Dec 31 '13 at 11:26
0

As an aside, a project can use ARC for just some files, so you could have compiled SBJson's classes with ARC and the rest of the project without.

A better way would be to just use SBJson from CocoaPods if you need to support iOS4. Or just switch to NSJSONSerialisation if you don't.

Stig Brautaset
  • 2,602
  • 1
  • 22
  • 39