-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathObjectiveC-BOOLchar.swift
45 lines (39 loc) · 1.25 KB
/
ObjectiveC-BOOLchar.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
@exported
import ObjectiveC
/// The Objective-C BOOL type.
///
/// On OS X, the Objective-C BOOL type is a typedef of "signed char". Clang
/// importer imports it as ObjCBool.
///
/// The compiler has special knowledge of this type.
struct ObjCBool {
var value : Int8
init(_ value: Int8) {
self.value = value
}
/// Allow use in a Boolean context.
func getLogicValue() -> Bool {
return value != 0
}
/// Implicit conversion from C Boolean type to Swift Boolean type.
@conversion func __conversion() -> Bool {
return self.getLogicValue()
}
}
extension Bool {
/// Implicit conversion from Swift Boolean type to Objective-C Boolean type.
@conversion func __conversion() -> ObjCBool {
return ObjCBool(self ? 1 : 0)
}
}