Error expected pattern in Swift?

I followed the Swift App tutorial created by Apple here . In particular, I am trying to create several custom buttons to create rating controls. Buttons have three images associated with it: emptyStar, fillStar, and highlightStar, which will be used in different states of the button.

I use the code exactly as provided by Apple, but I don’t know why I got this mysterious compiled-time Expected pattern error, as shown in the screenshot: Expected Template Errors Image assets

What am I doing wrong here?

+7
ios swift compile-time
source share
1 answer

Stupid me, and Xcode, it's a code autocomplete function that bothers me.

The small icons in the code shown in the first screenshot are not nice visual decorations that match my variable names (although I would like these clever β€œemoji” to decorate my code). They indicate that what I declare after let is not a variable, but itself.

You must be careful not to recognize autocomplete when entering text and when using plain text when declaring a constant. After such an announcement, you will see that there are two different ones, for example, emptyStar with the same name - one image and the other a constant.

Two empty stars

Here's the latest code, a barely noticeable visual change!

Final working code

+10
source share

All Articles