153
151

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SwiftでObjective-CのFrameworkを読み込む方法

Posted at

Objective-Cで作成されたFrameworkを読み込み、Swiftで呼び出す。
サンプルとしてGameFeatSDKを使用。

(1)Bridging-Header.hを作成

Objctive-CのFrameworkをimportするため
「GameFeatKit-Bridging-Header.h」
というヘッダーファイルを作成する。
※「GameFeatKit」の部分は任意で変更可能。

(2)Bridging-Header.hを編集

GameFeatKit-Bridging-Header.h
#import <GameFeatKit/GFController.h>

(3)Bridging-Header.hを読み込む

[Build Settings]の[Objective-C Bridging Header]に
GameFeatKit-Bridging-Header.h
を指定する

$(SRCROOT)/$(PROJECT)/GameFeatKit-Bridging-Header.h

スクリーンショット 2014-06-08 17.47.51.png

=====

■呼び出し方法

@Obj-C
[GFController activateGF:@"メディアID" useCustom:YES useIcon:YES usePopup:YES];

@Swift
GFController.activateGF("メディアID", useCustom: true, useIcon: true, usePopup: true);

このような形で呼び出すことができる。

Delegateに関しても同様に

@Obj-C
@interface UITestViewController : UIViewController <GFViewDelegate> {

@Swift
class UITestViewController: UIViewController, GFViewDelegate {

@Obj-C
`- (void)didShowGameFeat{
 NSLog(@"didShowGameFeat");
}

  • (void)didCloseGameFeat{
     NSLog(@"didCloseGameFeat");
    }
  • (void)didGetGfAds:(NSArray *)lists {
     NSLog(@"didGetGfAds");
     NSLog(@"%@", lists);
    }
  • (void)failGetGfAds {
     NSLog(@"failGetGfAds");
    }`

@Swift
func didShowGameFeat(){  println("didShowGameFeat"); } func didCloseGameFeat(){  println("didCloseGameFeat"); } func didGetGfAds(lists:NSArray){  for v:NSDictionary! in lists as AnyObject[]{   let app:String = v.objectForKey("app") as String;   let strTitle:String = v.objectForKey("title") as String;   let strUrl:String = v.objectForKey("url") as String;   println("\(app) : \(strTitle) \(strUrl)");  } } func failGetGfAds(){  println("failGetGfAds"); }

と指定する。

153
151
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
153
151

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?