Swift
, Combine
, CoreML
, and SwiftUI
.Framework
While the C/C++ library remains exposed as before, most Swift APIs have streamlined, but familiar namespacing. All asynchronous interactions and value streams use Apple’s Combine framework (which reads similar to React). If new to Combine, check out Joseph Heck’s guide.
Most activities kick off with a publisher, such as publish
or publish
. Next, an operator like .stream
, .log
, .command
, .read
, or .optionally
will consume a sensor configuration struct or code-completing preset.
A new iCloud metadata sync utility, Meta
, and drag-and-drop conveniences are in the Meta
product.
State changes are observed not through delegates, but publishers on the objects themselves. Gone are Scanner
and Scanner
. Now the Meta
publishes diffs of its own device map or individual discoveries. The connect()
command is relocated to the Meta
itself.
The scanner no longer mandates LED flashes upon connection. If you liked this, just use:
let pattern: MWLED.FlashPattern = ...
metawear
.whenConnected()
.command(.ledFlash(pattern))
.sink { _ in }
.store(in: &subs)
You can also use the new MWLED
to depict the same event in your UI.
Most properties remain similar. Minor objects have been shortened with MW prefixes or placed one level deeper in a hierarchy. Some examples are:
Meta
includes MACAddress
MWFirmware
meta
publish()
.command(.reset
An edge case difference: this SDK has a public init(peripheral:
for MetaWears so that you may roll your own Meta
.
Aspect | Bolts | Combine |
---|---|---|
Objects |
|
|
Semantics | Reference | Reference + value |
Requirement | iOS 10 | iOS 13 |
Distribution | Cocoapods | Enables Swift Package Manager |
Most publishers are value types, but Current
and Passthrough
are reference types. You can progressively build and pass around “unconnected” publisher pipelines. Execution starts upon subscription, which often is when you create and store an Any
token.
To consume one type and output another asynchronously, use flat
.
.flatMap { [weak self] output -> AnyPublisher<Output,Failure> in
return <new publisher>.eraseToAnyPublisher()
}
To perform side effects, use .handle
.
To cancel one or more pipelines, call .cancel()
on a stored Any
token or use the prefix(until
operator.
If the compiler says .flat
is unavailable or is inexplicably upset, the culprit may be discrepant Failure
types. For example, .try
erases custom error types. You can use .map
or your own .map
operator to keep the party going.
Philosophy | Prior SDK | Combine SDK |
---|---|---|
Purpose | Thin C wrapper | Beginner-friendly, extendable |
Outputs | Some C structs | Only SIMD or other native types |
Communication | Delegate-observer | Unlimited state subscriptions |
Namespacing | Wider | More hierarchical (not quite 1:1) |
Persistence | Many keys, fixed UserDefaults suite | One or two keys, customizable suite, migration |
Aspect | Prior SDK | Combine SDK |
---|---|---|
UI Assist | Imperative ScannerModel/Item | Publishers or cloud-synced metadata store |
Demo Apps | UIKit + SwiftUI | Bare test host, basic tutorial, MetaBase (all SwiftUI) |
Install Base | Wider | New, but same community forum |
Swift
, Combine
, CoreML
, and SwiftUI
.