2016-09-30 40 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

相关问题