blackstar26
blackstar26

Reputation: 146

Public classes in custom framework

In my custom framework, if i want to expose some classes/methods to swift or objective-c, i have to declare them as public, but with this method the classes and methods are exposed in the framework header. Is there a way to prevent to expose the methods to framework header?

Upvotes: 1

Views: 1101

Answers (1)

mag_zbc
mag_zbc

Reputation: 6992

If your framework is written in Swift, then use Access Levels - public, open, internal, file-private or private - documentation. You probably want to use internal

If your framework is written in Objective-C, you can use forward declaration. Instead of writing

// ClassA.h

#import "ClassB.h"

@interface ClassA : NSObject

- (void)doSomethingWithClassB:(ClassB*)obj;

@end

Write

// ClassA.h

@class ClassB;

@interface ClassA : NSObject

- (void)doSomethingWithClassB:(ClassB*)obj;

@end

// ClassA.m

#import "ClassB.h"

If your ClassA doesn't inherit from ClassB, you can forward declare ClassB in you ClassA header - in the header you're not calling any methods from ClassB, you just use a pointer to it, so the compiler doesn't need to know the full signature of ClassB. Instead, you promise that you will include the full definition of ClassB before actually trying to use it.

Upvotes: 1

Related Questions