2

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?

Michael Dorner
  • 17,587
  • 13
  • 87
  • 117

1 Answers1

4

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. ☹️

Community
  • 1
  • 1
Sergey Katranuk
  • 1,162
  • 1
  • 13
  • 23
  • Importing it in the .h framework file is not an option because you want it to be internal, right? – Sergey Katranuk Dec 23 '16 at 17:37
  • Actually yes. If I need to make all Objective-C files public, then a framework does not make sense anymore, right? :-) – Michael Dorner Dec 23 '16 at 18:03
  • If you want to keep your code safe you shouldn't use Objective-C in the first place. If you do a class dump all your interface will show up even if you link it as a static library. The only way to minimally secure it is to write in C, C++ or in Swift and add it to the main app as a static library. Then you can strip all the symbols and make it more secure. If you want to test that use the Hopper disassembler on your code and you'll see what I mean Try also Steve Nygard's class-dump utility and you'll see how exposed your code will be. – jvarela Dec 23 '16 at 18:46