Duplicate class issue while linking a framework in iOS - ios

How to Link a framework in your project where framework containing a class whose name is exactly the same of yours.?.I know that there is solution if we need to import same header name in two different target,because targets can be configurable.My case is different . For me I have a framework which have a file named a.h and it's a.m (For clarity let "a" be AppDelegate).The project where I want to use that framework also contains both(AppDelegate).So how to configure that I can run framework inside that project

Related

Xcode change dynamic framework Product Module Name

I’m trying to change the product module name of a dynamic framework.
The main reason I’m doing this is that my framework is customised for each client, so I have different targets with different names and output files that I want to keep different as they are, but I would like the framework to be imported for all the targets with the product name.
The framework is in objective C and consumed by a swift application.
In the Xcode build settings the DefinesModule is set to YES.
Let’s say the product name is CustomerSDK and I want it to be imported as ProductSDK.
For example: The framework file will be CustomerSDK.framework and the import statement import ProductSDK.
If I use the $(PRODUCT_NAME:c99extidentifier) as the module name (the default option in Xcode) by calling import CustomerSDK it works, but when I try to change the Product Module Name field in build settings to another one the code completion of Xcode in the host application project doesn’t find the module name and even if I write it I get the “No such module ProductSDK” error. Looking inside the resulting product framework I can see that no modulemap file is generated.
I tried also to create a custom module.modulemap file, in this case the code completion of Xcode in the host application project proposes the new name, but when I try to compile I still get the “No such module ProductSDK” error.
framework module ProductSDK {
umbrella header "CustomerSDK.h"
export *
module * { export * }
}

Access parent class from subproject framework

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.

Swift: using private framework

I have built an iOS Swift framework with Xcode.
After writing the code I have build the project and took the .framework file inside the Products folder to test it.
To test the framework have open a new application and drag and drop the .framework file previously built and I added it into the embedded binaries list of my application project.
To import it into my ViewController.swift class I wrote:
import frameworkName
No problem until here, this means that the project sees the framework.
When I try to use a public class inside the framework with:
var x : className?
I get the following error:
'className' is unavailable: cannot find Swift declaration for this class
What does it mean? What is the problem?
When you're referencing a framework in the products directory from your workspace, ensure that the location is "Built Products" and the filename is just the framework name, without any additional path components.
If you're referencing a framework that isn't in your workspace, I would recommend using Carthage instead of copying it directly into your repository. This will make versioning much easier, and will ensure that it is built correctly for both simulator and device.
To actual a self defined framework, u really have to do a lot of things.
Firstly, make sure ur framework is used on right device. It's to say framework can only be used on corresponding device(either one of Simulator, Device and Mac). In other words, if framework A built on simulator, project import framework A can only pass compile and successfully built on simulator.
P.S. if universal version desired, -lipo command is what u need to further explore.
Secondly, during implementing ur framework , make sure all the classes, methods and variables u want use outside start with Public.
Thirdly, check ur project setting Embedded Binaries and linked Frameworks and Libraries do contain ur framework.

Add Cocoa Touch Framework target - product is not created

For existing project that I have, I would like to add Cocoa Touch Framework target, to bind all the code in one package and later use it in another project.
I've succeeded creating and using standard Cocoa Touch Framework (created framework, added custom classes with function, built a framework product, dragged it to test project , imported my public headers and was able to use the functions)
Now I am trying to create the real thing. It is a bit different. The framework is not created from scratch. I have to use already existing classes of a project.
So I have added a new Cocoa Touch Framework target to the project. I am building the target but the framework product is not created. Why???
The framework was actually created. Strangely though the it was marked red in xCode in the products section, so I thought there was some problem. But it was found in the derived data folder.

iOS import swift class from swift using framework

How do I import a Swift class from a framework?
I have Xcode Workspace
I create a Cocoa touch framework with using Swift
I create a Swift class named TestClass in that Cocoa touch framework
I create a Tabbed Base iOS application
I import my framework in that tabbed iOS application using import FrameWorkTest
The application project compiler can't find TestClass.
How can I import TestClass for use in the main application?
It says that TestClass is not defined. I also want to add an extension in FrameWork an then use it.
https://github.com/ArtemKyslicyn/-SwiftImportFrameworkTest
I'm using this Tutorial
http://www.swift-studies.com/blog/2014/6/30/creating-a-pure-swift-framework-for-both-ios-and-mac
I'm on Xcode version 6.0 seed
Thanks
Make the class in framework public. Also any variables must be public if you want them to use outside the framework.
public class MyClass... {
...
}
Here's one solution I found:
Create new iOS project
Press on project
Press + to add target
In the resulting window, choose cocoa touch framework
Press on project and press add dependency and add framework
Success!
I used the solution here: https://github.com/ArtemKyslicyn/-SwiftImportFrameworkTest in the project named AddingFrameWork
#Artem Kislitsvn: I did see your github repository,
In which you have TestClass.Swift file outside the targets 'test' and 'FrameWorkTest'. Which is out of the scope of the namespaces.
In Swift the namespaces are specified per targets. In your case 'test' and 'FrameWorkTest' are two targets. If you keep your file out of the targets, then your class(.swift file will not visible to at any time).
The solution is very simple. You just move your TestClass.Swift file inside any of the target groups (Drag and drop through Project explorer).
Following this your project works...!
To import a Swift class from a framework:
Go to your Project -> Build phases -> Select test target -> Link Binary With Libraries -> + Button -> Add other (on the dialog) -> Select your framework and congrats!
I leave the explanation in images below:

Resources