2

In Objective C we have both .h and .m files. These .h header file declarations define the public interface of the class and .m file declares some properties and methods used internally by the class, so any app that uses this library won’t have access to them.

But in swift all my code is visible to public. So how to create Frameworks in swift without allowing users to see my code?

Cherry
  • 699
  • 1
  • 7
  • 20
  • 5
    Possible duplicate of [How to distribute Swift Library without exposing the source code?](https://stackoverflow.com/questions/25020783/how-to-distribute-swift-library-without-exposing-the-source-code) – Ssswift Jun 01 '17 at 15:02
  • When you distribute a framework, you are distributing the implementation details. A developer can disassemble the framework and/or use class-dump to see all the details, including the implementation. Not as convenient as source, but not much of a hindrance to a knowledgeable developer. – bbum Jun 01 '17 at 20:08
  • Possible duplicate of [Swift: how can I create external interface for static library (public headers analog in Objective-C .h)](https://stackoverflow.com/questions/24070722/swift-how-can-i-create-external-interface-for-static-library-public-headers-an) – Willeke Jun 01 '17 at 21:59

1 Answers1

0

By using Xcode 8.3, swift 3, I can distribute a Swift framework without exposing my Swift source code.

My framework project: My framework:

My application project:Application project

There is no .swift source code in the distributed framework:enter image description here

Duyen-Hoa
  • 15,384
  • 5
  • 35
  • 44
  • Thanks for the answer Hoa, however I am actually looking for different solution. I want to expose method declarations to Users, because by seeing method names and comments written on top it they can understand something about what exactly that method is doing. In the above example since you have created framework, you know that there is a "foo" method and what parameters you have to pass but it will be difficult to new users. Anyway thanks for your prompt response. – Cherry Jun 01 '17 at 16:19
  • Hello @SivaCherukuri , it's the same thing I'm looking for, I want to show only my classes and methods declarations without implementation. What was your solution for this ? can you help please ? Thank you – Maryeme Alaoui Feb 08 '19 at 16:09
  • @MaryemeAlaoui, have you fond any solution? – Pramod Shukla Apr 20 '22 at 09:10