Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API

From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
You should learn the basics of SwiftUI.
There is a lot of misunderstanding in your rant.
It’s not converting var to let.
SwiftUI Views are immutable value types, that’s why using var for later mutation is an antipattern.
If you want mutation and state inside of Views, you should use @State or @Binding or make dedicated view models. -
Here is some fun.. figuring out what owns what...
put self in front of ".padding" like this:
self.padding( .horizontal, 20 )
It builds easily and runs and then shits its pants 💩👖 with
Thread 1: EXC_BAD_ACCESS (code=2, address=0x16f17ffd0)
In some thread that I did not create.
"safe" seems to mean "no pointers" and I guess nothing else. I guess any car without a stick shift could be called "safe" by that sort of logic. (Swift == Hype) -
@Lensflare Digging through AI interaction on why that line causes the obscure error output, it very clearly pointed out that the reason the assignment could only be performed during declaration is because Swift functionally converts the "var" to a "let".
-
@xcodesucks if you want to know what type it belongs to, simply command+click on it.
It will jump to the declaration.
Alternatively, option+click will open the doc. -
@Lensflare In my experience command-click or option-command-click does not always work. Nothing happens for instance when command-clicking on "padding". Xcode Does suck you know... 🤣
Related Rants
I'm trying really hard to like Swift but every time I open the hood on this bird, it takes a shit on my windshield.
For example:
struct ContentView: View {
var body: some View {
let kFontPointSize = 25.0
var theFont: Font = .system( size: kFontPointSize )
theFont = .custom("Helvetica", size: kFontPointSize )
Text("Hello, World!")
.padding(.horizontal, 20.0)
.font( theFont )
}
}
... in spite of how wonderfully self documenting (🐂💩) Swift is, that dirty bird converts the 'var' to a 'let' and "theFont" cannot be reassigned after declaration.
3 things:
1. invisibly converting the 'var' to a 'let' and not indicating 'var' can't be used... really?! Suppose to just "know" these obscure inconsistencies? (sloppy design)
2. then the error Xcode presents on "theFont = ..." line is : "Type '()' cannot conform to 'View'"!? How about "can't use a 'var' here"? God forbid it should make sense. (sloppy design)
3. "var" means variable and "let" means letstant? If you are going to use "var", better use "const", or be consistent and use "set" and "let" instead of "var" and "let" (sloppy inconsistency)
4. and ".horizontal", who owns that? Self documenting?. It is owned Edge Set aka Edge.Set.horizontal and effectively a "global".
5. And reading the Swift coder's mind... No, you should NEVER NEVER NEVER use "25" as a constant literal passed like .system( size: 25 ). (magic numbers not aloud)
Have all best engineering practices been simply tossed out the window? Rule #1 in software "engineering": Globals are BAD. Corollary: magic numbers earn you a one-legged A on your project.
I am so incredibly disappointed in the Swift community right now. Swift designers are honestly earning a "script kiddy" badge of dishonor.
devrant
xcode