Managing What Happens When
暂无分享,去创建一个
So far in this book, you#x2019;ve made things happen in a fairly regular manner. You send a message to an object, the method corresponding to that message selector runs and then returns, and your code continues. This only scratches the surface of what#x2019;s possible with Objective-C and Cocoa Touch; you can run code later, run two pieces of code at the same time, or run nothing at all until something else happens. In this chapter, we#x2019;ll discuss the specifics of how you manage when your code runs, as well as delving into why it matters. We#x2019;ll cover writing code to take advantage of the latest multicore processors, using timers to repeat the execution of code over time, and run loops, Apple#x2019;s efficient way to wait for events. Along the way, we#x2019;ll cover topics such as thread safety and how to optimize your code for speed. First let#x2019;s discuss what we#x2019;ve done so far in the context of this larger discussion.