Install C4
Pick your weapon of choice and start kung-fu'ing some code.
There are a few ways to install C4:
Jackie Chan
The easiest way to create new projects is to install C4 directly into Xcode. I highly recommend this approach because it makes it extremely easy to quickly create new projects and test out your ideas.
- Download the installer
- Double-click the .pkg to open it up
- Follow the instructions to install
- Open Xcode
At this point, you’ll see a dialog that looks like this:
- Select “Create New Xcode Project
- Give your project a name
- Choose the device to build for
- Save the project somewhere
- When your project opens, choose the
WorkSpace.swift
file - Hit
Run
That’s it! You’ve created a new C4 project.
Pros
Like I mentioned above, I personally think this is the easiest way to test C4 projects. You can quickly create new projects, all the test media are included, and its an easy setup for copying and pasting any example code from our site straight into the WorkSpace
. Furthermore, the code that installs is static so it should always work out of the box.
Cons
The only significant drawback is that this installs a static copy of C4’s code base in every project you create. If there are updates to the core C4 project on Github this installer won’t update automagically. You’ll have to wait until we create a new installer build.
JCVD
The next level of mastery is to use Cocoa Pods. You’ll have to do a few things to get this running:
Install cocoa pods
- Create a new Xcode project (iOS: Single-View application)
- Close the Xcode project
- Open Terminal and navigate to the top level folder of your project. For example, you could write:
cd /Users/Mac/Desktop/C4CocoaPod
- Then, create a pod file by entering:
touch Podfile .
- Then, open the folder with the pod file:
open .
- Then add the following to the pod file:
This is a little instruction that tells cocoa pods where to install things.
Remember to change the TitleOfYourProject
. I used C4CocoaPod
as the title of mine.
- Back in Terminal, in the same directory, type:
pod install
This is what my terminal output looks like at this point:
Now, we need to update the Xcode project so that it works with the pod’ed thing.
- Open the
.xcworkspace
project - Open ViewController and change its contents to look like this:
1
2
3
4
5
6
7
8
import UIKit
import C4
class ViewController: CanvasController {
override func setup() {
canvas.backgroundColor = C4Blue
}
}
- 3. Run it.
Done.
Pros
Installing this way takes a bit more effort, but it guarantees that you always have the latest version of C4 that has been updated into the CocoaPod. Say, for instance, you make a project and then come back to it a couple weeks later (after we’ve updated) you can run pod update
and it will bring everything up to speed.
Cons
You have to work with .xcworkspaces
, which isn’t much of a problem. You might have some issues compiling the first time, but after getting things running a couple of times you’ll learn how to get past this. But, the main thing for me is that you’ll have to convert a normal Xcode project to use C4 every time… Which is slower than just creating a new project from a template.
The Guy From Ong Bak
Carthage… The brutal, light, efficient weapon of choice for many developers. Carthage installs the bare minimum you need and, unlike Cocoapods, doesn’t create a workspace that has everything set up for you.
This is how Alejandro teaches us to install via Carthage:
- Install Carthage
- Create Cartfile and in it paste github
"C4Labs/C4iOS" ~> 1.1.0
- Run
carthage update
- In your project reference the framework in Carthage/Build/iOS/C4.framework
Installing C4 this way is like the trophy at the top of the tree in Ong Bak… Good luck.
Pros
Super light installer of the necessary C4 framework components.
Cons
More painful terminal experience. You have to do all the linking to the installed C4 framework yourself, from Xcode.
Jet Li
Github for Mac. We host C4 on Github, so downloading their desktop application is one of the easiest ways of managing your projects. Through this tool you’ll be able to clone the C4 project onto your comp.
- Download Github for Mac
- Click the Clone in Desktop link
- Open Xcode
- Create new Single-View application
- Right-click on
ViewController.swift
- Choose “Add files to “New”…”
- Navigate to your recently downloaded
C4iOS.xcodeproj
and choose it.
- Embed the linked framework into your Xcode. In
General > Embedded Binaries
click the+
and addC4.framework
- Update the
ViewController
so it is aCanvasController
… There will probably be a warning. - Build the framework (for the simulator)
- In
setup()
change the background color to blue. - Run the app (for the simulator)
Pros
This way you’ll have a single copy of C4 on your computer, and through the Github app, you’ll be able to update that project at any time to keep it current. You’ll also be able to test any of the branches for the project. You’ll also be able to import the same project into ANY of the new Xcode projects you create. So, this approach gives you a nice way of keeping everything current, around a central project.
Cons
Takes much longer to set up a project. There are some git tricks that you cannot do with the Github app… It’s pretty decent, but there are some advanced techniques that I always have to fall back on Terminal to accomplish.
Bruce Lee
The martial arts master of keeping things up to date. Use Git, do everything from Terminal, fork, push, pull, rebase, etc. This one you’ll have to figure out on your own (for now).
Bwooooyaaaeeeaannnnn.
Pros
Ultimate control.
Cons
Ultimate control.