Swift框架分为Objective-C设备和模拟器架构

时间:2016-09-30 05:16:55

标签: objective-c swift frameworks cocoapods swift3

这里有奇怪的问题。我构建了一个名为: TestFramework

的动态框架

我能够成功地将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)

以下是我的配置和一些代码的屏幕截图: 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"
    }

}

我的Objective-C应用程序中的ViewController:

//
//  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

1 个答案:

答案 0 :(得分:0)

正如我所见 - 你为ios设备构建框架但是在Simulator上尝试运行项目时似乎出现了崩溃。模拟器具有与设备不同的架构。因为我的崩溃是因为你的框架不包含模拟器架构的符号(x86_64)。所以你只需要将这个架构添加到你的框架中。如何做到这一点好解释here