Swift: Object that explodes into smaller objects

I was wondering if anyone knows of a good tutorial or how2 on how one creates an object in swift that will upon contact explodes into smaller objects.

My intention here is to use the smaller objects for splash damage.... anyone know of a good tutorial?

There is no physics engines on Swift yet. And it is sad, because Rust has neat https://nphysics.org for example.

On the contrary, there are at least 3: UIKit Dynamics for UI animation, and the physics in SpriteKit and SceneKit respectively. The latter is probably used in ARKit as well. All of them are really nice to work with.

But SpriteKit and SceneKit requires a class infrastructure, and a root class object as I know. And big knowledge about how they works.

Well yes, but why does that disqualify them? As far as physics engines go, they are very easy to use, did you look at something like Box2d or Chipmunk2d?

Well, the main problem is the reference semantics of those engines. You cannot define your own element, for example a brick, as a structure. Instead, for building a brick wall you have to create a hundreds of breaks references and follow their lifecycle through your game process and so on.

I’m sorry but I still don’t quite understand the problem with dealing with class objects. That is just how these frameworks are designed, and they are very well made.

Hm. For big projects it is a good design I agree. But what if I would have a quick and compact function, as OP described, which takes a set of values, makes calculates, and returns the set of values with new positions, frame by frame. Then I would take that set and transfer it to a graphic conveyor.

You can do that with structs or classes. Still not understanding your point.

It sounds like you want a physics engine that is separate from a renderer, maybe then the ones in SpriteKit and SceneKit are not ideal - I never tried using them that way and haven't used either in years. You can do that with UIKit Dynamics, but it's not really made for hundreds of small objects.

And still, this requirement seems pretty orthogonal to the reference vs value type question.

Btw unless you want the pieces to bump into each other, it's very simple to make your own physics engine that can handle forces etc, it's the hit testing that is hard.