I have been following Swift App Tutorial created by Apple here. Specifically, I am trying to set up a few custom buttons to create a rating control. The buttons have three images associated with it: emptyStar, filledStar, and highlightedStar, to be used at different states of the button.
I use the code exactly as provided by Apple, but I don't know why I have been getting this compile-time cryptic error Expected pattern
as shown in the screenshot:
What am I doing wrong here?
Silly me, and Xcode, it's the Code Auto-Completion feature that confuses me.
The little icons in code shown in the first screenshot aren't nice visual decorations that match with my variable names (although I'd love these smart "emojis" decorating my code). They indicate that what I declare after
let
is not a variable, but the very image itself.You have to be careful by not accepting the auto-completion when typing and stick with normal text when declaring the constant. After such declaration, you will see that there are two different, for example,
emptyStar
's of the same name -- one an image and another a constant.Here's the final code, barely noticeable visual change!