forked from ReactiveX/RxSwift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KVORepresentable+CoreGraphics.swift
70 lines (59 loc) · 1.68 KB
/
KVORepresentable+CoreGraphics.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// KVORepresentable+CoreGraphics.swift
// RxCocoa
//
// Created by Krunoslav Zaher on 11/14/15.
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//
#if !os(Linux)
#if !RX_NO_MODULE
import RxSwift
#endif
import CoreGraphics
import class Foundation.NSValue
#if arch(x86_64) || arch(arm64)
let CGRectType = "{CGRect={CGPoint=dd}{CGSize=dd}}"
let CGSizeType = "{CGSize=dd}"
let CGPointType = "{CGPoint=dd}"
#elseif arch(i386) || arch(arm)
let CGRectType = "{CGRect={CGPoint=ff}{CGSize=ff}}"
let CGSizeType = "{CGSize=ff}"
let CGPointType = "{CGPoint=ff}"
#endif
extension CGRect : KVORepresentable {
public typealias KVOType = NSValue
/// Constructs self from `NSValue`.
public init?(KVOValue: KVOType) {
if strcmp(KVOValue.objCType, CGRectType) != 0 {
return nil
}
var typedValue = CGRect(x: 0, y: 0, width: 0, height: 0)
KVOValue.getValue(&typedValue)
self = typedValue
}
}
extension CGPoint : KVORepresentable {
public typealias KVOType = NSValue
/// Constructs self from `NSValue`.
public init?(KVOValue: KVOType) {
if strcmp(KVOValue.objCType, CGPointType) != 0 {
return nil
}
var typedValue = CGPoint(x: 0, y: 0)
KVOValue.getValue(&typedValue)
self = typedValue
}
}
extension CGSize : KVORepresentable {
public typealias KVOType = NSValue
/// Constructs self from `NSValue`.
public init?(KVOValue: KVOType) {
if strcmp(KVOValue.objCType, CGSizeType) != 0 {
return nil
}
var typedValue = CGSize(width: 0, height: 0)
KVOValue.getValue(&typedValue)
self = typedValue
}
}
#endif