Swift compiler can't guarantee a timing of a piece of code in general case aside from some simple specific cases – that would be equivalent to solving the unsolvable halting problem. You can make a language that postulates a maximum cycle count for a given piece of code with some markers and then enforce that limit at runtime via throwing an exception once that limit is reached. The calling context would have to do something with the error, e.g. if this is an audio procedure that must provide audio data some placeholder data would have to be provided, or a flag indicating "can't provide data at this time" returned back to the OS caller Somewhat relevant post.
1 Like