开发者

Problem with duplicate classes in JSON frameworks ? [duplicate]

开发者 https://www.devze.com 2023-03-26 16:32 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: What is the best way to solve an Objective-C namespace collision?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

What is the best way to solve an Objective-C namespace collision?

In my app I used the SBJSON framework (Stig Brautaset's) to interact with my json api and everything worked very well.

But now I am in a situation to use the Facebook SSO using facebook SDK. So I included the facebook sdk into my project as instructed in Facebook developer site.

But the problem is, the facebook sdk开发者_运维百科 too used some SBJSON classes like SBJsonParser, SBJsonWriter, etc that are already present in SBJSON framework that I used. These classes are similar in name but different in methods and properties. So neither I can delete , nor edit any of them. (I am a beginner and i don't know how to edit them without losing anything).

So it shows many errors because of duplicate classes.

What I can do here? Please help me :)

header files (.h) of both JSonParser classes are given below. (.m files cannot be given here because they are too lengthy.)

JSonParser.h that is used in Facebook SDK given below

#import <Foundation/Foundation.h>
#import "SBJsonBase.h"

@protocol SBJsonParser
- (id)objectWithString:(NSString *)repr;

@end

@interface SBJsonParser : SBJsonBase <SBJsonParser> {

@private
const char *c;

}   
@end


@interface SBJsonParser (Private)

- (id)fragmentWithString:(id)repr;

@end

JSonParser.h that is used in SBJson Framework given below

#import <Foundation/Foundation.h>

@interface SBJsonParser : NSObject {


NSString *error;
NSUInteger depth, maxDepth;

}

@property NSUInteger maxDepth;

@property(copy) NSString *error;

- (id)objectWithData:(NSData*)data;

- (id)objectWithData:(NSData*)data;

- (id)objectWithString:(NSString*)jsonText error:(NSError**)error;


@end

Thank you :)


You need to decide which SBJson implementation to keep, and then manually deleting the other one from your project setup.

The main problem is that there is allot of good iOS open source available. But the methods for distribution of this open source is arcane at best. No more advanced or fool proof than copying code on USB-sticks.

I have written a longer blog post on the topic titled The state of iOD Open Source: and what to do about it: http://blog.jayway.com/2011/05/16/the-state-of-ios-open-source-and-what-to-do-about-it/

My suggestion is to use the ability to have Xcode projects as dependencies for other Xcode projects. It works well, and I have used this method for over 5 years with good results.


Try this:

  • Remove one of the frameworks by deleting the reference to the files.
  • Choose each of the duplicate classes, and select the word representing the name (like JSonParser.h).
  • In Xcode, use the "Refactor..." menu item to rename it.
  • Reimport the removed framework.

Make sure you make a snapshot before so you can revert if something goes wrong.

0

精彩评论

暂无评论...
验证码 换一张
取 消