I'm making a UITableView which display image created from processed data.
This processing task is too heavy, I decide to declare an array type instance variable of UITableView class and create an operation per one processing task.
Because Every results would be stored into separate memory space identified by index, I thought It is thread-safe.
A Short version example:
class TestOperation: Operation {
var pi: [Int?];
override var isExecuting: Bool { ... }
override var isFinished: Bool { ... }
init(_ p: inout [Int?]) {
pi = p;
}
override func start() {
if pi[0] == nil {
pi[0] = 0;
} else if pi[1] == nil {
pi[1] = 1;
} else {
pi[2] = 2;
}
}
}
class Root {
var sharedArr: [Int?];
var queue: OperationQueue;
init() {
sharedArr = Array(repeating: nil, count: 3);
queue = OperationQueue.init();
for _ in 0...2 {
let operation = TestOperation.init(&sharedArr);
queue.addOperation(operation);
}
}
}
Root.init();
I expected sharedArr
to change, But all I get is array of nil. Is there anything I can try?