繁体   English   中英

swift build errors from Objective-C app due to import of Objective-C static library that contains a.swift file

[英]swift build errors from Objective-C app due to import of Objective-C static library that contains a .swift file

我正在将 ObjC static 库导入到我的 ObjC 应用程序中,但出现 95 个与 swift 相关的构建错误。
ObjC static 库构建正常并包含.mh 和.swift 源文件。
Swift 文件导入 CoreBluetooth。

以下内容...

  1. 构建错误
  2. 源代码文本
  3. 项目的 zip,应 Asperi 的友好请求
    更新 2
    更新 3

..1。 这里 Xcode 构建错误加上必要的源代码......

在此处输入图像描述

..2。 源代码文本

//  OBJC APP 
//  ViewController.h
//  sim_backend_UI
//
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

#import "Mobile_Sensor_API.h"

@interface ViewController : UIViewController

@end





//  OBJC APP
//  ViewController.m
//  sim_backend_UI
//
//

#import "ViewController.h"

@interface ViewController ()
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    Mobile_Sensor_API* mobile_sensor_API;

    if( !mobile_sensor_API ) mobile_sensor_API = [[ Mobile_Sensor_API alloc] init];

    // Tell Mobile_Sensor_API library to start BLE central scanning:
    [ mobile_sensor_API   _init_and_test ];
}
@end





//  OBJC STATIC LIB with some Swift
//  mobile_sensor_API.h

#import <Foundation/Foundation.h>


@interface Mobile_Sensor_API : NSObject
    -(int)_init_and_test;
@end









//  OBJC STATIC LIB with some Swift
//  mobile_sensor_API.m
//
//

// ObjC...
#import <UIKit/UIKit.h>
#import <CoreBluetooth/CoreBluetooth.h>

// app...
#import "mobile_sensor_API.h"
#import "mobile_sensor_API-Swift.h"

    //#define BUILD_SIM_MOBILE_HUB              ' builds sim mobile_hub
@interface Mobile_Sensor_API()
    @property BLE_Central*   BLE_central_instance;
@end

@implementation Mobile_Sensor_API
 

// Init Maestro lib at boot time and test interface with backend:
-(int)_init_and_test
{
    // Init access to Swift:

    _BLE_central_instance = [[ BLE_Central alloc] init];
    // Start BLE:
    [ _BLE_central_instance   start_central ];

    return 1;
}
@end





/*
//  OBJC STATIC LIB with some Swift

    Abstract:
    A class to discover, connect, receive notifications and write data to sensor peripherals by using a
    transfer service and characteristic.
*/

//import Foundation

import UIKit
import CoreBluetooth
import os

var centralManager: CBCentralManager = CBCentralManager()


@objc open class BLE_Central
: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate
{
    var discoveredPeripheral: CBPeripheral?
    var transferCharacteristic: CBCharacteristic?
    var writeIterationsComplete = 0
    var connectionIterationsComplete = 0

    let defaultIterations = 5     // change this value based on test usecase

    var data = Data()

    
    @objc public func start_central()
    {
        os_log("Central_class: start_central")
        mobile_sensor_API.centralManager = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionShowPowerAlertKey: true])
        os_log("Scanning started")
    }

. . .   

更新 1——2020 年 12 月 5 日...

  1. zip 项目项目:sim_backend_UI & mobile_sensor_API

我从 mac OS 压缩了两个项目 sim_backend_UI 和 mobile_sensor_API。

您需要使用您的... TARGETS > Signing > Team and TARGETS > Build Settings > All > Packaging > Product Bundle Identifier 设置项目

..因为我从他们那里删除了我们的公司。

更新 2——十二月。 6 已删除

更新 3——十二月。 7 回答了 1

我从 Asperi 获得答案 1 的步骤...

1.  Created workspace at top folder
1.1 Copied clean app and lib to top folder
2.  Add mobile_sensor_API.xcodeproj to workspace
3.  Add sim_backend_UI.xcodeproj to workspace
4.  Added dependency of sim_backend_UI to lib via workspace
a.  sim_backend_UI proj > General tab > Frameworks, Libs.. > +
b.  Select libmobile_sensor_API.a
c.  Add.


5.  Add Some.swift (any swift file you want) to sim_backend_UI, just for the purpose Xcode add required system swift dynamic libraries (which will be needed for swift part in static library as well)... and confirm creating bridge in appeared dialog
a.  new file > Swift > Some.swift
b.  Create Bridging Header
c.  Added to Some.swift ...

import Foundation

struct Some{}

d。 将 mobile_sensor_API.h 拖入 app proj nav e。 将 Xcode “活动方案”设置为应用项目和设备

6.  Build 
 I got "succeeded" and it runs on iphone.

最简单的解决方案是允许 Xcode 创建所有依赖项并包含所有必需的系统库。

这是我所做的:

  1. 在顶级文件夹级别创建工作区

  2. 将 mobile_sensor_API.xcodeproj 添加到工作区

  3. 将 sim_backend_UI.xcodeproj 添加到工作区

  4. 通过工作区将 sim_backend_UI 的依赖项添加到 lib

演示

  1. Add Some.swift (any swift file you want) to sim_backend_UI, just for the purpose Xcode add required system swift dynamic libraries (which will be needed for swift part in static library as well)... and confirm creating bridge in appeared dialog

演示2

  1. 构建 >>> 成功!

更新 3 .....................在我通过第 6 步完成此答案后,我得到了“成功”但 sim_backend_UI.app 是 RED 并且不会在 iphone 上运行。

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM