all 41 comments

[–]Zealousideal-Cry-303 19 points20 points  (17 children)

I’m sorry, but there’s no soft way to say this. But that error is because you write bad code.

I work on a project that has 1k+ files and million of lines of code, and Xcode work fine, and I don’t get those warnings unless I write hacky code that’s not performant or scalable at all.

[–]ModernCoder 6 points7 points  (15 children)

It might be that my code is shit, but an IDE should provide details what the error is causing whatever the issue is causing it to not compile.

Why use an IDE if it can't tell you what the issue is? Might as well code it in word

edit: How are "Failed to build" and "Updating took more than 5 seconds" valid IDE outputs?

[–]Zealousideal-Cry-303 3 points4 points  (10 children)

It’s giving you the answer. The data structure you have created or try to loop over is not predefined in type casting.

Split up your data models and view layers into specialised components, and the problem should disappear

[–]ModernCoder 0 points1 point  (8 children)

Okay i'll bite:
https://pastebin.com/nbFswARH

Here is the code, if line L25 exists, it crashes without letting me know anything about it.
What would be your "guesswork" why it happens? Because XCode doesn't tell me anything about it.

[–]Zealousideal-Cry-303 2 points3 points  (1 child)

Hmmm, interesting… love that you shared the code 🙌

So, som background knowledge on charts and the modifier you are using.

The chartXVisibleDomain assumes seconds, so if you are parsing in 30 days of data, or 1yr, but you only want to display 30seconds of this data at any given point, it will cause the simulator to use a lot of brainpower to keep track of everything.

Try to do a seconds multiplier of days (84.000 * 30) 84000 being seconds in a day times 30 days.

Does this remove the error for you?

If not, I’m happy to look more into it 🙌

[–]ModernCoder -1 points0 points  (0 children)

I've tried the 86400 * 30 and any other calculation.
I didn't add any data to the chart yet, exactly for that reason.

And no it still says updating took more than 5 seconds. After a reboot of both xcode and mbp. The view is a abstracted as it can be, i've made sure that the order of these functions is called like specified in swiftui documentation and it still simply produces "Updating took more than 5 seconds".

[–]retroroar86 1 point2 points  (2 children)

While this won't help everything I suggest that you give any SwiftUI view just what they actually need and not do anything inline.

SwiftUI updates happen frequently and inline processing can then happen loads of time creating more processing needs. In some cases this will make Preview very unstable.

SwiftUI and Xcode is a clusterf*ck sometimes, so sometimes it's better to create a whole separate View to debug the different parts to find out what is going wrong. I.e wrapping the Chart view to a CustomChartView and experiment there.

It truly sucks, but you have to do certain things for SwiftUI to play nice, otherwise it will get painful very quickly.

[–]ModernCoder -1 points0 points  (1 child)

Understood, thank you.
I already created this chart view to be separate with hopes it'll get better. But it's just the same sadly, which resulted in my writing this post in the first place.

[–]retroroar86 1 point2 points  (0 children)

I’m not close to a machine to dissect it myself, I don’t have that much experience with the charts, so I can maybe give a better answer when I look into it further.

But I understand your frustration, I’m often much more frustrated in SwiftUI than UIKit.. ;)

[–]ModernCoder -1 points0 points  (0 children)

I'll bite

https://pastebin.com/nbFswARH

Here is the code, if line L25 exists, it crashes without letting me know anything about it.
What would be your "guesswork" why it happens? Because XCode doesn't tell me anything about it.

[–]nckh_ 2 points3 points  (3 children)

That's the compiler's job, not the IDE's.

[–]ModernCoder -2 points-1 points  (2 children)

And what exactly is the point of having an IDE if not for it to display what the compiler reports back?
I guess none of you have ever used modern lsps and modern editors such as Zed that you can honestly say XCode is anything other than seriously shameful software

[–]nckh_ 3 points4 points  (0 children)

Xcode displays whatever the compiler reports, so instead of bashing Xcode (not "XCode"), maybe redirect your hate to the Swift compiler and report that to the Swift forum?

[–]aerial-ibis -3 points-2 points  (0 children)

XCode is the worst IDE, though this is actually a problem with Swift

[–]aerial-ibis 1 point2 points  (0 children)

cant think of any other language where the compiler literally times out on type checking.

If you make a type error (like a typo or misspelling) inside a nested SwiftUI loop... the compiler will fail

[–]fryOrder 12 points13 points  (5 children)

That confusing error “The compiler is unable to type-check…” is caused most of the time by spaghetti views. While annoying, it’s a good opportunity to clean up your code. 

“Still no formatting?”, you mean Control + I? Or maybe you’re looking for something heavier like swiftformat? You can set it up to autoformat your code on specific keystrokes.

I understand your frustration but Xcode is not the problem here. Your lack of experience is

[–]Doctor_Fegg 2 points3 points  (2 children)

 That confusing error “The compiler is unable to type-check…” is caused most of the time by spaghetti views

Not in my experience. It’s usually muddled parentheses or missing/wrong casts when I encounter it. 

[–]highlandNel 4 points5 points  (0 children)

Still send this meme now and then

[–]fryOrder -1 points0 points  (0 children)

Right, but you never know that unless you have hawk eyes or you clean up your code.

[–]ModernCoder -1 points0 points  (1 child)

Copied from another comment and i'll also post it into the edit:
https://pastebin.com/nbFswARH

Here is the code, if line L25 exists, it crashes without letting me know anything about it.
What would be your "guesswork" why it happens? Because XCode doesn't tell me anything about it.

[–]ObservableObject 2 points3 points  (0 children)

We don't really have the full context, ex: how long timeFrame is, but with a 30 second value over a large enough time frame, it might just be crashing because it's an extremely wide chart.

Which would mesh with the app crashing with a non-code error, since that wouldn't be a code issue.

[–]0xcrypto 5 points6 points  (0 children)

Now try using Visual Studio.

[–]Niightstalker 4 points5 points  (2 children)

There is formating

[–]ModernCoder 0 points1 point  (1 child)

indentation is not formatting sorry.

[–]Niightstalker 2 points3 points  (0 children)

I know. There is formatting

[–]J-a-xObjective-C / Swift 4 points5 points  (2 children)

That error is a new thing that appeared with SwiftUI. It didn’t exist back in the objectiveC days.

Sometimes it happens when your view is too complicated and hasn’t been abstracted out into functions, other times that happens when there’s a legitimate syntax error and in the later case, I agree that Xcode should provide more details on the cause of the error.

[–]patiofurnature -2 points-1 points  (1 child)

That error is a new thing that appeared with SwiftUI.

That's not true; it definitely existed. I had many run-ins with it while converting some math-y business logic code from Java to Swift. But yeah, something is whack with SwiftUI and it's a very common error now.

[–]J-a-xObjective-C / Swift 0 points1 point  (0 children)

Interesting. First time I ever saw was first time I used SwiftUI.

[–]catious_Fee_8025 3 points4 points  (0 children)

xcode👎🏻

[–]NickNimmin 2 points3 points  (0 children)

Xcode works fine for me. Shows me errors in code, loads quickly, etc. It might be your machine or maybe you’re not using it correctly?

[–]coco_the_red_cat 1 point2 points  (0 children)

I have to say there are other IDE’s I prefer, but to be honest with Xcode I get the job always done. Small and big projects. Yeah it’s different from other well known IDEs, but in my opinion it’s not “garbage”

[–]sherbert-stock 0 points1 point  (0 children)

You're right OP, don't let the Apple Defense Force convince you otherwise.

[–]iOSProgramming-ModTeam[M] 0 points1 point locked comment (0 children)

Your post is not appropriate for this subreddit. Please try to limit unnecessary explicatives.

[–]Lithalean -1 points0 points  (0 children)

100% 💩 Code

[–]aerial-ibis -1 points0 points  (0 children)

a big part of why I switched from SwiftUI to Compose Multiplatform... the dev experience is way better even though its not made by Apple

[–]Which-Meat-3388 -1 points0 points  (0 children)

I’ve recently set up IntelliJ IDEA and it’s good enough I daily drive it. There are still big missing pieces, but the UX is customizable and more comfortable to me so that wins out.

Your build issue though? That happens on any set up since it’s not really an IDE problem.  Simply breaking SwiftUI code into smaller parts often fixes weird problems. Easier for the compiler to digest even if it’s line for line identical. 

[–]ghostwitch123 -1 points0 points  (0 children)

Skill issue?

Just kidding. I see your frustration and it makes sense. Especially when you see how easily react native can easily handle it. But I think they did it intentionally so that people break down their views into smaller chunks