Ok, let's do it from scratch step-by-step just to recall that it is possible (used Xcode 11.2, sorry - no 10.2, but I did this even before, so sure nothing changed since then)
1) Create new project form template
iOS > Single View App > Sample (Swift/Storyboard) > Next > Create >
Build > Ok
2) Create static lib from template
Project Navigator > Sample > Add Target > iOS > Static Library >
Calculator (Objective-C) > Finish
3) Add something meaningful to Calculator
Update Calculator.h & Calculator.m with following ...
@interface Calculator : NSObject
+ (NSString *)calculatedValue;
@end
@implementation Calculator
+ (NSString *)calculatedValue {
return @"1 + 1 = 5";
}
@end
Switch active schema to Calculator > Build > Ok
4) (!!! Very important step) Prepare Swift-ObjC bridge in main target
I prefer that Xcode do this, so... switch back active schema to Sample app
File > New > Cocoa Touch Class > Stub (Objective-C)
Next > (Make sure target is Sample checked) > Create
Create Bridging Header (This is it! - actually internally it does
more) > Remove Stub.h/m (as they don't need for us)
5) Open Sample-Briding-Header.h and into it #import "Calculator.h"
6) Add library to main app target
Project Navigator > Sample > Target Sample > General > Section
"Frameworks, Libraries... > + > select libCalculator.a
Actually, that's it - now it possible to use Objective-C classes from static library in main Swift-based application
7) Simple demo manipulations... create UILabel
in View Controller Scene
of Main.storyboard
and create outlet to it in ViewController.swift
, set string generated in library to UILabel.text
property
class ViewController: UIViewController {
@IBOutlet weak var results: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
results.text = Calculator.calculatedValue()
}
}
8) Build & Run > OK (observe result of integration)