Objective-C code Swift-framework-internal

532 views Asked by At

I have the following structure for a Swift framework:

FrameworkA
├── FrameworkA.swift
└── Objective-C
    ├── ClassA.h
    └── ClassA.m

Unfortunately, I cannot access ClassA within FrameworkA.swift; the error is:

Use of unresolved identifier 'ClassA'

ClassA should be protected/framework-internal.

What am I doing wrong?

1

There are 1 answers

3
Sergey Katranuk On

As per Apple Docs

Importing Objective-C into Swift

To import a set of Objective-C files in the same framework target as your Swift code, you’ll need to import those files into the Objective-C umbrella header for the framework.

To import Objective-C code into Swift from the same framework

Under Build Settings, in Packaging, make sure the Defines Module setting for that framework target is set to “Yes”. In your umbrella header file, import every Objective-C header you want to expose to Swift. For example:

#import <XYZ/XYZCustomCell.h>
#import <XYZ/XYZCustomView.h>
#import <XYZ/XYZCustomViewController.h>

So, officially, it looks like there's no way to see an Objective-C class in Swift files without exposing it publicly. ☹️