How to create reusable code in iOS? - ios

I've been working on a mobile app for a couple of months. Now I want to develop other apps but reusing the code I've written. I'd like to have reusable code (ViewControllers) in order to be used in many projects. In this way, if there is some bug in one of these, I'd fix the bug and then apply the changes to all the projects that use my library. In short words, I'd like to know what is the best way to develop my own library for iOS with XCode. I've been developed for Android but I'm new in iOS development.
Is it possible to add my own library to CocoaPods?
Do you suggest any other alternative?
Thank you very much

Yes, you can create your private, internal, pods and make your applications depend on them. As an alternative you could use git submodules either.
But if you want you can even use both: having your private pods, which are also git submodules of your project, - they are usually called Development Pods - because you might want to fix a bug on your internal pod and push the fix immediately to the bleeding edge of your library as soon as you tested it on the application in which you spotted the bug in the first place.
A couple of interesting articles on this topic:
Working with internal pods
Development pods
On a totally side and obvious - I think - note, you can do this manually as pointed out by user1118321.

You can create a static library or a framework (shared library). From the "File" menu choose "New Project" and then click on "Framework&Library" under "iOS". Then choose "Cocoa Touch Static Library" or "Cocoa Touch Framework".

Related

Different apps from the same code base

I have developed a generic app, which can ne customized for clients. Each app should be available in the app store.
Any idea what is the best way to deploy the different apps? This is of course also necessary on app updates.
Only the package name, some graphics and some settings change for different Apps. The Code will be the same for all.
Consider deploying your app as a framework, static library or CocoaPod. The clients should be able to use your framework/pod to customize the appearance (and anything else) and publish their apps.
CocoaPods: If your project is in progress and your client is using it, I wouldn't recommend it. Pods are great way for managing dependencies mostly if dependencies are not going to change on nightly basis. Also you'll have to make a few decisions about how to integrate it with your source control. If you and your clients will be working on their client app and pods simultanously. They'll most likely have to get your pods in a workspace, which defeats the purpose of pods. (If somebody knows a better way around editing pods and project simultanously, please let me know as well.)
Static Library/Frameworks: Rey Wenderlich has a good tutorial for creating frameworks. http://www.raywenderlich.com/65964/create-a-framework-for-ios

Can someone please explain the differences between Cocos2d-Swift, SpriteBuilder, Xcode and CocoaPods?

I'm completely confused and I don't know where to start asking questions. I tried googling, but the terminology is confusing and I'm not sure what either of these things do (except for Xcode). Can someone explain like I'm 5?
I'm on the cocos2d-swift website and after reading the getting started section it says "From this point onwards, using SpriteBuilder is optional.". I don't know what they mean by that.
How do each of these correlate with each other?
Also, how is an API Documentation Browser and Code Snippet Manager useful to an everyday iOS Developer?
cocos2d-swift is a framework that enables you to build things like sprite-based games quickly.
SpriteBuilder is a tool that helps you build your own multilayered sprites (images and animations grouped into a single package -- i.e. Mario, a Goomba, a Fireflower fireball, etc.).
Xcode is a developer environment in which you write your source code, compile, distribute, and test.
CocoaPods is a tool that fetches and manages framework/SDK dependancies.
You would use CocoaPods to fetch the cocos2d-swift framework so that you could build a sprite-based game in Xcode using sprites you generated in SpriteBuilder.
Not sure what Cocos2d is, but swift is the latest programming language by Apple for both OS X and iOS development.
http://en.wikipedia.org/wiki/Swift_(programming_language)
SpriteBuilder is a framework used to create games for iOS very quick. Think of it as a game engine.
http://www.spritebuilder.com/about
Xcode is the IDE (integrated development environment) that you use when writing native OS X and iOS applications. It's awesome!
CocoaPods is a way to load in third-party libraries and frameworks without having to manually install them on your own. It also makes it very easy to keep the frameworks up-to-date. Pods also allows your project to be more portable as it's much easier to install an application with multiple dependancies via Pods.
http://cocoapods.org
A documentation browser is good if you want to have access to documentation while offline. However, I almost always use Google to find what I'm looking for regardless of what technology I'm working on. Google is just the best way to search.
Finally, I'd start off with this book. I read the first edition years ago, and made things very easy for me to understand.
http://www.bignerdranch.com/we-write/ios-programming.html
Hope this helps!
Here are some basics:
XCode (A Program)- Most of your iOS development will happen here. Coding, creating the app etc.
Think of an SDK as a suite of commands or tools you can use-API's (API - Application programming interface)
Cocoas2d (An SDK) - Game engine. A software development kit for creating games. you would pull this library of code and tools into xcode to use it.
SpriteBuilder (An SDK) - Suite of tools for building games. Just like Cocoas, you would pull this into xCode to make use of it as you code.
CocoaPods - A tool for linking/loading SDK's into XCode and easily updating them.
Moral of the story: XCode is the software you will use for everything. Everything else are just additional libraries of code you can pull in.

How to add iOS frameworks to a Unity project?

How can I add stuff like AdSupport.framework to a Unity project?
I don't want to add them (on the Xcode side) every single time I do a build for iOS...
Using Unity 4.6.
Update, related:
http://forum.unity3d.com/threads/ios-plugin-how-to-link-ios-framework.156231/
http://feedback.unity3d.com/suggestions/frameworks-and-plist-on-ios-outp
https://github.com/AdColony/AdColony-Unity-SDK/wiki/Unity-and-Xcode-Project-Setup
http://answers.unity3d.com/questions/222478/how-do-i-automatically-include-a-framework-with-my.html
http://forum.unity3d.com/threads/get-tired-in-dragging-frameworks-and-dependence-in-xcode-try-xuporter.190752/ - https://github.com/onevcat/XUPorter - https://github.com/josh-ruis/XUPorter
Until there is an official way of doing this within the Unity editor, I'll just answer like this:
There is no official way to do this. You have to do this every single time you build an iOS project. Does UT hate iOS?
Or you could check out some 3rd party plugins that try to address the issue. I haven't tried it myself yet but https://github.com/onevcat/XUPorter or one of its forks could do it. It appears 3rd party tools have a hard time keeping up with new Unity and Xcode versions.
Or this: https://github.com/openkit/openkit-unity
Also: Something that would work from day-to-day is to select "Append" at build time instead of replace. That way framework setup is maintained (however splash screens settings seem to be ignored, and possibly other stuff too). It won't work however of you checkout the project on another computer or similar.

Why doesn't Xcode have an ios framework option?

I've seen project such as ios-universal-framework, but I want to know why XCode iOS does not natively support having a framework. Is it some kind of legal issue. The static library option is not good enough because I want to be able to use .dylib files in my framework.
A little background on what I want to do with a framework. I have a project that is generated from Unity3D, and when we update, we have to manually add back all of our project changes.
What I want is to use a framework that can store most of those external libraries and resources to make it easier to upgrade our project when updates are released.
From a security perspective no code is allowed to be dynamically loaded, thus only static libraries are allowed.
It is possible to create static psudo-frameworks. Take a look at GitHub iOS-Universal-Framework.
What you need is a PosprocessBuilder as described in the build pipeline described in the Unity3d Documentation.
You can manage the Xcode configurations in this pipeline using scripts like the Xcode Zerg.
I've used one python script written by a guy called Calvin Rien that worked really well, if you want to know more about this script this blog post should give you a hint.
What you really need to look for to you automate the these steps is to look for posts of Continuous Integration using Unity 3d and iOS like this one:
Unity3d: from commit to deployment onto tester devices in 20 min using Jenkins

Show unity 3D in xcode project

I have a question. Is it possible to load unity project from web, and show it in Xcode project? In some non-fullscreen view? Also, unity must handle touch events. Any ideas, suggestions, links or anything else?
Thanks for advice.
P.S. Sorry for my english.
P.P.S. Main project created in Xcode, without unity.
load unity project from web
What do you mean by that? If you mean a compiled unity webplayer application, forget it.
If you mean a standard non compiled Unity project, note that with the iOS plugin you can compile for mobile Apple hardware. This used to cost a lot of money but now they're giving it out for free (included in Unity free).
Also, unity must handle touch events.
The standard Input Unity class handles touch events with methods such as GetTouch() and variables like touchCount or touches.
Unity is a very big and complex package: integrating it into an existing project may be overwhelmingly difficult. I really don't think there are natives way to do so.
Rather, I'd advise you to port your current XCode project into Unity (which sounds a really strange thing to do if you ask me).
Unity and XCode are 2 completely different tools: the former is useful for Cocoa classes and iOS IDE while the latter is for managing 3d game assets in a real-time interactive environment. I don't see how you can possibly integrate the two things.
Manage your project in a single IDE, it will make things a lot simpler.

Resources