Fix objc associated objects not working in release builds
This commit is contained in:
parent
38b0d57118
commit
68646c4b4d
|
@ -8,12 +8,12 @@
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
private var prevScrollOffsetBeforeScrollToTopKey: Void = ()
|
private let prevScrollOffsetBeforeScrollToTopKey = UnsafeMutableRawPointer.allocate(byteCount: 0, alignment: 0)
|
||||||
|
|
||||||
extension UIScrollView {
|
extension UIScrollView {
|
||||||
private var prevScrollOffsetBeforeScrollToTop: CGFloat? {
|
private var prevScrollOffsetBeforeScrollToTop: CGFloat? {
|
||||||
get {
|
get {
|
||||||
if let v = (objc_getAssociatedObject(self, &prevScrollOffsetBeforeScrollToTopKey) as? NSNumber)?.doubleValue {
|
if let v = (objc_getAssociatedObject(self, prevScrollOffsetBeforeScrollToTopKey) as? NSNumber)?.doubleValue {
|
||||||
return CGFloat(v)
|
return CGFloat(v)
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
|
@ -21,9 +21,9 @@ extension UIScrollView {
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
if let newValue {
|
if let newValue {
|
||||||
objc_setAssociatedObject(self, &prevScrollOffsetBeforeScrollToTopKey, NSNumber(value: newValue), .OBJC_ASSOCIATION_COPY_NONATOMIC)
|
objc_setAssociatedObject(self, prevScrollOffsetBeforeScrollToTopKey, NSNumber(value: newValue), .OBJC_ASSOCIATION_COPY_NONATOMIC)
|
||||||
} else {
|
} else {
|
||||||
objc_setAssociatedObject(self, &prevScrollOffsetBeforeScrollToTopKey, nil, .OBJC_ASSOCIATION_COPY_NONATOMIC)
|
objc_setAssociatedObject(self, prevScrollOffsetBeforeScrollToTopKey, nil, .OBJC_ASSOCIATION_COPY_NONATOMIC)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,20 +16,20 @@ protocol ToastableViewController: UIViewController {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var currentToastKey = "Tusker_currentToast"
|
private let currentToastKey = UnsafeMutableRawPointer.allocate(byteCount: 0, alignment: 0)
|
||||||
|
|
||||||
extension ToastableViewController {
|
extension ToastableViewController {
|
||||||
|
|
||||||
private(set) var currentToast: ToastView? {
|
private(set) var currentToast: ToastView? {
|
||||||
get {
|
get {
|
||||||
let holder = objc_getAssociatedObject(self, ¤tToastKey) as? WeakHolder<ToastView>
|
let holder = objc_getAssociatedObject(self, currentToastKey) as? WeakHolder<ToastView>
|
||||||
return holder?.object
|
return holder?.object
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
if let newValue = newValue {
|
if let newValue = newValue {
|
||||||
objc_setAssociatedObject(self, ¤tToastKey, WeakHolder(object: newValue), .OBJC_ASSOCIATION_RETAIN)
|
objc_setAssociatedObject(self, currentToastKey, WeakHolder(object: newValue), .OBJC_ASSOCIATION_RETAIN)
|
||||||
} else {
|
} else {
|
||||||
objc_setAssociatedObject(self, ¤tToastKey, nil, .OBJC_ASSOCIATION_RETAIN)
|
objc_setAssociatedObject(self, currentToastKey, nil, .OBJC_ASSOCIATION_RETAIN)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue