I am creating a number of subpaths in an CGMutablePath
object for use by CAShapeLayer
.
What works:
- Creating a number of subpaths sequentially.
- Making a single subpath utilizing
withTaskGroup
.
What would not work:
Creating a number of subpaths utilizing withTaskGroup
.
struct MyObject {
var body: CGRect
}
let path = CGMutablePath()
path.addRect(CGRect(origin: .zero, dimension: UIScreen.predominant.bounds.dimension))
let outcome = await withTaskGroup(of: MyObject.self,
returning: [MyObject].self) {
@MainActor [weak self] (taskGroup: inout TaskGroup<MyObject>) async -> [MyObject] in
var outcome = [MyObject]()
for merchandise in objects {
taskGroup.addTask { @MainActor in
let myObject = await self?.createMyObject(param: merchandise)
path.addRect(myObject.body)
return myObject
}
}
guard !taskGroup.isEmpty else {
return []
}
for await myObject in taskGroup {
outcome.append(myObject)
}
return outcome
}
let maskLayer = CAShapeLayer()
maskLayer.path = path
maskLayer.fillRule = .evenOdd
maskView.layer.masks = maskLayer
When a single subpath is added utilizing addRect
, a cutout from the maskView
is seen. Nevertheless, when a number of subpaths are added utilizing withTaskGroup
, no cutouts are seen.