It happened for me to write following code snippet in one of my UIViewControllers
in my new iOS Swift Application.
var starButtonsCount = starButtons.count
@IBOutlet var starButtons: [UIButton]!
Then straight next to the starButtonsCount
variable declaration following error appeared in red.
Error: Cannot use instance member ‘starButtons’ within property initializer; property initializers run before ‘self’ is available.
So I found out that by declaring the starButtonCount
variable as lazy
we can resolve this error (temporary in the long run of the iOS App development process).
I'm curious to find out what are the other methods to solve this?
Is there a way to trigger the initialization for starButtonCount
when the starButtons
IBOutlets get initialized?
awakeFromNib
method. – MaricelastarButtonsCount
as a constant, still the same error appears. So the focus should be how theBOutlets
get initialized and how to catch that and initialize my variable. – FauniestarButtonsCount
is declared aslet
with a constantInt
– Bartie