There is a little problem with UINavigationBar
which I\'m trying to overcome. When you hide the status bar using prefersStatusBarHidden()
method in
The first problem I faced was Swift extension can't have stored properties.
First of all, categories in Objective-C also cannot have stored properties (called synthesized properties). The Objective-C code you linked to uses a computed property (it provides explicit getters and setters).
Anyway, getting back to your problem, you cannot assign to your property because you defined it as a read-only property. To define a read-write computed property, you would need to provide a getter and setter like this:
var fixedHeightWhenStatusBarHidden: Bool {
get {
return objc_getAssociatedObject(self, "FixedNavigationBarSize").boolValue
}
set(newValue) {
objc_setAssociatedObject(self, "FixedNavigationBarSize", NSNumber(bool: newValue), UInt(OBJC_ASSOCIATION_RETAIN))
}
}