Skip to content

Commit be1272f

Browse files
committed
Work around need to use CoreFoundation directly from plutil
1 parent fb6a747 commit be1272f

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

Sources/Foundation/NSNumber.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,18 @@ open class NSNumber : NSValue, @unchecked Sendable {
11501150
}
11511151

11521152
open override var classForCoder: AnyClass { return NSNumber.self }
1153+
1154+
/// Provides a way for `plutil` to know if `CFPropertyList` has returned a literal `true`/`false` value, as opposed to a number which happens to have a value of 1 or 0.
1155+
@_spi(BooleanCheckingForPLUtil)
1156+
public var _exactBoolValue: Bool? {
1157+
if self === kCFBooleanTrue {
1158+
return true
1159+
} else if self === kCFBooleanFalse {
1160+
return false
1161+
} else {
1162+
return nil
1163+
}
1164+
}
11531165
}
11541166

11551167
extension CFNumber : _NSBridgeable {

Sources/plutil/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ add_executable(plutil
2020
PLULiteralOutput.swift)
2121

2222
target_link_libraries(plutil PRIVATE
23-
CoreFoundation
2423
Foundation)
2524

2625
set_target_properties(plutil PROPERTIES

Sources/plutil/PLUContext.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
@_spi(BooleanCheckingForPLUtil)
1314
import Foundation
14-
import CoreFoundation
1515

1616
func help(_ name: String) -> String {
1717
name +
@@ -275,10 +275,12 @@ extension NSNumber {
275275
}
276276

277277
var betterSwiftType: BetterSwiftType {
278-
if self === kCFBooleanTrue {
279-
return .true
280-
} else if self === kCFBooleanFalse {
281-
return .false
278+
if let booleanValue = _exactBoolValue {
279+
if booleanValue {
280+
return .true
281+
} else {
282+
return .false
283+
}
282284
}
283285
switch UInt8(self.objCType.pointee) {
284286
case UInt8(ascii: "c"), UInt8(ascii: "s"), UInt8(ascii: "i"), UInt8(ascii: "l"), UInt8(ascii: "q"):

0 commit comments

Comments
 (0)