Adding sub-project in swift - ios

I have 2 projects in a workspaces, both are built using Swift.
I want to use one of the project as a sub-project of the other one and the classes, which are in the sub-project, in the parent project.
My sub-project is using bridging-header.
I have tried to add one project as a reference to another and imported the class, which is in sub-project, but it didn't work.
Showing me Error: "No such module "
Please help me achieving this?

Fixed the issue, thing i did was:
Removed bridging header file, which was bridging my objective-C and
swift code from my framework and deleted the bridging header file from Build Settings.
Created a file named "Framework-name.h" and copied all the header files, which were there in my bridging header file, into "Framework-name.h" file.
import "Framework-name.h" inside "Framework-name.h" file (this is vey important, it will keep the file at the root level of the framework).
Made "Framework-name.h" and files that were included in Framework-name.h" file public.
Created an aggregate target for my framework. https://medium.com/#syshen/create-an-ios-universal-framework-148eb130a46c
Built the framework.
Drag and drop the created framework into the root level of another sample project.
Test the framework, writing import Framework-name in swift class of the sample project.
Build the project.
Bingo!!!

Related

Xcode framework: Swift Generated Interface not in DerivedSources folder

Xcode 10, iOS 12
I have a project, that has 2 targets: an app and a framework. I use both Swift and Objective-C. I'm trying to reference Swift classes from Objective-C. I've set the SWIFT_OBJC_INTERFACE_HEADER_NAME property to "SwiftInterface.h" in the project, and when the target is "app", all is working well, I can include and use Swift classes. With the same settings, the "framework" doesn't compile, because it can't find the generated header.
What I have investigated:
The "app" generates the header file to {TempFolder}/{Project}.build/Debug-iphoneos/MyApp.build/DerivedSources/SwiftInterface.h
The "framework" has the corresponding folder, but the header file is missing.
I've read, that this might be because of Swift compiler errors, but it is not, since the file is actually generated in the MyFramework.framework/Headers folder, where the public headers are.
Now, if I copy this header file to the DerivedSources folder manually, the framework seems to compile normally.
So the question is: How can I make Xcode generate the swift bridging header to the right place, and how to remove it from the public headers folder.
Clean, Rebuild, DerivedData-Nuke didn't help.

No Such Module error in objective-c framework inside Swift

I implement a API to my project. However, class doesn't see the library inside a swift class. (I was using the same api with same project before but now I created a new project but now It isn't working).
First I implement the class in build Phase then create "New copy file phase" but didn't work. I also create bridging header file.
]4
I delete framework from build settings etc.. then moved it to the project directory and It worked!

Unable to import bridging header

Im trying to link an external Objective-C framework, "frameworkSDK", to my swift project. However I seem to be getting this error :
<unknown>:0: error: failed to import bridging header
I've looked at loads of solutions to my problem but non of them seem to work. Here's what I've done so far :
I've created a "bridingfile.h" at the root of the project and
imported "frameworkSDK.frameworkSDK.h" to the file.
I've made sure Objective-C Bridging Header path was correct under
Swift Compiler - Code Generation.
I've changed my framework search paths to the where the
"frameworkSDK" is located - Code Generation.
Added the path to "bridgingfile.h" to Header Search Paths - Code
Generation.
I've tried to instead create the bridgingfile 1 directory in from
the root folder, and then update accordingly.
Any help would be greatly appreciated! :)
If you are importing an external Objective-C framework, i.e. one stored in, say, frameworkSDK.framework directory structure (bundle), you should not have to worry about a bridging header. Instead do the following:
Under Build Settings set Framework Search Paths to the parent
directory of the frameworkSDK.framework directory.
Also under Build Settings set Runpath Search Paths to
$(FRAMEWORK_SEARCH_PATHS) #executable_path/../Frameworks.
In a Swift file where you want to use the Objective-C framework do
import frameworkSDK.

No Such Module 'Ensembles' Error - importing objective-c framework to use in swift project

I am add Ensembles to my Swift project - found here https://github.com/drewmccormack/ensembles. I have had no luck adding iCloud support to my app and syncing data across devices so hoping this will work.
I have followed the following instructions for adding the framework to my app,
In Finder, drag the Ensembles iOS.xcodeproj project from the
Framework directory into your Xcode project.
Select your App's project root in the source list on the left, and then select the App's target.
In the General tab, click the + button in the Linked
Frameworks and Libraries section.
Choose the libensembles.a library and add it.
Select the Build Settings tab. Locate the Other Linker
Flags setting, and add the flag -ObjC.
This is how it looks in my project, I am unsure if i have done this step right.
Select the Build Phases tab.
Open Target Dependencies, and click the + button.
Locate the
Ensembles Resources iOS product, and add that as a dependency.
Open the Ensembles iOS.xcodeproj project in the source list, and open the Products group.
Drag the Ensembles.bundle product into the Copy
Bundle Resources build phase of your app.
Add the following import in your precompiled header file, or in any files using Ensembles.
It is step 10 that I am having problems with. Do I have to create a bridging header or just import the framework into my swift files ?
This is how I am importing within my CoreDataStack.swift file
import UIKit
import CoreData
import Ensembles
class CoreDataStack: NSObject, CDEPersistentStoreEnsembleDelegate {
}
This gives me the error;
No such module 'Ensembles'
I tried creating a bridging header by doing the following;
Add new header file
Import Ensembles
This is how that looks;
#ifndef Header_h
#define Header_h
#import <Ensembles/Ensembles.h>
#endif /* Header_h */
But still no luck, does anybody know where I am going wrong when trying to import the framework to use with my swift project ?
When creating a bridging header you do not need to use import.
However I don't think you may be adding a bridging header correctly, go to, file, new, file, add a objective-C file and a dialog should pop up asking if you want to create a bridging header. Add both files but delete the objective-C file and keep the bridging header.
Then import the ensembles framework to the bridging header like so.
#import <Ensembles/Ensembles.h>
When creating a bridging file successfully you should not need to import the framework in your swift files and it should be available throughout your project. See this post for more information - Connect Objective C framework to Swift iOS 8 app (Parse framework)

Can't include Objective C Files into Project?

I want to include an Objective-C project (https://github.com/soffes/ssziparchive) into my Swift Project so that I can include the SSZipArchive into my project. I need this so I can unzip a file. As included in the instructions on the Github, I included the folder minizip, SSZipArchive.h, and SSZipArchive.m into my project. I have also created a bridging header where I included the following import into my project #import "SSZipArchive.h". However, when I try to type SSZipArchive on Xcode, the autocomplete doesn't occur, leading me to believe that SSZipArchive isn't included properly in my project. Any ideas on how to do so? I have already looked at numerous links on how to include Objective-C projects into Swift and I have found that I simply need to include the corresponding header files for my project to work.
I guess that you haven't set bridging header path properly. It's a very common problem, but easy one to fix.
Go to the Project Settings -> Build Settings -> Search, and search for bridg, and under Objective-C Bridging Header set the path of your bridging header file (carefully inspect it's path in Finder first, since it may be in some sub-directory of your project).
Also make sure that all your included header files have target of your application. To check if they have, click on the header file, open up Utilities from the right side and under Target Membership, make sure the first target is checked.

Resources