简体   繁体   中英

How to *** include *** source code within my macos Swift framework

This is for macOS. No iOS-specific answers, please.

How can I configure my macOS Framework project in Xcode to include / bundle / package all my source code so that it is available to all client projects that use the framework?

EDIT - I am the client of my own framework and I want to be able to open the framework source when developing using it.

To give an analogy of what I want, when you download a Java library as JAR, you often get bin and src folders within that JAR, and the Eclipse IDE is able to then show the source. In other cases, you can download the source separately, and "Link to source" in Eclipse. That's what I want.

I've done TONS of research on Google, and found results for hiding source code, but none for showing it.

My progress so far

I've successfully built my macOS-only Swift framework which contains a single public Swift class with a public init and all functions public.

I'm also able to import the framework's module successfully in my app project which uses the Swift class from the framework. All good. It compiles fine.

import MyFrameworkModule
let myObject: MyFrameworkClass = MyFrameworkClass()

The problem

Now, when I Cmd+Ctrl+Click on MyFrameworkClass in XCode , I want it to open the source code of MyFrameworkClass from within MyModule. But, it opens a blank file with 2 empty lines, ie no source code is shown.

How can I configure my macOS Framework project in Xcode to include / bundle / package all my source code so that it is available to all client projects that use the framework?

Once you build your framework, the only thing you should see is the public interface of your framework, all the information about your source files implementation private methods etc are lost.
And this due to the fact that what you compile become a mach-o file that contains your compiled framework. You can inspect you framework and also the binary part of it. The framework is just a directory by pointing to it you can see all contained resources and that mach-o file.
You can also inspect the Mach-o file, and if you do you will see that most of the informations are "lost", you see for instance that all your methods name and classes have been mangled.
If you want to share your source code just share it, they can integrate your framework project inside their project, in this case they will be able to have direct references to your source files. Or you can use a dependency manager such as cocoa pods and basically sharing your source code and having the process of integration simplified.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM