Live data from Hacker News

SwiftUI After 7 Years

ykvm.com

321–330 of 343 posts

Re: SwiftUI After 7 Years

#321

Earlier quoted context omitted.

I have always treated state as the source of truth in UIKit. Every view gets an equatable state struct, and mutating it triggers an idempotent view update. Self-mutating views (e.g. inputs) back-propagate their state up the view hierarchy. SwiftUI/React/etc don't introduce that pattern, they simply enforce it (and add efficiencies). If a developer isn't familiar with the pattern, it's not because they are a UIKit dev…

Any chance you have any links so I can read up on this approach?

I don't know iOS-specific links off-hand - I'm basically just referring to rudimentary state-driven UI. But implemented manually, without a framework, and therefore bug-prone for unfamiliar devs.

For example (this is pseudo-code, I haven't written Swift in a long time):

  class ProfileViewController: UIViewController {

    struct State: Hashable {
      var username: String?
      var profileImageURL: String?
    }

    var state = State() {
      didSet {
        if state != oldValue { updateView() }
      }
    }

    // must be idempotent
    // must only read state and only mutate the view
    function updateView() {
      usernameLabel.text = state.username
      profileImageView.setImage(url: state.profileImageURL)
    }
  }
Lots of stuff can complicate this: External sources of truth (CoreData, UserDefaults), reference types (no memberwise equality), self-mutating views (UITextField), continuously changing values that state is derived from (the current time). But the pattern is so simple it's easy to extend it to account for these things as needed, usually with another layer of `update...()`, e.g. `updateState()` from a CoreData observer.

Re: SwiftUI After 7 Years

#322

Earlier quoted context omitted.

You’re shifting the burden of proof. You made a claim and refused to substantiate it in any way whatsoever.

I’m not trying to prove anything…? I just don’t care that much either way about what others think if it’s adversarial, even if thousands of HN users come to this comment chain to opine about this or that macbook model. If you mean my claim that some team in Apple already knows about it, there’s literally no way to prove that to passing readers.

> I’m not trying to prove anything…?

That’s exactly the point. Why would you expect others to even entertain a vague claim like that if you give them no reason to find it plausible? “Just test it yourself” (test what?) i.e. “prove me right yourself” is not going to be very successful.

Re: SwiftUI After 7 Years

#323
post #312

Earlier quoted context omitted.

Since when did asking someone to give a single example to support their point become "noise"? How can they do any testing, if you refuse to tell them what to even look for?

Uh are you confused? I’m not the one claiming they refuse to test it, they are the ones who said so.

You are the one refusing to give any detail whatsoever (e.g. what task?) to substantiate your claim.

Re: SwiftUI After 7 Years

#324

Earlier quoted context omitted.

Why should I need to do any testing ? I'm just going to keep on not believing you until you back up your claims. And your iPad example doesn't make sense at all, you compared 2 Macbooks and now you're talking about another OS altogether. > idk what to say. You could just tell us one example of something that's faster on your 2019 Macbook Pro 15 versus a M5 Macbook pro and how to reproduce it.

> Why should I need to do any testing ? I'm just going to keep on not believing you until you back up your claims. And why should he care what you think, because you have already made up your mind and don't care at all about facts or the truth.

On the contrary, they care enough about facts not to take a random, implausible and unsubstantiated claim at face value. Please don’t resort to Bulverism.

Re: SwiftUI After 7 Years

#325
post #309

Earlier quoted context omitted.

> until they saw the Objective-C adoption numbers were high enough. Nope. Until they saw that (a) CocoaJava was a complete dud, not just technically, but also in terms of developers buy in and (b) Cocoa/ObjC was accepted well by a large part of the dev community. > > "Garbage collection is deprecated in OS X 10.8. Use ARC > ARC is garbage collection, In terms of the Apple ecosystem, "Garbage Collection" refers to the…

Ah, the famous reality distortion field where industry terms get the meaning that suits Apple's marketing team and developer advocates.

No. Just that within the Apple ecosystem, the terms were used in a specific way.

Apple GC is a form of GC. There is no redefinition going on. It is correct.

However, it is ridiculous to say "we will replace garbage collection with garbage collection" and it is too cumbersome to say "we will replace reference counting garbage collection with tracing garbage collection".

Both "garbage collection" for the tracing garbage collection mechanism and "reference counting" for the reference-counting garbage collection mechanism are correct uses of terminology.

Using these shorthands instead of either the cumbersome complete terms or the confusing other shorthand is perfectly fine.

Although admittedly some Apple zealots started insisting that the Apple shorthands were the correct terminology. Or that programs that were broken by the broken GC had always been broken. Or that what Apple calls "MVC" is actually the correct definition of MVC when it is not.

https://blog.metaobject.com/2015/04/model-widget-controller-...

https://blog.metaobject.com/2017/03/concept-shadowing-and-ca...

Re: SwiftUI After 7 Years

#326

Earlier quoted context omitted.

That's pretty much where immediate mode GUIs and to a less extent React came from. (Though for React the provenance is probably closer to the HTML web-app: send request - update model - return HTML with complete and completely new UI.) The difference is that for most games, throwing away the complete rendered graphics and re-rendering from the world model is often the right approach. For most UIs, it isn't, unless th…

> The difference is that for most games, throwing away the complete rendered graphics and re-rendering from the world model is often the right approach. Well, that is what "retained mode" GUIs (i.e. those using control/widget trees and such) do too. The immediate mode GUI to me always felt like an approach came up by people who do not really want to bother doing GUIs. In terms of games it is like mixing logic and pre…

> Well, [throwing away the complete rendered graphics] is what "retained mode" GUIs (i.e. those using control/widget trees and such) do too.

That turns out not to be the case.

The widget tree is retained.

When changes come in, the resulting damage from those changes is assessed and then the damaged parts are redrawn in an optimized fashion.

https://developer.apple.com/documentation/AppKit/NSView/draw...

Re: SwiftUI After 7 Years

#327
post #288

Earlier quoted context omitted.

I knew Apple was lost when they dropped the “Home” button, just after spending a $1B to build a Palo Alto headquarters in the shape of the “Home” button.

I suggest reading Steve Jobs biographies regarding those kind of expenses at Apple, Pixar and NeXT.

What would the biographies say? He opposed them?

Re: SwiftUI After 7 Years

#328
post #302

Earlier quoted context omitted.

Genuinely curious: do you have experience with other environments, or mostly Apple?

Excellent question. I have mostly used Apple tools, but have also tried (most notably) VSCode, android studio, zed, Eclipse, vim and Sublime Text. None of these convinced me, except Sublime which I still use for “non-Apple” projects (also non-android, obviously). I also like vim, but not for coding, just as a general text editor. I particularly hate VSCode, for some reason (the reason is not that it comes from M$ if…

Right.

For me I think it is a bit more general than "just" the IDE.

For a start, it's painful to install the apps I develop on Apple devices: it's limited in number, so once in a while I have to delete the sample apps I installed. Also I need to "trust the developer" for each app, and apparently more than once (everytime I uninstall the app maybe?), and it requires going through an unintuitive path in the settings and clicking the wrong choice the first time because "allow" is in red (as if it meant "cancel").

Then it has to go through Xcode. I hate Xcode, but I can accept that people like it. My experience is that regularly, I have to clean the cache, then clean the hidden cache, then quit Xcode, go and erase some DerivedData, restart Xcode and hope it works. All the iOS developers I know are aware of this, so it feels like it's "part of the process"? For Android you can use whatever you please, to the point where you could even write your own IDE!

Signing is a pain during Apple development. You need a development team, sometimes it doesn't work for some unclear reason.

The Xcode project files are a big mess. Developers routinely version a whole hierarchy of file (xcodeproj, xcworkspace and whatnot) without understanding what's there. You want to change something? Go to the Xcode GUI, change some obscure field somewhere, and your xcodeproj files will change in a way you can't understand anyway. "Trust me bro, it worked on my computer", I guess?

Compiling without Xcode is impossible. For Android you can just use gradle (or another build system if you really want), for Apple you have to use Xcode. For scripts or for a CI, you probably want the command line; I find the Xcode CLI extremely bad (I am a Linux person, my favourite kind of UI is CLI, so it's not like I'm confused with CLIs in general).

Talking about CI, you need a macOS machine. That is a pain in itself.

You want to share your app just with a friend? You have to go through TestFlight, send them an invite, and the app will only be available for some days (is it 30 or 90 days?).

Did we talk about SPM that chose to abuse GitHub for distribution? I cannot distribute just a binary, I have to dedicate a repo for that. Wanna use a monorepo? Your Package.swift cannot go into the "swift/" subdirectory, no no: SwiftPM WANTS it at the root of the repo. And SwiftPM will make a complete clone of the whole repo, so all your users will have to download the whole monorepo. People love to hate the Java ecosystem, but Maven solved the package distribution decades ago.

You want to do something with USB? Forget it. Really (don't get me started on MFi). Apple only supports a handful of devices, versus the plethora of Android devices. But still the Android experience is vastly better there: USB has just worked since the very beginning.

I don't know SwiftUI well enough to comment, but the article seems to confirm that it is absolutely consistent with the rest of the developer experience.

And for all that joy, you have to pay 100$/year?

I understand that developers must develop for Apple, because people love their Apple devices. I just don't get it when developer don't hate the Apple developer experience.

Re: SwiftUI After 7 Years

#329
post #256

Earlier quoted context omitted.

I know, that's why I said, that when you hit things like that (state that is too big to pull onto the client at once, and/or displayed at once), React's (and I guess a lot of other immutablity-based frameworks') dataflow management stops being magic, and you have to start tending to it. Which usually means this model loses all advantages compared to simple MVC, or imperative systems, and at worst, becomes another hea…

I guess my point was that it doesn't matter whether your framework/library is immutable/mutable/retained/functional/MVC/MVVM or whatever. You're hitting platform limitations one way or another. But the rest of your app still gets the simplicity of a declarative programming model.

Imo that's a rather nihilistic take. My personal opinion is that despite ungodly amount of money invested, the web has changed very little from the 'static website +maybe jQuery' days - 90% of the content people consume is static, with very little interactivity, that would be perfectly captured by the 'script' nature of Javascript (think 10 line scripts, like 'if hovered, play live preview of video'). Even that interactivity is mostly driven by data that needs to be fetched from the server.

'Web Apps' are the exception, and are more or less completely alien to the rest of the content, think 'flash games' or 'google maps' - which have become 'wasm games on unity on itch.io'.

Having a mostly static web for the former, and the ability to basically almost whatever would be for the best.

Speaking of Flash, the 'cross section' of the two - websites with tons of interactivity and flashy animation have almost disappeared.

The web of today is an unhappy compromise of mediocrity and low expectations.

Re: SwiftUI After 7 Years

#330
post #328

Earlier quoted context omitted.

Excellent question. I have mostly used Apple tools, but have also tried (most notably) VSCode, android studio, zed, Eclipse, vim and Sublime Text. None of these convinced me, except Sublime which I still use for “non-Apple” projects (also non-android, obviously). I also like vim, but not for coding, just as a general text editor. I particularly hate VSCode, for some reason (the reason is not that it comes from M$ if…

Right. For me I think it is a bit more general than "just" the IDE. For a start, it's painful to install the apps I develop on Apple devices: it's limited in number, so once in a while I have to delete the sample apps I installed. Also I need to "trust the developer" for each app, and apparently more than once (everytime I uninstall the app maybe?), and it requires going through an unintuitive path in the settings an…

> it's limited in number, so once in a while I have to delete the sample apps I installed

10, but only for Apple accounts that are not a part of the Apple developer program (99$) AFAIK

> regularly, I have to clean the cache, then clean the hidden cache, then quit Xcode, go and erase some DerivedData, restart Xcode and hope it works

Yes and no… I have been an Apple platform developer for ages, and yes, this has been true for a long time: deleting the derived data was indeed needed way too often (but doing this only has always been enough though, no need to play w/ anything else). The whole build system of Xcode, while powerful, is extremely poorly known (because very poorly documented, obviously), and was, truthfully, unreliable. However, it is getting MUCH better nowadays (and it is also open-sourced; technically they rewrote it in the open from scratch AFAIK). It’s been a long time since I’ve had to delete the derived data tbh. (I still have to close/reopen the project way too often though >Wrt. having to use Xcode, it’s not really true (Xcode only calls other binaries after all), but it is de facto true in the sense that most of the binaries Xcode uses are either internal and/or poorly documented (it’s a theme…).

> Signing is a pain during Apple development.

Honestly haven't have got issues in a while; automatic signing kind of “just works” nowadays. At least for me (and all my teammates).

> You need a development team

No, you can use a standard (free) Apple account, but there are limitations (namely the 10 apps allowed, and the long, difficult(-ish) path to enable it on your phone).

> The Xcode project files are a big mess.

To start off, I’d like to say, having worked (very little) with android studio, I find it as much as a mess as Xcode, if not more.

Once again, poor documentation (you guessed it), and wrong initial implementation (Xcode is very old!) lead to poor practices. Currently, a proper gitignore in an “Apple project” is (not the widely propagated `gitignore` file found on the web):

    xcuserdata/
That’s it. You can add `.DS_Store` if you feel like it, but this should be in a global gitignore, not in the repo.

Other than that the structure of an xcodeproj is relatively straightforward: `project.pbxproj` contains the project references and targets/build settings, then there are a bunch of auxiliary files, those of which that are in a `xchshareddata` folder (basically everything that is not in an `xcuserdata` folder) should be shared. These auxiliary files contains mostly the schemes of the projects (configuration to launch the targets), but there can also be shared breakpoints, the Xcode Cloud manifest, performance tests baselines, etc. And also more recently, SwiftPM files (basically the Package.resolved file) are there.

The central `project.pbxproj` file format is an old plist format. Whatever, it’s just a text files containing reference to other files, basically. One of the big problems we had with this was merge conflicts when two different branches added files to the project. Now Xcode supports “folder references” for code too (long time coming, but we have it now!), so this does not really happen anymore (obviously old projects have to be migrated, but the migration works well).

> You want to change something? Go to the Xcode GUI, change some obscure field somewhere…

Yes, but again also no. Proper projects should use xcconfig files and never touch the GUI, thus leaving the pbxproj file alone. It’s not mandatory, obviously, but it’s way better. Also if you modularize your app using SPM, the config of the modules now resides in the `Package.swift` files, not in the GUI at all anymore.

Other solutions exist, that skip the pbxproj altogether in the committed file, and instead have another file format describing how to generate the pbxproj with a project generator. Honestly, using the folder reference mentioned earlier and xcconfig files solves pretty much all of the issues I ever had with pbxproj, so I truly think it’s overkill. It was useful, though.

> Compiling without Xcode is impossible

Depends. For iOS apps, yes. For everything that do not target being an “Apple app,” no. `swift build -c release` and you’re done. I’m pretty sure even “Apple Apps” will end up being simple modules in the end, but we’re not there yet…

Other than that, yeah, xcodebuild sucks very much, though it is not that complex either.

> Talking about CI, you need a macOS machine. That is a pain in itself.

I would not go so far as to say that it is a pain, but yes.

> You want to share your app just with a friend?

It’s 90 days, and if I’m not mistaken google is also taking this route more and more, no? Locking up the platform, I mean.

> talk about SPM that chose to abuse GitHub for distribution

Not GitHub. Any git repository. It’s not the same at all!

> I cannot distribute just a binary, I have to dedicate a repo for that.

Wrong, at least on Apple platforms, and will be wrong for other platforms later. You can distribute xcframeworks via SPM (but the manifest does indeed have to be at the root of a repo, which is indeed annoying to say the least).

Regarding both latest points, you can also use a custom registry and not use git repositories to setup your dependencies. (Disclaimer: I intend on using that, but have not already.)

Also, if you’re using Xcode (because you can be doing other things than iOS apps with Swift), you can use a workspace to put any dependency you want in it. They are just there, ready to be imported. That way you can have e.g. a submodule with your monorepo and any dependency you want in your Xcode project.

> You want to do something with USB?

No. Never have, never will ^^ But I trust you there (:

Post reply on HN