1

We are developing an iOS dynamic framework. It will be distributed to internal teams via cocoapods.

I was wondering if we can somehow prevent the access to the internal classes, is it even possible? Is there some obfuscation flags or tool that might help here?

The idea is to hide internal (private) classes, at the same time distribute the dynamic framework via cocoapods.

HAK
  • 2,023
  • 19
  • 26
Ajit Singh
  • 128
  • 1
  • 2
  • 7
  • Are you talking about access specifiers? Like private, public, internal etc? Which language are you interested in? Swift or Obj-C? – HAK May 23 '18 at 06:37
  • Swift. I want some of the files to be exposed at all to the consumers of my dynamic framework. – Ajit Singh May 23 '18 at 07:48
  • I am planning to try https://github.com/rockbruno/swiftshield, may this be useful for you? – Alex Cohn Dec 22 '20 at 10:04

1 Answers1

1

Swift 4 has 5 access specifiers:

  1. open
  2. public
  3. internal
  4. fileprivate and
  5. private

Among which open is the least restrictive while private is the most restrictive.

Use open or public specifier for the classes/structures or variables that you want to expose outside the module.

By default anything you define is marked as internal. Can be accessed within the module but not accessible out side.

fileprivate exposes the variable/class or structure to the defining class.

private is the most restrictive and cannot be used outside its defining class or structure.

Generally for public API open and public are used.

For concerete details refer to the Apple docs: Access Control

HAK
  • 2,023
  • 19
  • 26
  • Hak, I believe access specifier plays a role when creating the binary of the framework. But here I was to share the framework as cocoapod. – Ajit Singh May 23 '18 at 09:43
  • Cocoapod is just a way of sharing the framework. At the end of the day you are creating a framework that will be imported as a separate swift module. Hence these access specifiers work. How you distribute your framework doesn't affect the language semantics. – HAK May 23 '18 at 10:33
  • 1
    Hello @AjitSingh, I see that these access specifiers that Hak mentions, don't make the needed classes hidden like you want. It's the same thing I'm looking for, I have some classes that I want to hide, but even with theses access control specifiers its still shown. What was your solution for this ? – Maryeme Alaoui Feb 08 '19 at 15:41
  • @MaryemeAlaoui - This was the best possible option I could find and implement, at that time. – Ajit Singh Feb 10 '19 at 09:33
  • Note that if the Swift module has C part, it is [exposed by default](https://stackoverflow.com/q/65396920/192373) – Alex Cohn Dec 22 '20 at 09:56