iosmacostvosfoundationipados

How expensive NSTimeZone is


How expensive it is to create [NS]TimeZone? Meaning it is cheaper to have a single

static let utc = TimeZone(abbreviation: "UTC")

or have

TimeZone(abbreviation: "UTC")

all over the place (as I see in one MR I;m currently reviewing)


Solution

  • Instantiation of a timezone will not take any noticeable time compared to everything else your app does. You will not see any app performance difference between the 2 in normal use.

    The best thing is to just make sure your code is clean. Don't spray TimeZone(abbreviation: "UTC") through your code, wrap it in a helper method which does what ever date formatting you are doing, and call it from where you need it so you can localize all the date functions in 1 spot.