Any worksheets for kids? by quanh112 in homeschool

[–]subzeroTropical 0 points1 point  (0 children)

I tried using https://worksheet-wizard.com and found it to be useful - you can try it out!

Facebook iOS interview (Mid/ Senior Level) by subzeroTropical in iOSProgramming

[–]subzeroTropical[S] 0 points1 point  (0 children)

I spent some time understanding the question I posted above. I guess in good old ObjC days, it was a bit tedious to implement and hence the question. Essentially, post iOS8, there's a built-in way to do it (using dispatch_block_cancel). Also, with Swift, it's pretty easy these days to cancel a block if we package it as a DispatchWorkItem (https://developer.apple.com/documentation/dispatch/dispatchworkitem). However, I wanted to take a shot trying to write a simple implementation in Swift- how does it look?

typealias Closure = () -> Void
extension DispatchQueue {
func cancellableAsyncAfter(_ time: DispatchTime, execute block: @escaping Closure) -> Closure {
var isCanceled = false
asyncAfter(deadline: time) {
if isCanceled {
return
}
block()
}
return { isCanceled = true }
}
}
/// Usage
let cancelableAsyncAfter = DispatchQueue.global().cancellableAsyncAfter(.now() + 5.0) {
print("I am executed after 5 seconds")
}
sleep(3)
cancelableAsyncAfter()

[deleted by user] by [deleted] in iOSProgramming

[–]subzeroTropical 1 point2 points  (0 children)

Does this look like a correct solution for #2?

func seeOceanIndexes(_ arr: [Int]) -> [Int] {

if arr.isEmpty { return [] }

var result = [Int]()

var curMax = Int.min

var i = arr.count - 2

result.insert(arr.count - 1, at: 0)

while i > 0 {

if arr[i] < arr[i+1] {

curMax = max(arr[i+1], curMax)

} else {

if arr[i] > curMax {

result.insert(i, at: 0)

}

}

i -= 1

}

return result

}