Convert swift Xcode project into importable cocoapods - ios

I have a Xcode project and it's running well.
But now I want to convert my Xcode project into importable cocoapods, so I can import same cocoapods in multiple Xcode project and create new separate app with same features. (by changing some UI configuration only)
(Basically, I want to move whole app/project into cocoapods, including storyboards, assets and all files. so I can create another similar app by just re-branding UI)
Can someone please help me how to configure and setup for this kind of structure?
Thanks.

Related

Modifying Cordova iOS platform template -- linking frameworks?

I have been working on a Cordova project for both iOS and Android.
As part of the project as we will need to build a number of projects from a basic template.
I have done this by creating a template for the actual cordova project and also as part of it I pulled the cordova-ios-master code base for when we add the iOS platform. So we use our own cordova-ios-master due to some small modifications we needed to add.
With some of the plugins we have added / created we need to access SDK's / API's from some third party developers (this is mainly for some push notification services). Normally when we create the project and have added the platform we then need to add the linked frameworks using Xcode.
However I can see that within the cordova-ios-master there is the template Xcode project. I was hoping I could add the linked frameworks within this project so that they are already added when we first create the project and add the custom iOS platform.
What seems to be happening though is if I add the linked library into the template Xcode project and then save it. Once I then re-add that platform to the cordova project instead of the Xcode project being named after the cordova project name, it seems to have messed the re-naming of the Xcode project.
Below shows how the Xcode project normally appears when you add the libraries manually after adding the platform
So if i modify the Xcode template in cordova-ios-master, shown below....
You can see it already has a libCordova.a added.
I add one more and re-save the project.
But then when I add the platform to my project again from this source, i open the Xcode project for it and whilst my library is added, the project was named "myproject" but i can't choose to run it as the project selection seems to appear as "PROJECT_NAME" as opposed to being named and usable as "my project"....
Im fairly new to mac's and Xcode so maybe I'm doing something basic wrong.
Any suggestions or ideas would really help, I hope this post makes sense, it is a bit complex.
Thanks again
Rhys
Right I found a solution. I think I was looking at the problem the wrong way round. So if I need to add a framework for a particular plugin, rather than edit the Xcode project to add the framework. Cordova actually gives you the option to add certain frameworks from within the plugin.xml. Found this answer here....
How to copy a custom ios framework using plugin.xml on Phonegap 3
so I have added a required framework like so....
<framework src="src/ios/OtherLevels/OtherLevels.framework" custom="true" />
My bad!
-Rhys

How to add unity project in a currently existing ios project?

I have searched a lot about this. But all the answers suggest that, it is possible to add new files into unity(xcode) project but vice versa is not possible. Actually, my target is to create sdk which will be used in a cordova plugin. What should I do?
To create an iOS sdk for unity you can create a library project in xCode and import the build to unity's Assets/Plugins/iOS folder. everything in here will automatically get included in xCode project generated by Unity.
And yes, it's very hard to include unity build in your own xcode project. There have been people begging for enlightenment to integrate Unity in another app but every time the threads are stranded beyond hope. Gibberish-gibberish... It's not possible.
It's extremely frustrating but it is possible. It requires a lot of changes to the build settings and compiler settings as well as customizing the launch of Unity components.
Best place to start is to import the Classes, Libraries, and Data folders (if applicable). Data as a folder reference and not a group. I'm also assuming your Unity project output is similar to what I've been given. We've modified our main.m file to be a C++ file (main.mm) and added in the Unity initialization code. We also updated the UnityAppController.mm file to not run startUnity on launch.
If this is still something you're working on please feel free to contact me on Twitter (#Ruprect) and I can help troubleshoot.
In this repo: https://github.com/jiulongw/swift-unity you can find how to integrate Unity Project into Xcode Swift Project.

Adding Framework and App as the target for same Xcode project

I have a Xcode project released on the app-store. Now I want to create a framework with some part of the app to be used by other users.Also I want to reference the same file which are common between app and framework so that any modification done should not be done twice(once in framework file and next in app file).What will be the best approach to do it? Shall I create a separate Xcode project and add those files by unchecking the option copy items if needed? Or can I add one more target in Xcode project as framework?
Please help.
you can use frameworks or CocoaPods.
you can find how create iOS Framework here.
For CocoaPods see raywenderlich tutorial
hope this will help you.
This source may help in you making reusable modules in a drag and drop framework

Unity-iOS: Separating Unity iOS project into any existing iOS Xcode project

I have developed Unity iOS project. I am using some 3ds max model files in it with some animation. When I create project through Unity, it does creating it automatically and installing it on the iPad. Now, I want to include this unity based functionality into my existing iOS project. How can i separate this unity project and integrate into my existing iOS Xcode project? I see lot of dependancies in Unity created project. I don't know the steps how can we separate this and integrate into any existing iOS Xcode project?
Please advise!
Here's how we did it using Unity 5.2.2f1, Xcode 7.1 and Swift 2.1.
The steps outlined in the link below seem like a lot, but honestly, aside from the Import/Cleanup of some of the unity files, it takes < 5 min once you know the steps.
https://github.com/blitzagency/ios-unity5
Actually thats not THAT hard to do. But honestly i would recommend not to try to integrate the generated project into your own, but start with the generated project and integrate yours. Since usually your part of the project will have a lot less changes in the build settings and dependencies.
Once you done the integration, you can update from a new export by simply copying the Classes and Libraries Folder from the generated project to the integrated one.
I explain how we integrated Unity into our iOS App in more detail here: http://www.markuszancolo.at/2014/05/integrating-unity-into-a-native-ios-app
regards

How to reuse Swift code in other projects?

I wrote a class in Swift. I want to use this code in two separate iOS app projects that I wrote. Both the shared code and the apps are written in Swift. What is the best way of doing that?
I tried to create both a framework and a library in Swift and then add it as a sub-project to my app. In both cases I could not make the app see the module. I tried to add the shared module to "Target Dependencies" and "Link Binary With Libraries" of the main app's target. No luck - the app still can not see the classes of the shared module.
Using Xcode6 Beta6 at the moment.
Solution
As Konstantin Koval and Heliem pointed out, all I needed is to use public in my class and method declarations, in the shared module. Now all works, both if I use workspace and if I add the module as a subproject.
Update
I just found an excellent easy solution for reusing code between projects in Swift. It is called Carthage (https://github.com/Carthage/Carthage). This is not a plug as I am not affiliated with it in any way, I just really like it. It works in iOS 8+.
Create a new project (iOS Cocoa Touch Framework) for your reusable code
Move your classes to that Framework project
Mark your methods and classes, that should be visible to others as public
Create Workspace.
You can create a workspace on step 1. When you create new Framework project, Xcode will ask you if you want to create new workspace and add that project to workspace. This is the best approach
Add both your project and Framework to the workspace
Select you project target -> General tab. Add Framework and Libraries (add your library here)
When you want to use code from your Library in swift file, import it using import 'LibTargetName'
You can take a more programatic approach by using SWM (Swift Modules): https://github.com/jankuca/swm
It is very similar to npm (node.js package manager) or bower (client-side module manager); you declare your dependencies in a swiftmodule.json file like below. It does not have a central module registry like the two mentioned JS solutions, it only accepts git URLs.
{
"name": "ProjectName",
"dependencies": {
"Dependency": "git://github.com/…/….git"
}
}
…run swm install and have the Dependency module (compiled into a *.swiftmodule binary) ready for import in the .modules/ directory.
import Dependency
And if you prefer to skip Xcode for app development, you can also build your whole app using swm build (more info in the project's readme).
The project is still in early stages but it makes itself useful a lot for me at least. It provides the most clean (and clear) way of creating importable modules.
Here is a video which is very straightforward: http://eonil-observatory.tumblr.com/post/117205738262/a-proper-way-to-add-a-subproject-to-another-xcode
The video is for OS X instead of iOS. But you will get it and figure out the process for iOS.
Let's assume that AppA needs to reused code from SharedProject.
The following process works for me in Xcode 7 Beta:
Create SharedProject. Project type must be Framework instead of Application. You write common code in this project and mark the code as public.
Open AppA in Xcode, open the folder which contains SharedProject in Finder. Drag the .xcodeproj file of SharedProject from Finder and drop it into the root folder of AppA in Xcode Project Navigator.
AppA --> Build Phases --> Link Binary with Libraries. Add SharedProject.
import SharedProject and reuse code from SharedProject!
Edit:
Nowadays I suggest you use Carthage. It's better than the home made solution above.

Resources