1

I'm importing an ObjC static lib into my ObjC app but get 95 swift-related build errors.
The ObjC static lib builds ok and contains .m .h and .swift source files.
Swift file imports CoreBluetooth.

CONTENTS BELOW...

  1. build errors
  2. source code text
  3. zip of project, in response to kind request from Asperi
    UPDATE 2
    UPDATE 3

..1. Here Xcode build errors plus essential source code....................

enter image description here

..2. source code text

//  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")
    }

. . .   

UPDATE 1 -- DEC 5, 2020...

  1. zip of project projects: sim_backend_UI & mobile_sensor_API

I zipped both projects sim_backend_UI & mobile_sensor_API from mac OS.

You will need to set projects with your... TARGETS > Signing > Team and TARGETS > Build Settings > All > Packaging > Product Bundle Identifier

..because I delete our company from them.

UPDATE 2 -- DEC. 6 deleted

UPDATE 3 -- DEC. 7 DID ANSWER 1

MY STEPS FOR ANSWER 1 from Asperi...

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. drag mobile_sensor_API.h into app proj nav e. Set Xcode "active scheme" to app project and device

6.  Build 
 I got "succeeded" and it runs on iphone.
Doug Null
  • 7,989
  • 15
  • 69
  • 148
  • I assume this is not a code, but project settings issue. Would you give access to project somehow? – Asperi Dec 05 '20 at 05:54
  • Asperi: I just added access to project. Download project from this link: https://drive.google.com/file/d/1tefgnZf0b5ulpwI2lMb9ly8m9PO9Pbfh/view?usp=sharing – Doug Null Dec 05 '20 at 17:28
  • Asperi: I zipped both projects sim_backend_UI & mobile_sensor_API from mac OS. You will need to set projects with your... TARGETS > Signing > Team and TARGETS > Build Settings > All > Packaging > Product Bundle Identifier ..because I delete our company from them. – Doug Null Dec 05 '20 at 17:36

1 Answers1

1

The simplest solution is to allow Xcode to make all dependencies and include all required system libs.

Here is what I did:

  1. Create workspace at top folder level

  2. Added mobile_sensor_API.xcodeproj to workspace

  3. Added sim_backend_UI.xcodeproj to workspace

  4. Added dependency of sim_backend_UI to lib via workspace

demo

  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

demo2

  1. Build >>> Succeeded!

UPDATE 3 .................................. AFTER I DID THIS ANSWER thru step 6, I got "succeeded" but sim_backend_UI.app is RED and won't run on iphone.

enter image description here

Doug Null
  • 7,989
  • 15
  • 69
  • 148
Asperi
  • 228,894
  • 20
  • 464
  • 690
  • Awesome! Can't wait to try. so, sounds like my big mistake was not having workspace. – Doug Null Dec 05 '20 at 20:43
  • Trying to make app depedant on lib, I dragged lib's .a to app proj > TARGETS > General > Frameworks, Libraries, and Embedded Content, built (cmd-B), lib built but app's Products sim_backend_UI.app is still red, though title bar shows "Succeeded". (UPDATE with all my steps is above) – Doug Null Dec 07 '20 at 04:22
  • You missed my steps... don't drag (moreover remove made libs from Finder at all) - just add dependency as specified at step 4 - Xcode will build (rebuild) lib when needed by itself. – Asperi Dec 07 '20 at 04:41
  • Asperi, to do step 4 "add dependency" I dragged libmobile_sensor_API.a from lib's Products into app > TARGETS > Frameworks, Libraries, and Embedded Content. Was this the correct way? – Doug Null Dec 07 '20 at 14:32
  • What about the mobile_sensor_API.h file? Does that need to be dragged into app project? – Doug Null Dec 07 '20 at 16:01
  • Asperi, after I followed your answer thru step 6, I got "succeeded" but sim_backend_UI.app is RED and won't run on iphone. I updated my question with my exact steps, this time following yours exactly. – Doug Null Dec 07 '20 at 16:48
  • Don't you think it is out of topic question... or will we develop entire application here? – Asperi Dec 07 '20 at 17:14
  • I got it working. Thanks for your great help! – Doug Null Dec 07 '20 at 17:26
  • Asperi, thanks again for your answer. Question: when you ran it, did you see error "[CoreBluetooth] XPC connection invalid" in log after BLE central starts? I started new StackO question: ObjC app calling ObjC static lib gets “[CoreBluetooth] XPC connection invalid” – Doug Null Dec 09 '20 at 16:49