|
I have narrowed down the subject warning to a single .disabled modifier. This happens with an iOS target but not a macOS target. My desire is to have the user type 5 characters and as the 5th character is typed the TextField is disabled.
Xcode marked the @main statement (not the .disabled modifier) with this warning. The Xcode console gives:
This .disabled modifier seems to work on both iOS and macOS but only iOS produces this warning. As a further explanation - I do not want to type / tap 'return' so .onSubmit is not a preferred solution. Am I doing something wrong? Since it seems to work, should I just ignore this wrning on iOS? Any insights appreciated. |
|
SwiftUI is a declarative language. Some of these errors won't appear if you keep revising your code to read as declarations... This is what I want SwiftUI to do. This line doesn't seem very Swifty.
As a fellow coder, I have to stop and think about what you're trying to accomplish. Indeed, this is where the error is introduced. However, with a simple change shown below, you can eliminate the error, and improve readability at the same time.
When SwiftUI is building your view it grabs the external value of At this point, the view builder may find out that the new value is different from the value it used when determining if the field should be disabled or not. See? You are potentially changing the value, while the view is being constructed. Don't do this. |
|
@twostraws wrote this article to answer the WHY part of your question. |
|
Hi Vincent, That very insterting that it disabled in macOS and error in iOS What I would be asking myself is what are you going to do with the You disable the No, do not ignore this error. PS just in case you have not tried it |
|
@Obelix - Thanks so much for the quick reply. I copied your FieldLengthView: into an iOS app and get the exact same Xcode Warnings.
When I use your code or my code in a macOS app I get no Xcode warnings. The …app.swift file has (iOS only):
|
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.
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.