-
Notifications
You must be signed in to change notification settings - Fork 69
[objective_c] Swift style KVO pattern #2344
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
PR Health
Breaking changes
|
Package | Change | Current Version | New Version | Needed Version | Looking good? |
---|---|---|---|---|---|
objective_c | Breaking | 8.0.0 | 8.1.0-wip | 9.0.0 Got "8.1.0-wip" expected >= "9.0.0" (breaking changes) |
This check can be disabled by tagging the PR with skip-breaking-check
.
Changelog Entry ✔️
Package | Changed Files |
---|
Changes to files need to be accounted for in their respective changelogs.
API leaks ⚠️
The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
Package | Leaked API symbols |
---|---|
objective_c | _FinalizablePointer _Version |
This check can be disabled by tagging the PR with skip-leaking-check
.
License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files |
---|
no missing headers |
All source files should start with a license header.
Unrelated files missing license headers
Files |
---|
pkgs/jni/lib/src/third_party/generated_bindings.dart |
pkgs/native_doc_dartifier/example/native_doc_dartifier_example.dart |
pkgs/native_doc_dartifier/lib/native_doc_dartifier.dart |
pkgs/native_doc_dartifier/lib/src/native_doc_dartifier_base.dart |
pkgs/objective_c/lib/src/ns_input_stream.dart |
The added tests are failing on mac though |
Yeah, still trying to debug. |
Gave up trying to fix the test and just disabled the failing bits. Filed #2352 |
Usage
Observer
protocolobject.addObserver(observer, ...)
addObserver
returns anObservation
, which must be held for as long as you want to keep receiving updatesObservation
object holds strong refs to theObserver
and the observed object, keeping them aliveobservation.remove()
, or allow it to go out of scope and be GC'd, and the observations will stopImplementation notes
Observer
is an ordinary ffigen'd ObjC protocol defined in observer.h.addObserver
is an extension method onNSObject
.Observation
is a thin wrapper aroundDOBJCObservation
.DOBJCObservation
is defined in observer.h/m and holds a strong reference to both the observedNSObject
and theObserver
. These references are dropped if.remove()
is called.NSObject
internally holds a weak reference to theObserver
.Observer
to hold a strong reference to the observedNSObject
. But it would create reference cycles if they held strong references, even indirectly, to theObserver
or theObservation
(this is pretty much the same restriction we have for any protocol implementation).Fixes #1508