【问题标题】:Swift framework into Objective-C device and simulator architecturesSwift 框架融入 Objective-C 设备和模拟器架构
【发布时间】:2016-09-30 05:16:55
【问题描述】:

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

的动态框架

我能够成功地将 TestFramework 框架导入到我的 Objective-C 应用程序中。但是,它只能为设备架构或模拟器架构构建。

如何设置它,以便我可以使用这个适用于任何架构的 swift 框架运行我的 Objective-C 应用程序?

现在,我通过从应用程序中删除框架、重建 .framework 文件(选择设备或模拟器)然后将该框架重新部署到应用程序项目中来实现任一架构。这样做很烦人,因为我希望能够在任何项目(模拟器或设备)中使用这个框架。

我可以使用 CocoaPods,但我还没有设置。

在框架中,我有一个名为:“Testing”的类(参见问题下方的方法)。我可以在我的 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)

这是我的配置和一些代码的屏幕截图:

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

【问题讨论】:

    标签: objective-c swift frameworks cocoapods swift3


    【解决方案1】:

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

    【讨论】:

    • 这为我指明了正确的方向,并使用聚合目标解决了我的问题。不过,我还没有将框架提交到应用商店,也没有将包含此框架的应用提交到应用商店。希望这也能像这些答案中解释的那样工作。谢谢!
    猜你喜欢
    • 2017-03-23
    • 1970-01-01
    • 1970-01-01
    • 2022-10-22
    • 1970-01-01
    • 2016-04-05
    • 1970-01-01
    • 2017-01-27
    • 2018-07-01
    相关资源
    最近更新 更多