Skip to main content

Thread Safety

QuickLayout is designed to be a powerful and flexible layout engine, allowing you to create complex layouts with ease. One of the key benefits of QuickLayout is its thread safety, which enables you to use it in a variety of scenarios, including concurrent programming.

Layout Algorithm Thread Safety

The layout algorithm itself, including VStack, HStack, frame, padding, and other layout functions, are thread safe. However, the overall threadsafety of any layout operation depends on the threadsafety of leaf elements used in your layout hierarchy. If your layout contains UIView instances, the sizeThatFits and applyFrame methods can only be used on the main thread which means layout overall has to be used on the main thread and attempting to do otherwise will result in a runtime error.

UILabel.Proxy is Not Thread Safe

When using ViewProxies, keep in mind that UILabel.proxy is not thread safe. This is because it uses a shared instance of UILabel to calculate size, which can lead to crashes or unexpected behavior when accessed from multiple threads.