@christianselig@mastodon.social avatar

christianselig

@christianselig@mastodon.social

iOS developer, creator of Apollo and Pixel Pals. Previously at . he/him. i love animals. 🌱

This profile is from a federated server and may be incomplete. Browse more on the original instance.

christianselig, to random
@christianselig@mastodon.social avatar
christianselig,
@christianselig@mastodon.social avatar

@Mister_Eel Scratch!

christianselig,
@christianselig@mastodon.social avatar

@lkngrrr I picked up some 110/18 needles and nylon bonded thread per a video recommendation, I'm hoping this works haha

christianselig, to random
@christianselig@mastodon.social avatar

SwiftUI noob question: I understand why my ViewModel is being initialized twice, but why is it not being deinitialized?

It's created, then a second later when appState.show is changed, the view is recomputed, and view, and its ViewModel, are created anew. Cool! But why is the old one not deinitialized? What's holding onto it?

Sample code: https://gist.github.com/christianselig/d88b1a4d1989b973689ae62d4691162f

christianselig,
@christianselig@mastodon.social avatar

@tclementdev Your guess is as good as mine, this stuff continually confuses me :p

christianselig,
@christianselig@mastodon.social avatar

@jonduenas It shows both as still being in memory, but the references are nothing I can comprehend

christianselig,
@christianselig@mastodon.social avatar

@marcpalmer Unfortunately not, changing it to something simple like a Button yields the same effect :(

christianselig,
@christianselig@mastodon.social avatar

@rockbart So they're just created willy nilly for no reason, and also not deallocated? lol

But also, why wouldn't recreating SpecialView recreate the ViewModel as well, isn't it just bound to the "instance" of the SpecialView?

christianselig,
@christianselig@mastodon.social avatar

@ryanashcraft I'm glad someone appreciates them :p And this code is as fascinating as it is weird, this feels kinda wrong, doesn't it?

christianselig,
@christianselig@mastodon.social avatar

@landonepps It's more so that it's effectively a memory leak, if my ViewModel is somewhat heavy having extra occurrences of it just kicking around is… not ideal

christianselig,
@christianselig@mastodon.social avatar

Hey, this is my first SwiftUI noob question where people are like "Dang… that is kinda weird". I feel like that is somewhat of an accomplishment

christianselig,
@christianselig@mastodon.social avatar

@shadowfacts @harshil The weird thing though is that the second initialization doesn’t even appear to be used. Is that part expected? Or given that it’s not deduped the expectation is just to ignore unnecessary allocations?

christianselig,
@christianselig@mastodon.social avatar

@shadowfacts @harshil Ah ha, so on consecutive (say, fifth, sixth, seventh invocations), it just would overwrite the "second" one, while the "true" first one continues to be the de facto instance that is actually used?

christianselig,
@christianselig@mastodon.social avatar

@BenRiceM how do you block in ivory

christianselig,
@christianselig@mastodon.social avatar

@tclementdev With more digging it seems like it's weirdly intended behavior? https://iosdev.space/@alpennec/112472185803890091

christianselig,
@christianselig@mastodon.social avatar

@tjadejong Seems like weirdly intended behavior ;_; https://iosdev.space/@alpennec/112472185803890091

christianselig,
@christianselig@mastodon.social avatar

So basically it seems like a weird choice of the new Observation framework, in that @​State doesn't use an autoclosure like @​StateObject (which allows it to be smarter about duplicates), which is unfortunate design and causes @​State to create instances without really needing to, but it’s at least documented with a weird workaround

My ViewModel is a bit heavy so having them be randomly allocated is kinda rough

So, back to StateObject I go (for this at least)!

https://iosdev.space/@alpennec/112472185803890091

christianselig,
@christianselig@mastodon.social avatar

@kenryall @tclementdev @alpennec I'm fine with the view being created willy nilly, but I didn't expect the State objects that are supposed to persist between recreations to also be recreated

christianselig,
@christianselig@mastodon.social avatar

@groue @alpennec I will not attempt to trivialize the work Apple does internally because I'm sure this stuff is complicated with a lot of moving parts

Butttttttttt… damn I wish this was how Apple did it 😅

christianselig,
@christianselig@mastodon.social avatar

@mikaelacaron It's definitely possible. It seems the secondary (and tertiary…) creations are just created and never do anything, so it's not like your initial state/creation is thrown out or anything, but if your initializer modifies global state or something it could be causing something nasty D:

christianselig,
@christianselig@mastodon.social avatar

@Drarok The opposite! State should be able to do everything StateObject does and replace it as of iOS 17 with the new Observation framework. It brings niceties like nested observation, so unlike StateObject if a property of your observed object changes internally that can also trigger a change in your view, which is really handy

christianselig,
@christianselig@mastodon.social avatar

@mikaelacaron Ahh, sign in issues are my least favorite bugs to work with, I feel for you 😢 I'd be peppering print statements everywhere lol

christianselig,
@christianselig@mastodon.social avatar

@malhal @alpennec @rockbart @shadowfacts @harshil Ah nice! @groue did something similar, nice to see people in the community fixing holes in the framework :D https://hachyderm.io/@groue/112320846092536694

christianselig, to random
@christianselig@mastodon.social avatar

iPhone 15 Pro’s been my best battery performer by a mile, damn. All MagSafe charging too pretty much

christianselig,
@christianselig@mastodon.social avatar

@justindumlao Dang, nice, I hope to still be at that 100% in another 30 charging cycles

christianselig, to random
@christianselig@mastodon.social avatar

Dumb question, but if I bought one of those "MagSafe stickers" on Amazon, that are traditionally used to give an Android phone MagSafe-like-stickiness, could I instead use it in reverse, and stick it to a non-MagSafe accessory so it would stick to my iPhone?

For instance, say I want to stick it to a banana so the banana magnets to my phone

christianselig,
@christianselig@mastodon.social avatar

@dwineman Damn, this is the ultimate answer! Thank you!

christianselig, to random
@christianselig@mastodon.social avatar

Choosing a travel backpack is really hard, and I still haven't found one I love, so mostly for my own reference I wrote a long post with thoughts on pretty much every travel backpack out there https://christianselig.com/2024/04/choosing-a-backpack-is-hard/

If you have other recommendations gimme

christianselig,
@christianselig@mastodon.social avatar

@phneutral No external water bottle holder is an immediate no go for me unfortunately :(

  • All
  • Subscribed
  • Moderated
  • Favorites
  • JUstTest
  • kavyap
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • osvaldo12
  • khanakhh
  • Youngstown
  • mdbf
  • slotface
  • rosin
  • everett
  • ngwrru68w68
  • Durango
  • anitta
  • InstantRegret
  • GTA5RPClips
  • cubers
  • ethstaker
  • normalnudes
  • tacticalgear
  • cisconetworking
  • tester
  • Leos
  • modclub
  • megavids
  • provamag3
  • lostlight
  • All magazines