Doubts on concurrency with objects that can be used multiple times like formatters

前端 未结 1 400
清酒与你
清酒与你 2021-01-13 02:35

Maybe a stupid question to ask but I need some confirmations on it.

Usually, when I deal with objects that can be used multiple times within my application I use an

相关标签:
1条回答
  • 2021-01-13 02:41

    NSNumberFormatter is mutable, so it is generally not thread safe and cited in Thread Safety Summary (see the "Thread-Unsafe Classes" section) in the non thread safe classes list.

    But if you treat your object as an immutable object, you don't have to worry about race conditions. So for example, you cannot change the format if there are multiple threads accessing the formatter. If _internal_numberFormatter isn't altered in any way, and you have just these two methods in the category, you should consider it thread safe.

    0 讨论(0)
提交回复
热议问题