Skip to content

Update Unmanaged+Extension #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/OpenSwiftUICore/Data/Property/PropertyList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ private func find<Key: PropertyKey>(
return nil
}
repeat {
guard keyFilter.match(element.flatMap(\.keyFilter)) else {
guard keyFilter.match(element.map(\.keyFilter)) else {
return nil
}
if let before = element.map(\.before),
let result = find(before, key: key, keyFilter: keyFilter) {
return result
}
if element.flatMap(\.keyType) == Key.self {
if element.map(\.keyType) == Key.self {
return element.map { $0 as? TypedElement<Key> }
}
guard let after = element.map(\.after) else {
Expand Down
24 changes: 0 additions & 24 deletions Sources/OpenSwiftUICore/Data/Property/Unmanaged+Extension.swift

This file was deleted.

31 changes: 31 additions & 0 deletions Sources/OpenSwiftUICore/Extension/Unmanaged+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Unmanaged+Extension.swift
// OpenSwiftUICore
//
// Audited for iOS 18.0
// Status: Complete

extension Unmanaged {
@_transparent
package func map<T>(_ transform: (Instance) -> T) -> T {
_withUnsafeGuaranteedRef { transform($0) }
}

@_transparent
package func map<T>(_ transform: (Instance) -> T) -> Unmanaged<T> where T: AnyObject {
_withUnsafeGuaranteedRef { .passUnretained(transform($0)) }
}

@_transparent
package func map<T>(_ transform: (Instance) -> T?) -> Unmanaged<T>? where T: AnyObject {
_withUnsafeGuaranteedRef { transform($0).map { .passUnretained($0) } }
}

package static func == (lhs: Unmanaged<Instance>, rhs: Unmanaged<Instance>) -> Bool {
lhs.toOpaque() == rhs.toOpaque()
}

package static func != (lhs: Unmanaged<Instance>, rhs: Unmanaged<Instance>) -> Bool {
lhs.toOpaque() != rhs.toOpaque()
}
}
Loading