|
This works, but I know its a horrible method. Well, maybe not horrible since it works, but its the hard way. My issue is every time I try to add newWord.count to gameScore it gives me issues that I can't add this to an Int which is what gameScore is. I tried INT(newWord) but couldn't...
|
|
You could simplify all of this into 1 line of code if you think about it. If you look at all of your
But I'm not sure why you are getting the error you are getting, but I might be able to help more if you can provide the exact error message that you are seeing.
|
|
Have you tried var contents = newWord.count then print or add the contents to your gamescore see what happens? Not saying this is right or proper way to do things since I can't see exactly what you're trying to achieve, your full code is not listed, but the print statement should get you in the right direction. If all else fails print everything and anything that you're not sure what it is. Is very handy tool in playground. Right click on go to defenition that always helps too. And most importantly don't forget snacks. Have a nice day! |
|
|
|
The error is "Left side of mutating operator isn't mutable: 'count' is a get-only property" when I try to add newWord += gameScore. When I option-click gameScore, I get this... @AppStorage var gameScore: Int { get nonmutating set }. My code does work, but I know its not optimal. |
|
If you are using
You are trying to add an Int to a String. That will not work. Instead, you should be adding the number of letters in the word to the gameScore.
If you are trying that in reverse...
You are trying to change the value of That will not work, and is probably the reason it is telling you that the left side is not mutable. If you have the word "Dog" and get the count property of it, it would be 3. Then, if you try to say "I want to add 5 to that number" it wouldn't make sense to allow you to do that, because the word would still be "Dog" and it would not suddenly have 8 letters in it. |
SPONSORED Alex is the iOS & Mac developer’s ultimate AI assistant. It integrates with Xcode, offering a best-in-class Swift coding agent. Generate modern SwiftUI from images. Fast-apply suggestions from Claude 3.5 Sonnet, o3-mini, and DeepSeek R1. Autofix Swift 6 errors and warnings. And so much more. Start your 7-day free trial today!
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.