Access parent class from subproject framework - ios

I'm trying to split in modules a big XCode project. I have a main project and one submodule as an embedded framework.
I need to import some classes from the main project into the subproject but no success.
I added the subframework in the embedded binaries and in the Linked Frameworks of the parent's project target. Moreover I added in build settings "Header Search Path" in the parent project the path of the subframework.
Any help would be appreciated

You can't. Also it meaningless because if you separate some pieces of your code into framework it means that this code doesn't have any dependencies with other code. So if you have any case when your framework need to import some class outside you have only two ways:
Include it inside framework.
Refactor framework's classes and try to remove dependencies.

Related

How to create a close source SDK for iOS with other framework dependencies

I have multiple projects that build into XCFramework. For example:
FeatureA.xcframework
FeatureB.xcframework
FeatureC.xcframework
When I build MySDK, it produces a .xcframework with a "frameworks" folder in it. FeatureA, B and C are inside that folder. This means that the frameworks were embeded.
But, when I add MySDK into another project and try to build I get: no such module "FeatureA" OR Could not build "FeatureA" to Objc.
The only way that my test project builds is by adding each .xcframework dependency. I tried using the search paths, but no luck.
I also tried change the modulemap file, but the error describe above continues.
I want to build a SDK, MySDK.xcframework that contains all depencency frameworks. In this way I hope that someone who wants to use my library will only have to import MySDK.xcframework.
What I want is even possible for iOS?

How to access one project classes from other project While using multiple project with one Workspace

I am using two different project within one workspace. I have one base(Say Unity-iPhone) project and i drag and drop another iOS project (Say InnerApp). Each file and folder are visible in base project as attached screenshot. I have also added the dependency in build phase of base project, and set the other linker flag and header search path.
Now I want to access the InnerApp classes and storyboard file in base project.
Now My problem is that, I want to launch the Inner App Main.storyboard into base project. But InnerApp classes are not accessible into base project.
Please guide me. Thanks.
You can follow some great step-by-step instructions on how to add static library dependencies while using multiple projects.
Use below urls -
Include one project into another one
Include static libraries into another one

Is it possible to create a standalone distributed Swift Framework?

I have a scenario where I need to package some common code into a Swift only framework. I have found many tutorials on how to do this but all involve creating a framework within an iOS app. My goal is to:
Create a seperate Framework project
Build and produce a .framework file
Copy that single file(without all the source files) into some iOS app project, add it under "Linked Libraries" and use it.
Question: Is this possible or do I have to include all of the Classes that are part of the framework?
I have added a framework project to an iOS app and had success using it because all the source code was in the Framework project. I tried to copy that .framework file alone to a new project and use it but when trying to access the classes or instantiate the contents of the framework I couldn't even-though whatever needed to be declared as public was.
Appreciate any help...

How to create an Xcode project that is not an app but is visible in other projects?

I want to create a project with a handful of categories that add useful functionality to UIKit.
I want to keep this as a separate project so that it can be source-controlled separately (and eventually hosted on github, and downloadable as a dependency via cocoa pods...but let's skip this for now.)
But all the Xcode 6.1 project templates imply an app inside. When I select an empty project it complains about missing base SDK. But this cannot be set without a target present. It is quite confusing. I don't need a target. Do I?
The project should be just a shell for a number of categories + a accompanying summary header file.
I want to be able to drag this project as a subproject to any other proper app project, import the summary header file and expose those categories to the main project.
Any advice?
You need a target. Every source file that should be compiled must be a part of a target.
You could reference each source file from the target(s) in your app's Xcode projects, but that'd be tedious as you'd have to add to every project manually when you add source to your shared repository.
Either create an embedded framework project or a static library. Unless you are really going to share code between an app and an app's extension, go with the static library. It is a lot easier to manage.
Create a project that has a static library target, add the files to that static library.
Then create a workspace that has your static library project and your app(s) project(s) in it. Modify the app targets to link against the static library.

How to reuse Swift code in other projects?

I wrote a class in Swift. I want to use this code in two separate iOS app projects that I wrote. Both the shared code and the apps are written in Swift. What is the best way of doing that?
I tried to create both a framework and a library in Swift and then add it as a sub-project to my app. In both cases I could not make the app see the module. I tried to add the shared module to "Target Dependencies" and "Link Binary With Libraries" of the main app's target. No luck - the app still can not see the classes of the shared module.
Using Xcode6 Beta6 at the moment.
Solution
As Konstantin Koval and Heliem pointed out, all I needed is to use public in my class and method declarations, in the shared module. Now all works, both if I use workspace and if I add the module as a subproject.
Update
I just found an excellent easy solution for reusing code between projects in Swift. It is called Carthage (https://github.com/Carthage/Carthage). This is not a plug as I am not affiliated with it in any way, I just really like it. It works in iOS 8+.
Create a new project (iOS Cocoa Touch Framework) for your reusable code
Move your classes to that Framework project
Mark your methods and classes, that should be visible to others as public
Create Workspace.
You can create a workspace on step 1. When you create new Framework project, Xcode will ask you if you want to create new workspace and add that project to workspace. This is the best approach
Add both your project and Framework to the workspace
Select you project target -> General tab. Add Framework and Libraries (add your library here)
When you want to use code from your Library in swift file, import it using import 'LibTargetName'
You can take a more programatic approach by using SWM (Swift Modules): https://github.com/jankuca/swm
It is very similar to npm (node.js package manager) or bower (client-side module manager); you declare your dependencies in a swiftmodule.json file like below. It does not have a central module registry like the two mentioned JS solutions, it only accepts git URLs.
{
"name": "ProjectName",
"dependencies": {
"Dependency": "git://github.com/…/….git"
}
}
…run swm install and have the Dependency module (compiled into a *.swiftmodule binary) ready for import in the .modules/ directory.
import Dependency
And if you prefer to skip Xcode for app development, you can also build your whole app using swm build (more info in the project's readme).
The project is still in early stages but it makes itself useful a lot for me at least. It provides the most clean (and clear) way of creating importable modules.
Here is a video which is very straightforward: http://eonil-observatory.tumblr.com/post/117205738262/a-proper-way-to-add-a-subproject-to-another-xcode
The video is for OS X instead of iOS. But you will get it and figure out the process for iOS.
Let's assume that AppA needs to reused code from SharedProject.
The following process works for me in Xcode 7 Beta:
Create SharedProject. Project type must be Framework instead of Application. You write common code in this project and mark the code as public.
Open AppA in Xcode, open the folder which contains SharedProject in Finder. Drag the .xcodeproj file of SharedProject from Finder and drop it into the root folder of AppA in Xcode Project Navigator.
AppA --> Build Phases --> Link Binary with Libraries. Add SharedProject.
import SharedProject and reuse code from SharedProject!
Edit:
Nowadays I suggest you use Carthage. It's better than the home made solution above.

Resources