UIViewControllerを拡張して、StringやBoolが保存できる
vc.addedString = "Str"
vc.addedBool = true
public extension UIViewController { private struct additional { static var addedString: String = "" static var addedBool: Bool = false // TODO: ここ他にも増やせる } var addedString: String { get { guard let theString = objc_getAssociatedObject(self, &additional.addedString) as? String else { return "" } return theString } set { objc_setAssociatedObject(self, &additional.addedString, newValue, .OBJC_ASSOCIATION_RETAIN) } } var addedBool: Bool { get { guard let theBool = objc_getAssociatedObject(self, &additional.addedBool) as? Bool else { return false } return theBool } set { objc_setAssociatedObject(self, &additional.addedBool, newValue, .OBJC_ASSOCIATION_RETAIN) } } // TODO: ここ他にも増やせる }