user92301
user92301

Reputation: 531

XCode 4 Framework - Private objects

Is there any way to create "private objects" when creating a framework? (meaning, classes that won't be exported outside)

I have a problem that my frameworks uses the JSON library and when projects using my framework try to also include the JSON library they get a "symbol already defined" error.

Thanks!

Upvotes: 1

Views: 302

Answers (1)

Wolfgang Schreurs
Wolfgang Schreurs

Reputation: 11834

With Objective-C that's not really possible. There are some guidelines to prevent collision though, for example one should use prefixes for members that are to be 'hidden' for other people and member variables are often prefixed with a underscore as well (Apple reserves the right to use 2 underscores). Which JSON framework are you using? Perhaps consider SBJSON if you aren't using it already, it uses the prefix (SB) to prevent collision.

From Apple's documentation:

Prefixes are an important part of names in programmatic interfaces. They differentiate functional areas of software. Usually this software comes packaged in a framework or (as is the case of Foundation and Application Kit) in closely related frameworks. Prefixes protect against collisions between symbols defined by third-party developers and those defined by Apple (as well as between symbols in Apple’s own frameworks).

A prefix has a prescribed format. It consists of two or three uppercase letters and does not use underscores or “sub prefixes.” Here are some examples NS: Foundation NS: Application Kit AB: Address Book IB: Interface Builder

Use prefixes when naming classes, protocols, functions, constants, and typedef structures. Do not use prefixes when naming methods; methods exist in a name space created by the class that defines them. Also, don’t use prefixes for naming the fields of a structure

If you want to stick with the JSON library you use, and the "namespace" is the cause of the issue, consider adding a prefix to your own classes.

Upvotes: 1

Related Questions