2016-09-30 46 views
3

gotta 很奇怪問題在這裏。我構建了一個名爲:TestFrameworkSwift框架到Objective-C設備和模擬器體系結構中

我能夠將TestFramework框架成功導入到Objective-C應用程序中。但是,它只能針對器件架構或仿真器架構進行構建。

如何設置它,以便我可以使用此Swift框架爲任何體系結構運行我的Objective-C應用程序?

現在,我通過從應用程序中刪除框架,重建.framework文件(選擇設備或模擬器),然後將此框架重新部署到應用程序項目中,實現任一架構。這樣做很麻煩,因爲我希望能夠在任何項目(模擬器或設備)中使用此框架。

我可以使用CocoaPods但我還沒有設置它。

在框架中,我有一個類叫做「測試」(請參閱​​下面的問題)。我可以在我的objective-c應用程序中訪問這個類。實例化一個「測試」對象,將其稱爲公共函數或其他。代碼編譯!但是,當我嘗試構建該框架未編譯的體系結構時,我得到一個錯誤錯誤:

ld: warning: ignoring file /Users/kersan/projects/TestApp2/TestApp2/TestFramework.framework/TestFramework, missing required architecture x86_64 in file /Users/kersan/projects/TestApp2/TestApp2/TestFramework.framework/TestFramework (2 slices) 
Undefined symbols for architecture x86_64: 
    "_OBJC_CLASS_$__TtC13TestFramework7Testing", referenced from: 
     objc-class-ref in ViewController.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

這裏是我的configs的截圖和一些代碼: enter image description here enter image description here enter image description here enter image description here

TestFramework.h:

#import <UIKit/UIKit.h> 

//! Project version number for TestFramework. 
FOUNDATION_EXPORT double TestFrameworkVersionNumber; 

//! Project version string for TestFramework. 
FOUNDATION_EXPORT const unsigned char TestFrameworkVersionString[]; 

// In this header, you should import all the public headers of your framework using statements like #import <TestFramework/PublicHeader.h> 

Testing.swift:

// 
// Testing.swift 
// TestFramework 
// 
// Created by Kaan Ersan on 2016-09-29. 
// Copyright © 2016 Kaan Ersan. All rights reserved. 
// 

import Foundation 


@objc open class Testing : NSObject { 

    open var testDescription : String? 


    open func printDesc() -> String { 
     print("testDescription: \(testDescription)") 
     return "Testing class -> Hello World" 
    } 

} 

的ViewController在我的Objective-C的應用:

// 
// ViewController.m 
// TestApp2 
// 
// Created by Kaan Ersan on 2016-09-29. 
// Copyright © 2016 Kaan Ersan. All rights reserved. 
// 

#import "ViewController.h" 
#import "TestFramework/TestFramework-Swift.h" 

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    Testing *testing = [[Testing alloc] init]; 
    [testing printDesc]; 

    [_label setText:testing.printDesc]; 

    // Do any additional setup after loading the view, typically from a nib. 
} 


- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 


@end 

回答

0

當我看到 - 你爲構建iOS設備框架,但似乎碰撞模擬器上運行的嘗試項目時出現。模擬器具有與設備不同的體系結構。因爲我的崩潰是因爲你的框架不包含模擬器架構的符號(x86_64)。所以你只需要將這個架構添加到你的框架中。如何做到這一點很好解釋here

+0

這指出我在正確的方向,並使用聚合目標解決了我的問題。儘管如此,我還沒有將該框架提交給appstore或具有此框架的應用程序。希望這個解決方案也能在這些答案中解釋。謝謝! – c0d3Junk13

相關問題