Introducing Simple Layout Engine
Note: This is a Swift rewrite of the original article published in 2020
Note: This is a Swift rewrite of the original article published in 2020
The maths required for SwiftUI custom layout reminds me of the days before AutoLayout and the constraints based system. The good thing is that Simple Layout Engine already provides a nice system to handle all the maths involved. To demonstrate I would use build the subset of the demo app from the WWDC session on this topic: Compose custom layouts with SwiftUI.
UnfairLock
seems to be causing a lot of confusion for Swift developers. Every once in a while I run across some incorrect implementation that reads like:
About mixing UIScrollView
with MTKView
. This is the trick I learned from WWDC 2012 Enhancing User Experience with Scroll Views session that talks about mixing UIScrollView
with OpenGL. The idea is to simply use the MTKView
to render whatever metal content we would like and then use the UIScrollView
to provide with the scrolling effect. The benefit of using UIScrollView
is that we get exactly the same dragging and bounciness behavior that iOS users expect.
Swift in a sense is very much like C++, and when I say C++ I mean C++11 and beyond. One could also say that Swift is cleaner C++, or C++ without the backwards compatibility baggage from the 80s. To give an idea here’s a minimal modern C++ code: