I am attempting to use NSKeyValueObservation in a Swift executable I am running on Docker. I am using the following swift version: 5.1.3
I stripped down everything and I literally just declare in main.swift:
var observer: NSKeyValueObservation?
The error returned is:
/package/Sources/TestPackage/main.swift:30:19: error: use of undeclared type 'NSKeyValueObservation'
var observer: NSKeyValueObservation?
Since the error does not occur locally, my hunch is that Docker is running linux and linux doesn't know about NSKeyValueObservation but this isn't documented anywhere. If so, how do I get around this issue?
The relevant Docker version information is:
Client: Docker Engine - Community
Version: 19.03.5
API version: 1.40
Go version: go1.12.12
Git commit: 633a0ea
Built: Wed Nov 13 07:22:34 2019
OS/Arch: darwin/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.5
API version: 1.40 (minimum version 1.12)
Go version: go1.12.12
Git commit: 633a0ea
Built: Wed Nov 13 07:29:19 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.2.10
GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version: 1.0.0-rc8+dev
GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version: 0.18.0
GitCommit: fec3683
Your hunch is correct. NSKeyValueObservation
relies on the Objective-C runtime, which does not exist on non-Darwin platforms. You will need to use an alternative, such as some flavor of Rx.