I was working on one of my previous app that was done on Objective C. I need to add a new module to it and I decided to use Swift for that particular module.
I have a class called HomePage
in Objective C, I wanted to add some new IBAction
s and IBOutlet
s in it. For that I added a new swift file and extended the existing class like:
// MARK: IBOutlets and IBActions
extension HomePage
{
@IBOutlet var image : UIImageView!
...
/*!
* Loads the application support webpage
*/
@IBAction func loadSupportURL(sender : UIButton)
{
}
...
}
If I add only the IBActions everything is working perfectly. But when I add an IBOutlet, the compiler throws an error like:
Extensions may not contain stored properties
For fixing it I have two ways,
Is there any other way to fix this issue ?
As the error message clearly states, you can't have stored properties in an extension. But the thing is, you can't have them in Objective-C categories either, so the language isn't the problem here.
In both languages, you need to use associated references to implement stored properties. Please see this thread for an example of using associated references in Swift. Since it is a C API, its usage is pretty much the same in Objective-C.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With