gh-XcodesOrg-XcodesApp/Xcodes/Backend/Optional+IsNotNil.swift
2020-12-28 12:42:28 -07:00

9 lines
328 B
Swift

import Foundation
extension Optional {
/// Note that this is lossy when setting, so you can really only set it to nil, but this is sufficient for mapping `Binding<Item?>` to `Binding<Bool>` for Alerts, Popovers, etc.
var isNotNil: Bool {
get { self != nil }
set { self = newValue ? self : nil }
}
}