I downloaded code from here:
https://github.com/QuickBlox/quickblox-ios-sdk
wich include sample-chat-swift example folder where seems somehow guys created a framework.
In my case if I just use cocoa pods to pull code into my project Xcode says to me that we can't find any of downloaded classes. So I am sure that is problem with bridging but my question what are the steps I need to do to create framework like guys did in theirs example.
Or do I need to bridge each files manually? If so I guess it can take so much time.
I created my own framework for using Tumblr in an app. I'm sure you know how to setup a framework project, but I'll explain what I did when I complied the framework. After you finished the framework what you do is under your xcode project folder in the directory is a fold Products. The text for Project.framework should be red or black. Either way run your project and make sure its black. Then right click and choose Show in Finder. Then you can copy that framework and bring it into the top of the project you want to use the framework in.
You will also need to make a header file. Like the one I have below if you are using Obj-c, but I'm sure you can google and find an example in swift it you are trying to hide certain aspects of your framework with a swift interface file.
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
//! Project version number for Tumblr.
FOUNDATION_EXPORT double TumblrVersionNumber;
//! Project version string for Tumblr.
FOUNDATION_EXPORT const unsigned char TumblrVersionString[];
// In this header, you should import all the public headers of your framework using statements
//#import <Tumblr/Tumblr.h>
#import "TMSDKUserAgent.h"
#import "JXHTTPDataBody.h"
#import "JXHTTPOperationQueueDelegate.h"
#import "TMTumblrAuthenticator.h"
...
Regarding bridging issue, guys form QB answered on it:
so using this http://quickblox.com/developers/IOS-how-to-connect-Quickblox-framework#Additional_steps_for_Swift_using_CocoaPods
we can simple achieve bridging, even without creating framework.
Related
I am trying to create a Swift wrapper for the FIT C++ libFitSdkCppiOS.a library but don't really know how to set things up with the mix of C++, Objective-C and Swift code.
Here is what I have done so far:
1. Created a new target for the FITFramework
2. Copied the libFitSdkCppiOS.a library and the associated cpp header files into the targets folder in Xcode
3. Because you can't use a Bridging-Header file in Frameworks I am trying to figure out how what to do next.
I have seen a few posts about something called an umbrella header but have no idea what that is or what needs to be in it to get this to work. Can someone please explain step by step what I need to do to create this Swift Wrapper and package it up as a framework that can be used by other projects.
Is the umbrella header the main framework header file, in this case the one called FITFramework.h ?
If not how do I create an umbrella header file and where does it need to be?
What should be in the umbrella header file?
FITFramework.h
//
// FITFramework.h
// FITFramework
//
// Created by xxxx xxxxxxx on 7/6/18.
//
#import <UIKit/UIKit.h>
//! Project version number for FITFramework.
FOUNDATION_EXPORT double FITFrameworkVersionNumber;
//! Project version string for FITFramework.
FOUNDATION_EXPORT const unsigned char FITFrameworkVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <FITFramework/PublicHeader.h>
EDIT:
1. How do I expose the Objective-C classes to Swift without using a Bridging-Header file ?
There are a few articles that mention the use of a module.map file but this seems to be to expose the C headers rather than the Objective-C headers to the Swift wrapper function
OK I figured it out - and it was hard to find any good or accurate guides. I will write it up in more detail elsewhere and add a link at some point.
In the meantime - assuming your framework is call XXXFramework - you need to:
create a XXXFrameworkPrivate subdirectory in the XXXFramework folder with a module.modulemap file in it
add the private headers to the module.modulemap file like so
module FitFrameworkPrivate {
header "../XXX.h"
header "../YYY.h"
header "../ZZZ.h"
export *
}
create a XXX.xcconfig file with the following line
SWIFT_INCLUDE_PATHS = $(SRCROOT)/XXXFramework/XXXFrameworkPrivate
set the project configuration to use this config file for both debug and release
add this line to your Swift classes
import XXXFrameworkPrivate
Basically this allows Swift classes to import the headers from the module.modulemap file instead of using a Bridging-Header file which can't be used in a Framework.
Watch out though - I have callbacks between the C++ classes, the Objective-C classes and the Swift classes and this creates a problem if your public class uses a protocol to communicate with one of the private Obj-C classes. To avoid that add another public Swift class that talks to the Swift wrapper and only have that one public.
If anyone has a better way of doing it please let me know.
Thanks a lot! This answer was very useful to me as I had similar issue (to integrate the c fit sdk instead of the c++ fit sdk into a swift framework for macOS and iOS apps)
I'll just add the follow step I had to do, in case it helps someone:
When using the framework in a app that used Pods, I wasn't able to include the "Private" framework (necessary because it contains the c constant converted to swift constant like FIT_MESG_XXX) and the xcconfig are set by the Pods framework. Editing the Pods xcconfig worked, but clearly bad.
Eventually, I figured out you can just create a new xconfig with a #include and use that in the external app where you want to use like so (this is separate from the xcconfig you need to build the framework)
#include "../Pods/Target Support Files/Pods-iOSorMac/Pods-iOSorMacOSApp.debug.xcconfig"
SWIFT_INCLUDE_PATHS="$(SRCROOT)/fit-sdk-swift/RZFitFile/sdk" "$(SRCROOT)/fit-sdk-swift/RZFitFile/src"
I want to use one third party library which is written in Swift but I am working in Objective-C environment. How to do that? Until now what I have done is:
Drag and drop the third party library into my project.
It is asking for the bridging header I clicked on yes.
In Build settings defines Modules no to yes in both.
Product Module Name showing like $(PRODUCT_NAME:c99extidentifier). I have tried with my project name also.
Now I am getting plenty of errors like below:
pDatePicker.swift:50:9: Consecutive declarations on a line must be separated by ';'
and
Ambiguous use of 'open'.
I am getting errors around 50 to 60 same as above errors. Where is my mistake? Can anybody help me?
Are you able to see projectName-Swift.h file in your project ?
Demo Example is available on github.
https://github.com/hasyapanchasara/UsingSwiftInObjectiveC
If yes then, Hope you have imported #import "projectName-Swift.h" in Objectice C .m file ?
#import "projectName-Swift.h"
Then only you would be able to access objective c files in swift code.
Refer
https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html
Check in build setting
Objective-C Bridging Header
ProjectName-Bridging-Header.h has perfect location.
if there is problem with that path than bridging will not work properly , that why when you compile #import "projectName-Swift.h" is not getting generate.
Download
Download above sample project.
Make sure, that your swift version in settings is the same as this lib uses; if not, try to translate it by yourself, or set Use Legacy Swift Version to YES
I'm trying to build a Cocoa Touch Framwork (XCode 6, obviously) with Objective-C and some Swift classes.
I've successfully added Swift classes to regular projects (no framworks) before so I'm aware of the build settings required for this (Embedded Content Contains Swift Code). Unfortunately, the framework project doesn't build the header file (projectName-Swift.h) and I'm not able to import the class and the Swift classes into any of my .m files.
Does anybody know why this wouldn't work, and what build settings I need to change in order to make this work?
Finally found the answer;
Within the frameworks the import statement for Swift files has to look as follows;
#import <ProjectName/ProjectName-Swift.h>
instead of
#import "ProjectName-Swift.h"
Sometimes it helps to RTFM (https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_82)
I've struggled with this for a while because I don't think the documentation is clear. I have a slightly different project setup, and it's taken me a while to work this out so I thought I'd answer here.
I have a project with name: MyProject
In this project, I have a framework: MyFramwork
I have a swift file in MyFramework which I want to import into an objective c file in MyFramework.
To do this, you need:
#import <MyFramework/MyFramework-Swift.h>
NOT
#import <MyProject/MyFramework-Swift.h>
Hope that helps someone.
I'm writing an iOS App using Parse.com to interact with a server.
I've downloaded and installed the SKD, added all frameworks correctly and everything works fine until it comes to the PFQueryTableViewController. It doesn't appear in the drop down list when I'm creating a new class and I can't create one programmatically because Xcode just doesn't know it.
Same with a PFImageView, is this somehow related?
The SKD should be up to date since I updated it yesterday including the local datastore.
Am I missing here something?
Thanks in advance!
For anyone using swift having this issue. In your bridging header file make sure you have the following:
#import <Parse/Parse.h>
#import <Bolts/Bolts.h>
#import <ParseUI/ParseUI.h>
There are two possibilities:
You do not have the Frameworks compiling properly. Make sure the Frameworks are properly installed by following the instructions here: https://parse.com/apps/quickstart#parse_data/mobile/ios/native/existing
The Xcode UI is not seeing the class properly to add it for subclassing - not a big deal. Get around it by starting the creation of a new class, then when you get to the naming page, simply start typing in the 'Subclass of:' box the name PFQueryTableViewController and it should autocomplete, as seen in this screenshot:
UPDATE:
You may also want to check your 'Link Binary with Libraries' under 'Build Settings'. Be sure that the Parse.framework and Bolts.framework files are listed.
I'm currently translating an Objective-C project I have over to Swift. In the process, I have a few implemented 3rd party libraries that are pure Objective-C like MFSideMenu and Parse.
I've created a Bridging-Header.h file per Apple's documentation and other's recommendations to bridge the Objective-C files with the Swift code. This works fine for frameworks like Parse. Unfortunately, when importing MFSideMenu and running the application, I receive the attached errors below.
I was contemplating if this was because a library needed to be manually imported into the Objective-C files using it, so I attempted importing UIKit and Foundation in the project and manually added the frameworks without any success. Any assistance would be greatly appreciated.
Turns out, the compiler for swift no longer supports non modular based imports for frameworks. You must change all references to frameworks to #import statements rather #import.
I had the same problem, add code below at the header file of this class
#import <UIKit/UIKit.h>
it can help you