【发布时间】: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