Hi there i have the following usecase and have been building a couple days and finally got a bad solution that i don't really link and would really need some assistance on. Would be much appreciated if anyone helps out.
What i have:
I have a framework that uses Alamofire as a dependency with Swift package manager.
I build this framework for distribution with Alamofire it's automatically embedded and i want to make it not embeded just to use it for development until the other project uses it and adds it there.
Next step is add it to the other project. If i don't add Alamofire in the new project there is no issue.
If i add Alamofire there is a duplicate symbols. Anyone have a suggestion how to fix this? I currently don't have a good approach i tried out pretty much everything and as far as i understand it's in development still the SPM...
Example: MyFramework uses Alamofire with SPM and App uses SPM with Alamofire i get duplicate symbols.
What i expect:
A way to be able to add Alamofire into my framework project to use it for development. After when i generate my xcframework and add it to the next project to add the Alamofire lib there and to work without duplicate symbols.
Much appreciated any info.
You can try out #_implementationOnly import Alamofire instead of import Alamofire
This will not expose import Alamofire as public interface in .swiftmodule
I am creating a custom framework in iOS. I have a built-in framework as shown in the image. When I try to import a file from an already created framework (Ex,smma) I get the error "smma.h" file not found. Any help will be appreciated.
I also had some issues with creating my own framework and including it in a project. I found Kodmunki had a really useful guide.
https://kodmunki.wordpress.com/2015/09/22/ios-9-universal-cocoa-touch-frameworks/
Pay particular attention to the section on Adding Frameworks to an App. This was where I was making mistakes. Once I followed the steps in this section I found it was working correctly.
I'm working on a personal project and I've installed Firebase with Cocoapods and imported it in the bridging-header.
My question is why do I get an error if I try to use a Firebase method in my project if I haven't written import Firebase at the top? The same can be said for Google Analytics etc.
The reason I ask is because in this tutorial: Ray Wenderlich Firebase Tutorial
Firebase is configured the same way as mine - but none of the documents contain import Firebase, and the project recognizes any Firebase method universally without errors.
I know I can just use import but I don't understand what I am doing differently and would rather not have to.
I think u have in pod file line:
use_frameworks!
delete it and reinstall pods it should help
In the mentioned project, the import is done from the Grocr-Bridging-Header.h, it's actually an Objective-C import:
#import <Firebase/Firebase.h>
The reason why the import was done from Objective-C is beause the project is quite old and Cocoapods didn't have support for Swift then.
I wonder how can I import https://github.com/mozilla/firefox-ios to my existing Obj-C project. While it does not a framework, I could not import sources of it in my Obj-C project files when I added the project into workspace. I tried to convert it to a static library, but I could not figured it out. I have a little bit experience on Swift and this creating static library thing. Actually, I am not sure this is the right way to do.
Thanks
You should check the Apples documentation about using Swift in Objective-c.(The Importing Swift into Objective-C part)
You can add a Swift-module header and import your .swift files and use them in your objective-c code.
How do I import 3rd part frameworks into Xcode Playground?
Swift Playground obviously has a framework import mechanism because we can import Cocoa, SpriteKit, and in an OSX Playground, XCPlayground (XCPlayground seems missing from iOS, oddly)
What I'd really like to do is hide code from my playground and be able to show a minimal example. Any thoughts on how to load a Framework into Swift playground?
See also:
How to import own classes from your own project into a Playground
Is it possible to import third-party Objective-C code into a Swift playground?
(This question is different because the request is to use a framework in Playground rather than simply regular swift files)
There is currently no supported way to import your own framework or app code into a playground, short of pasting it into the playground editor. We're aware that this is very desirable functionality, but as always we encourage people to "vote with bugreporter" at bugreport.apple.com
Right now, if you're just trying to hide code for showing in an example, code folding in the editor might do the trick.
It is now possible to import your own frameworks into a playground. This provides a way to share code between your applications and playgrounds, which can both import your frameworks. To do this, your playground must be in the same workspace as the project that produces your framework. You must have already built your framework. If it is an iOS framework, it must be built for a 64-bit run destination (e.g. iPhone 5s). You must have an active scheme which builds at least one target (that target's build location will be used in the framework search path for the playground). Your "Build Location" preference (in advanced "Locations" settings) should not be set to "Legacy". If your framework is not a Swift framework the "Defines Module" build setting must be set to "Yes". Once all these conditions are fulfilled, importing your framework will work in a playground.
Edited: As of Beta5 this is now supported when the playground is part of the workspace that builds the framework as a target. There are more details on the Apple dev forums site, but hopefully #Rick Ballard will add them to his answer here and that should becoke the definitive answer for this question.
Don't do the below anymore!
For the short term, while there's no supported solution, if you're producing a Module/Framework you can copy it into the SDKs System/Library/Frameworks directory and then just import <#Module#> the same way as you import system Frameworks.
For an OS X Playground: /Applications/Xcode6-Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks
And for iOS: /Applications/Xcode6-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/System/Library/Frameworks/
But before you do that... go file a radar as #Rick says in his answer.
I've written a tutorial covering import of custom frameworks in Beta 6
In short, if you've got your playground and framework either in the same project or workspace, and your framework is built for 64 bits (even for iOS), they play very well together.
source: http://qiita.com/ryokosuge/items/2551cd4faa9dca324342
If there is anyone who still had difficulty understanding how to go about it after reading the accepted answer, this may help.
It's not in English though so I will explain here:
Using Carthage:
1: Setup your Cartfile in the root of the project, add your libraries and run:
carthage update --platform iOS --use-submodules
2: Make sure your project is saved as a Workspace. From the Xcode menu bar: File > Save As Workspace. Shutdown Xcode and reopen from the new .xcworkspace file.
3: Add your library's .xcodeproj file in your workspace: File > Add files to "your_workspace_name". Then find it in: ${SRCROOT}/Carthage/Checkouts/your_library_name/your_library_name.xcodeproj
4: Find the Embedded Binaries and Linked Frameworks and Libraries section in your project's general settings. Add your library's .framework file to both.
5: Clean(⇧+⌘+K) and build(⌘+B).
6: Import your library in the playground.
I solved it by copying the built frameworks to the Built Products Directory, where Playgrounds in the workspace also searches for frameworks. Note: you also need to run lipo and strip away unused architectures from the FAT binaries.
The steps needed (in a nutshell):
Create an aggregate target
Add a script phase to copy the frameworks
from Carthage/Build/iOS/ to BUILT_PRODUCTS_DIR (I use a swift script
in the example below, but you can use also use bash, ruby python
etc.)
Run aggregate target Now you can import the framework(s) in a
Playground
Additionally you can leverage the aggregate target in your app:
Embed frameworks from BUILT_PRODUCTS_DIR, not Carthage/Build/iOS/
Add aggregate target to app scheme to re-establish frameworks after a clean.
Here is an example project setup as above: https://github.com/richardnees/CarthagePlaygrounds
Like using Objective-C classes in Swift code, you can import 3rd-party library/classes into your project and Xcode will ask you if you wanna create a <#YourProjectName>-Bridging-Header header file. Choose yes and import all header files you need in that file. After that, in your playground, you can simply do import <#YourProjectName>-Bridging-Header after import UIKit and you will be able to use the classes you imported to your project.
Update: this is actually incorrect. Please see my comment below. Sorry for any confusion...