m_shige1979のときどきITブログ

プログラムの勉強をしながら学習したことや経験したことをぼそぼそと書いていきます

Github(変なおっさんの顔でるので気をつけてね)

https://github.com/mshige1979

swiftでCocoaPodsのライブラリを使用する

Objective-Cのライブラリは多いけどswiftのライブラリは少ないのでObjective-Cのものを流用しましょう

ということらしい

gem

cocoapodsをインストール
gem install cocoapods --pre

$ pod
Usage:

    $ pod COMMAND

      CocoaPods, the Objective-C library package manager.

Commands:

    + init                Generate a Podfile for the current directory.
    + install             Install project dependencies to Podfile.lock versions
    + ipc                 Inter-process communication
    + lib                 Develop pods
    + list                List pods
    + outdated            Show outdated project dependencies
    + plugins             Show available CocoaPods plugins
    + repo                Manage spec-repositories
    + search              Searches for pods
    + setup               Setup the CocoaPods environment
    + spec                Manage pod specs
    + trunk               Interact with the CocoaPods API (e.g. publishing new specs)
    + try                 Try a Pod!
    + update              Update outdated project dependencies and create new
                          Podfile.lock

Options:

    --silent              Show nothing
    --completion-script   Print the auto-completion script
    --version             Show the version of the tool
    --verbose             Show more debugging information
    --no-ansi             Show output without ANSI codes
    --help                Show help banner of specified command
$

Podfileを作成

Podfile
pod 'SVProgressHUD'
構成
Podfile
swiftSample24
swiftSample24.xcodeproj
swiftSample24Tests
インストール
pod setup
pod install

Analyzing dependencies

CocoaPods 0.36.0.beta.1 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.

Downloading dependencies
Installing SVProgressHUD (1.1.2)
Generating Pods project
Integrating client project

[!] From now on use `swiftSample24.xcworkspace`.

※xcworkspace?

f:id:m_shige1979:20150118022211p:plain

Bridging-Header追加

CocoaClassを追加

f:id:m_shige1979:20150118020413p:plain
f:id:m_shige1979:20150118020530p:plain
f:id:m_shige1979:20150118020451p:plain

swiftSample24-Bridging-Header.hを編集
#import <SVProgressHUD.h>

viewファイル修正

view
import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func btn_push(sender: AnyObject) {
        SVProgressHUD.showWithStatus("loading...")
    }

}

結果

f:id:m_shige1979:20150118022431p:plain
f:id:m_shige1979:20150118022452p:plain

所感

ライブラリを使用することである程度の開発コストが減るのでネットで調べて安心そうなものは積極的に使用するようにする
わからないことが多くて調べるのが大変。
作りたいものが複雑になるにつれて混乱していく…