How to use Cocos2d-Swift in existing project - ios

I got an existing Objective-C project. Now I decided to rewrite some code and add Cocos2d to it. I know this framework for a long time and I recently discovered that they stopped the support for Cocos2d and created a new version called Cocos2d-x. There I found the Swift library and I asked me how to use the Cocos2d-Swift framework in my existing Objective-C project ? A step by step tutorial would be great. I searched a bit in the internet and found this:
Stackoverflow Link
But since the post is from 2011 it does not cover how to add the swift library, since Swift wasn't introduced at this moment.

Cocos2d-swift is a bit of a misnomer : it is currently written in objective-c. The software is now distributed with SpriteBuilder, that is why there is no 'install.sh' as there used to be. So integrating it into your project should not be too difficult. Use SpriteBuilder (from the AppStore) to create a 'blank' SB project, and see how cocos2d is integrated in there. Then, what you see is what you integrate !
caveat : Cocos2d is now ARC, so it is best your project defaults ARC. Otherwise you will have to do a lot of Xcode click-click-click to make the reference count strategy file specific.

Related

Where can I find new Cocoa Touch Framework project in XCode?

I'm following a tutorial to learn to make a cocoapod. Unfortunately the tutorial instructs to create a "Cocoa Touch Framework" when that no longer exists in current XCode.
What's the current equivalent, that I can use for the purposes of this tutorial / to make a cocoapod?
The answer isn't too complicated: it's the "Framework" option.
A Static Library is pure object code (a.k.a. compiled code), and it cannot contain images, storyboards, etc. Pure object code also means you can't read the code files which makes it pretty much un-debuggable.
A Metal Library lets you develop using the Metal library, basically for 3D graphics and GPU stuff.
Framework is a cocoapod framework. Tried and tested and loved by all Apple Developers.

Does Swift support WebRTC?

Our team is in process of electing programming language to develop a new iOS application in which we have to write features to support video conversation.
The backend is written using WebRTC, now we have to decide which language to use in the iPhone app and we prefer Swift in this case.
However, I'm not sure Swift supports WebRTC or not.
My initial research show that we can implement the features using Objective-C. I found an example written in Objective-C which you can find the source code here.
However, I'm not sure about Swift. Does Swift also support WebRTC?
UPDATE 2023
Unfortunately, as of 2023 there still appears to be no completely Swift framework that implements the WebRTC protocol. Although the iOS framework hosted at webrtc.org can be fairly easily used in Swift apps, it is written mostly in objective C.
For those stumbling on this question, who just want to get webRTC running in your app this is still relatively easy using the cocoapod
UPDATE 2016
The easiest way is to get webRTC in your project is to simply install the CocoaPod using the directions at https://cocoapods.org/pods/WebRTC
If you have never used CocoaPods before you will need to first follow this guide: https://guides.cocoapods.org/using/getting-started.html
Original Answer
The simple answer to the question is that there are currently no open source libraries written in Swift conforming to the WebRTC protocol. You can still compile the code from the official WebRTC project into your app. Directions which may not lead to a successful build can be found here: https://webrtc.org/native-code/ios/
Finally, to clarify Omkar Guhilot's answer: Skylink is a company with a closed source SDK that is designed to work only with their paid stun-turn service, and https://github.com/alongubkin/phonertc requires cordova, which may not be ideal for many native ios developers.
Webrtc comes with Objective C interface. I dont think they will move to swift interface anytime soon. But You can always use them via bridging headers. I have written apprtc (webrtc's demo) in swift 2.3 version with help of bridging headers in github link with a description in this blog . I have planned to write 3.0 version and a swift wrappers over it.
Current version of webrtc framework doesn't require any pods or any extra bridging headers.
The framework can be generated by following instructions on this Link :
https://webrtc.github.io/webrtc-org/native-code/ios/
If you follow them correctly you will generate a framework add that framework in your project and follow the webrtc necessary steps and you will have a WEBRTC integrated project.
To know what all steps are necessary follow this link from appear.in
:
https://tech.appear.in/2015/05/25/Getting-started-with-WebRTC-on-iOS/
This will get you to a stage where you will be able to make calls between a browser and any iOS 8+ device
Yes swift supports WebRTC and there is one more library which you can use in swift link:- http://skylink.io/ios/
And the link that you have shared to which is written in Objective C, we should be able to use that as well in swift by creating a Bridging header
Have a look at this as well https://github.com/alongubkin/phonertc
Thanks
Omkar

Integrate Swift into an exported Unity project instead of using Objective C?

I am currently starting an iOS project and I want to use Unity as the primary drive for the project. Currently when you export Unity as an exported project, I am only given Objective-C.
How do I make a Unity based project using primarily Swift?
This seems extremely complicated as Objective-C can develop in top level and most of Unity is involved with the top level, how can I use Swift in this project? I am planning on using most of the Unity in Objective C and most of the front end GUI on Swift.
After a good couple of days hammering at this, it is possible. The main pitfalls was of course how the linking and the compilation process that Objective-C and Swift have to interact in order to do so:
Create an AppDelegate in Swift, subclassing UnityAppController and utilizing startUnity instead of Application(..)
Bridge between Swift and ObjectiveC using Unity's generated main.mm and the bridging headers
Create an Objective-C wrapper whose sole responsibility is to communicate between the Swift project and the Unity project
As follows here: https://apollowprogrammingblog.wordpress.com/2015/08/17/how-the-heck-do-you-integrate-swift-and-unity/
UPDATE July 11th 2016: There is also another guide, which I have since started using for my app development moving forward: https://github.com/blitzagency/ios-unity5. This is a different approach and also largely more maintainable due to the easily configurable unity.xcconfig (To get through most of the project config headaches) strat used here

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.

Transitioning a project from Cocos2d v1.x to v2.x and then to ARC

I might sound lazy but I am slightly confused on how to proceed on this subject. I have followed this guide which is very well done.
My goal is to convert the Cocos2d v1.x game project to Cocos2d v2.x and then refactor the project code to ARC.
To get started I created an empty HelloWorld Cocos2d v2.x project and created the v2.x static library (as from Steffen's guide). I then rafactored the code to ARC and the HelloWorld worked smoothly.
The issue is when I try to add to the same project the classes I had already written that don't complain to ARC (assuming that there will be not many Cocos2d v2.x vs v1.x problems - e.g. use of deprecated methods and classes like TouchJSON - my project doesn't at least as far I can see). So, I added a couple of Game classes that don't depend from the rest of the game (to reduce the number of potential Cocos2d v2. Vs v1 issues) to the project to see if the ARC covnersion worked for those as a proof of concept. After adding them I choosed: EDIT->Refactor option from XCode.
But now the compiler gives me some ARC warning messages like "ARC forbids explicit message send of autorelease" in the following method:
return [[[self alloc] init] autorelease];
Or similar problems with the dealloc method already written.
I was assuming that EDIT->Refactor would have changed the added code but it appears to work only once. Any hint on this? should I add all my code to the new project template before refactoring the code?
EDIT:To verify whether it was an XCode bug I created an empty iOS project with no Cocos2d libraries and then converted it to ARC. Then created a new empty sublcass of NSObject and added a dealloc method and run the conversion again, it did work! So I might have not followed correctly some of the steps to create and link to the static library..
In addition to this there are some other small issues (not XCode related, but Cocos2d v2.x related), like the fact that the CDXPropertyModifierAction is not automatically included to the CocosDenshion folder and I had to add it to the project after creating the static library (when I noticed the issue).. but I guess this is more template creation related.
Thanks for reading!
so, yeah, I can confirm that the solution in the comment did work. As usual with some IT things is was just about playing around a bit with the various options and see if it works changing the prospective (its not a bug but is me being stupid or lazy).
What worked for me was to use the EDIT->Refactor from the XCode menu and de-select the files created in the first instance by the Cocos2d 2.x template that I had converted after creating the static library (e.g. main.m and AppDelegate.m) (ask if this is unclear).
This converted smoothly all my newly converted Cocos2d 2.x classes into ARC complaint classes and yeah, I have my project fully supporting both Cocos2d 2.x and ARC :).
Please find below the screenshot of the files I deselected to get it working:

Resources