Swift Tips and Best Practice

From Hawk Wiki
Revision as of 02:13, 17 March 2015 by Hall (Talk | contribs) (Created page with "===NSData(contentWithUrl: url)=== Do not use this for network request. Because it is synchronized and it may block your UI a tens of seconds. ===Run Loop=== It's the main thread ...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

NSData(contentWithUrl: url)

Do not use this for network request. Because it is synchronized and it may block your UI a tens of seconds.

Run Loop

It's the main thread run()

  • Handle UI Input
  • View Drawing
  • Animation
  • More

You have 17ms to do stuff in the main thread.

Threading

If you want to some intensive computation. Use another thread.

NSThread

old method Clumsy and poor. Do not use.

Gran Central Dispatch

  • Abstract thread pool pattern
  • Better performance