Code Not Compiling


I'm attempting to follow Apple's Dev tutorials, but I've gotten this far and it won't compile. I just added in an initializer that assigns a default value to the id property from Step 3 in the section "Displaying data in a list".

I've also found, likely due to the same issue, that my ScrumsView isn't even close to the tutorial images.

MacBook Air 13″, macOS 13.2

Posted on Feb 25, 2023 9:51 AM

Reply
Question marked as Top-ranking reply

Posted on Feb 25, 2023 10:32 AM

You’re presumably referencing this Scrumdinger example: Develop apps for iOS | Apple Developer Documentation


The initializer needs to be declared within its related type; within a struct or class. Here, that usually means there’s a } in the wrong place, probably with the struct just above the blocks with the errors. Without having Xcode or the example handy to review and test, the } at line 17 probably needs to be moved to line 35.


I’ve found some of those Apple Swift tutorials can go badly wrong when I’ve made a syntax error somewhere earlier in the tutorial. If you’d be interested in a different approach for learning Swift: https://cs193p.sites.stanford.edu/

7 replies
Question marked as Top-ranking reply

Feb 25, 2023 10:32 AM in response to IbsinRG

You’re presumably referencing this Scrumdinger example: Develop apps for iOS | Apple Developer Documentation


The initializer needs to be declared within its related type; within a struct or class. Here, that usually means there’s a } in the wrong place, probably with the struct just above the blocks with the errors. Without having Xcode or the example handy to review and test, the } at line 17 probably needs to be moved to line 35.


I’ve found some of those Apple Swift tutorials can go badly wrong when I’ve made a syntax error somewhere earlier in the tutorial. If you’d be interested in a different approach for learning Swift: https://cs193p.sites.stanford.edu/

Feb 25, 2023 5:12 PM in response to IbsinRG

The error messages describe what the problems are. You have another CardView struct declared somewhere else in the project. Same for CardView_Previews. For the labelStyle modifier, you are using ".trailingIcon" which doesn't exist.


Unfortunately, Apple changes its platforms, products, languages, and APIs very frequently. When I do a search, I see other people who used ".trailingIcon" from this tutorial. And this was only a few months ago. The tutorial specifies iOS 13. So perhaps it was different back then. Or perhaps another part of the tutorial created that style. Unfortunately, this is pretty typical for Apple tutorials and sample code. It's always a moving target.


Just comment out that modifier and keep going. Of course you'll need to track down the other CardView structs and get rid of them too.

Feb 25, 2023 5:06 PM in response to IbsinRG

Okay. Run some DuckDuckGo or other web searches for scrumdinger TrailingIconLabelStyle (the latter included in the search query as there seems more than one version of the demo around) and fetch the posted code from github or wherever else, and diff it.


Something related to CardView or its extension diverges from demo expectations.


I found a couple of examples posted.


Also found this: https://github.com/pointfreeco/standups

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Code Not Compiling

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.