CocoaPods Works for Swift

Use CocoaPods for Packages Management in Xcode

UPDATE 20150104 - CocoaPods Is Ready for Swift:

新的swift分支终于可以使用了,虽然没有正式集成,还是拿来先测试了下。

提交记录:https://github.com/CocoaPods/CocoaPods/pull/2835

Gemfile:

1
2
3
4
5
6
source 'https://rubygems.org'
gem 'cocoapods', :git => 'https://github.com/CocoaPods/CocoaPods.git', :branch => 'swift'
gem 'cocoapods-core', :git => 'https://github.com/CocoaPods/Core.git', :branch => 'swift'
gem 'xcodeproj', :git => "https://github.com/CocoaPods/Xcodeproj.git", :branch => 'master'
gem 'claide', :git => 'https://github.com/CocoaPods/CLAide.git'

Podfile:

1
2
3
4
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git'
1
2
bundle install
bundle exec pod install

TestFile.swift

1
2
3
4
5
6
7
8
9
10
11
12
import Foundation
import SwiftyJSON
class TestFile {
class func addNumbers(a: Int, b: Int) -> Int {
return a + b;
}
class func addToJSON(name: String, age:Int) -> JSON {
let json:JSON = ["name": name, "age": age]
return json
}
}

编译方式从之前的静态链接库 .a 变为了动态链接库.framework,每一个Pod都会有一个Target,生成一个framework文件,最后汇总为libPods.framework

REF::