wiedii's memo

色々メモリます。

CocoaPodsでld: library not found for -lPods clang: error: linker command failed with exit code 1 (use -v to see invocation)のようなエラーが出て困った。

「.xcodeproj」ではなく「.xcworkspace」を使います。

たのしいCocoaプログラミング[Leopard対応版]

たのしいCocoaプログラミング[Leopard対応版]

CocoaPods便利ですね。
CocoaPods: The Objective-C Library Manager

iOS(とMacOSX)で使うフレームワークを管理してくれるシステムです。
「かっこいいくるくる回るローディング画面作りたいな…SVProgressHUDってのがあるのか…ダウンロード…解凍…プロジェクトにドラッグアンドドロップ…」
「JSON処理しなきゃ…JSONKitが便利そうだ…ダウンロード…解凍…ドラッグアンド…」
CocoaPodsを使えばそういう部分を綺麗に管理できるようになります。

インストール

$ [sudo] gem install cocoapods
$ pod setup

今回は試しにSVProgressHUDをCocoaPodsを使って管理してみます。
SVProgressHUDは本当に便利です。
[SVProgressHUD show]
[SVProgressHUD dismiss]
この2つだけで簡単にインジケーター(であってるかな)が使えちゃいます。

CocoaPodsSampleというプロジェクトを、Empty Applicationテンプレートを使って作ります。
そんでもってTitleViewControllerというUIViewControllerのサブクラスを追加して、ひとまずXcodeを閉じます。

そしてTerminal.appを開いてプロジェクトファイルがあるディレクトリに移動します(CocoaPodsSample.xcodeprojがあるディレクトリ)。

$ cd (CocoaPodsSample.xcodeprojがあるディレクトリ)

そのディレクトリにPodfileというファイルを追加します。今回はemacsを使って作成します。

$ emacs Podfile

下記のような内容を入力して、Ctrl+x, Ctrl+s, Ctrl+x, Ctrl+cと入力します(Ctrl+はコントロールを押しながら)。

platform:ios
pod 'SVProgressHUD', '~>0.9'

そしてTerminalに戻ったら以下のコマンドでインストールを開始します。

$ pod install
pod install
Analyzing dependencies
Downloading dependencies
Installing SVProgressHUD (0.9)
Generating Pods project
Integrating client project
$

このあと何ですが、
「さてCocoaPodsSample.xcodeprojを開いて作業を続行するか…」は間違いでした。
新しいViewController作って、SVProgressHUD.hをimportしていざビルドしようとすると、
「ld: library not found for -lPods clang: error: linker command failed with exit code 1 (use -v to see invocation)」
のようなエラーが出ます。

ちょっと困りましたが、調べてみたら

$ pod install

というコマンドを打つと、自動で「(プロジェクト名).xcworkspace」というファイルが作られ、そのファイルを開いて作業をするようです:)

AppDelegate.m

#import "AppDelegate.h"
#import "TitleViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    TitleViewController *title = [[TitleViewController alloc] init];
    self.window.rootViewController = title;
    
    [self.window makeKeyAndVisible];
    return YES;
}
@end

TitleViewController.m

#import "TitleViewController.h"

@interface TitleViewController ()

@end

@implementation TitleViewController

-(id)init{
    if(self = [super init]){
        CGRect btn_rect = CGRectMake(0, 0, 100, 50);
        UIButton *hud_show = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [hud_show setBounds:btn_rect];
        [hud_show setTitle:@"HUD SHOW" forState:UIControlStateNormal];
        [hud_show setCenter:CGPointMake(100, 100)];
        
        UIButton *hud_dismiss = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [hud_dismiss setBounds:btn_rect];
        [hud_dismiss setTitle:@"HUD DISMISS" forState:UIControlStateNormal];
        [hud_dismiss setCenter:CGPointMake(200, 200)];
        
        [hud_show addTarget:self action:@selector(hudShow) forControlEvents:UIControlEventTouchUpInside];
        [hud_dismiss addTarget:self action:@selector(hudDismiss) forControlEvents:UIControlEventTouchUpInside];
        
        [self.view addSubview:hud_show];
        [self.view addSubview:hud_dismiss];
    }
    return self;
}

-(void)hudShow{
    [SVProgressHUD show];
}
-(void)hudDismiss{
    [SVProgressHUD dismiss];
}
@end

f:id:wiedii:20131102031816p:plain
:)

フレームワークの検索

$ pod search GPU


-> GPUImage (0.1.1)
   An open source iOS framework for GPU-based image and video processing.
   pod 'GPUImage', '~> 0.1.1'
   - Homepage: https://github.com/BradLarson/GPUImage
   - Source:   https://github.com/BradLarson/GPUImage.git
   - Versions: 0.1.1, 0.1.0, 0.0.1 [master repo]


-> GPUImage@siuying (0.0.2)
   Versioned fork of GPUImage.
   pod 'GPUImage@siuying', '~> 0.0.2'
   - Homepage: https://github.com/BradLarson/GPUImage
   - Source:   https://github.com/siuying/GPUImage.git
   - Versions: 0.0.2, 0.0.1 [master repo]


-> RDGPUImage (0.1.1)
   Versioned fork of GPUImage
   pod 'RDGPUImage', '~> 0.1.1'
   - Homepage: https://github.com/BradLarson/GPUImage
   - Source:   https://github.com/reigndesign/GPUImage.git
   - Versions: 0.1.1, 0.1.0 [master repo]


-> ZGPullDragScrollView (0.0.3)
   Awesome Scroll Category for DragUp and PullDown.
   pod 'ZGPullDragScrollView', '~> 0.0.3'
   - Homepage: https://github.com/zhigang1992/ZGPullDragScrollView
   - Source:   https://github.com/zhigang1992/ZGPullDragScrollView.git
   - Versions: 0.0.3, 0.0.2, 0.0.1 [master repo]


-> ZGPullDragTableView (0.0.1)
   Awesome TableView Category for Drag and Pull.
   pod 'ZGPullDragTableView', '~> 0.0.1'
   - Homepage: https://github.com/zhigang1992/ZGPullDragTableView
   - Source:   https://github.com/zhigang1992/ZGPullDragTableView.git
   - Versions: 0.0.1 [master repo]
$

CocoaPodsで追加したライブラリの削除方法は、Podfileで削除したいライブラリの記述を削除して、

$pod install

で出来ます。

森永 ミルクココア 300g

森永 ミルクココア 300g

ハートキャッチプリキュア! ココロポット

ハートキャッチプリキュア! ココロポット