XCFramework add third party library with Swift package manager duplicate symbols - ios

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

Related

PayMill SDK iOS swift 3.0 Xcode 8.1

I'm trying to use PayMill SDK in a Swift project.
I used CocoaPods as described by PayMill, the framework, and it generated 'Pods_PayMilDSK'
After that I tried to import it on my file but I can't get access to any to the functions included in the framework.
I also tried to import the framework directly in my project but I can't access the PayMillSDK framework (i.e. import does not 'see' it).
Any help would be greatly appreciated.
Rodolphe
After running pod install You should always Build your project, cmd + B, because your project still hasn't read the contents of the library you just installed.
Also make sure you're using the .xcworkspace and not the .xcodeproj
I can now make the import of the PAyMill module but functions are not available

How can I use a 3rd party Framework inside my CocoaTouchFramework and my consuming App?

I am developing an iOS App and a CocoaTouchFramework. The iOS App depends on the framework. My goal is to use a 3rd party Framework (in this case AlamoFire) inside my CocoaTouchFramework. According to this Stack Overflow link it is discouraged to have a Framework embed another framework. The way I understand it is that the consuming iOS App (the app which depends on the framework) needs to provide the 3rd party dependency and that my framework can reference that dependency. I don't know how to set this up in Xcode however. Here is what I have currently set up in Xcode:
AlamoFireApp is the actual App and AlamoFramework is my own Framework that will use AlamoFire to perform various network requests. I embedded the AlamoFire dependency into the App. How can I use AlamoFire in the Framework now? I've tried linking to AlamoFire from within the Framework (Adding Alamofire.framework) in the Link Binary With Libraries section) but I always get the No such module 'AlamoFire' error when I try to import AlamoFire in my Framework's classes.
Any help is appreciated.
#cbbcloud you can make your own cocoa pods using alamo fire. All you have to do is add them as dependency in pod spec. And then you can import the use the framework to build your framework.
Pod::Spec.new do |s|
s.name = 'YourFrameworkName'
//other info
s.dependency 'Alamofire'
end
If you are new to cocoapods , follow this link
https://guides.cocoapods.org/making/index.html
Ok I've found a way to do it. I was able to solve the problem by dragging the AlamoFire.Framework into my framework (in this case, AlamoFramework) in Xcode. The important part that makes this work is to check the 'Copy items if needed' checkbox.
After checking this, the compiler can resolve the Alamofire module and there are also no linker issues. However this approach seems to contradict the recommendation of Rob Napier in his answer to this question that states:
The only appropriate time to link dependencies is at the application layer.
I haven't done full-time iOS development for very long so if anyone has any input they can give to clear up this issue, that would be great. But my problem has been fixed for now so I can continue with development.

Cannot import framework file in custom framework in iOS

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.

Xcode 6 Playground using Parse framework?

I would like to use Parse SDK/Framework my playground file but I get an error if I import it. I can import the iOS frameworks like UIKit
I know there are similar posts to this (How to I import 3rd party frameworks into Xcode Playground?)
but i could not make it work for my project.
Any help here is very very much appreciated... I am not a complete newbie but am not an expert So as many details (almost for dummies ;-)) as you can please...Many thanks.
To get Parse working in playground you will need to create an Xcode project and include the Parse framework. Then within that project you can add a playground and import frameworks and code written in that project. Hope this helps.
If you are curious I did it for a framework I created and created a Playground inside the projects workspace. In that I import Dollar which is a custom framework but I guess you could import Parse and it should work https://github.com/ankurp/Dollar.swift

How to I import 3rd party frameworks into Xcode Playground?

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...

Resources