Andropov
Site Champ
- Joined
- Nov 8, 2021
- Posts
- 713
It's more like having a super-confident doctor that never actually went to med school and faked its degree instead.^ Interesting. Not related to this thread but i checked out ChatGPT late last year (under my social sciences hat). Initial enthusiasm - ’gee, this is like having a quite good intern/research assistant on tap’ - rapidly drained away when i encountered errors and repetitive answers that missed important differences in questions. I found exactly what you did in your last paragraph
Yep, I've asked ChatGPT a few SwiftUI questions and saw the same things all over the place. Probably a symptom that many people are doing it, though.
- Then it decided it was okay to recreate all child view models (which tends to break things in SwiftUI through over-invalidation)
It is in fact quite hard to mentally parse that code.Swift:func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) { children = controller.fetchedObjects?.compactMap { ChildViewModel(child: $0) } ?? [] }
(As an aside, I kinda hate this code as it uses trailing closures in a way that makes the code harder to read.)
Yeah, a lot of the answers are like that. I actually had to re-read the sentence to figure out what was wrong.Uh... what? No? That's not how initializers work?
This is an interesting tool for probing some existing knowledge and faster/easier than swimming through the SEO gray goo that search engines are quickly becoming, but it is also just as much possible to lead you into a different type of grey goo where there's this sort of air of authority to everything ChatGPT is putting out, but it's about as useful as a new hire out of college working in an unfamiliar language, trawling through Stack Overflow.
I tried to ask ChatGPT how to programmatically scroll to the bottom of a List in SwiftUI (this just came up at work today). ChatGPT proposed:
Swift:
struct ContentView: View {
@State private var messages: [String] = []
var body: some View {
VStack {
List(messages, id: \.self) { message in
Text(message)
}
HStack {
TextField("Enter a message", text: $newMessage)
Button(action: {
messages.append(newMessage)
newMessage = ""
scrollToBottom()
}) {
Text("Send")
}
}
}
.onAppear {
scrollToBottom() // Scroll to bottom when the view appears
}
}
private var newMessage = ""
private func scrollToBottom() {
// Use ScrollViewReader to scroll to the bottom of the list
ScrollViewReader { scrollView in
scrollView.scrollTo(messages.last, anchor: .bottom)
}
}
}
ScrollViewReader
s do not work like that. At all. It's comically bad. Also, the List
probably won't work as-is either, since String
doesn't conform to Identifiable
and you absolutely need that to use scrollTo
... The explanation of why anchor: .bottom
is used was also wrong.I tried a couple more examples but it's clear that it's not useful at all for SwiftUI.
I'm still very skeptical that Large Language Models will surpass their many pitfalls any time soon. I think we're at the limit of what can be achieved without higher order thinking, and ChatGPT clearly doesn't have that.It will improve, but I think the worry I have is that with the big recent publicity, there's folks (Microsoft being one of them) that are pushing to try to adapt this into their workflow. But if you aren't able to recognize that its output is inherently untrustworthy, then you can find yourself going down the wrong path and having to start over once you realize the answer is wrong. Even worse is that as people become dependent on tools like ChatGPT, the issue of citing sources gets harder, not easier, and so checking things gets more difficult. We make ourselves dependent on a tool that doesn't reason the way we do, in order to reason about topics and issues. Woof.
Hm. I don't use protocols very much in the View Models themselves though. I think. Maybe after turning on the strict concurrency checks I'll discover that I actually do. Haven't had much time to play with it yet. But yeah, I can see that in some scenarios you'd only annotate some functions/properties asMain actor-isolated property 'id' cannot be used to satisfy nonisolated protocol requirement
Because identifiable is a non-isolated protocol, but it's being used in a main actor context, the compiler cannot resolve the conflict. This makes sense since Identifiable shouldn't be an isolated protocol in practice (it's a very generic concept), but it does mean I can't provide an implementation of Identifiable and mark the class as MainActor at the same time. This is the sort of pain I'm thinking of when it comes to fixing this stuff.
So realistically, you probably want to mark the async functions in an Observable Object as MainActor, rather than the whole type. Meanwhile things like UIView/View/etc should absolutely inherit MainActor for the whole type where possible.
@MainActor
in there.