[swift-users] Should a queue be value type or reference type?

Quinn "The Eskimo!" eskimo1 at apple.com
Tue Jul 26 02:36:57 CDT 2016


On 25 Jul 2016, at 15:10, 褚 晓敏 via swift-users <swift-users at swift.org> wrote:

> So what should it be, according to API design guidelines?

It’s hard to answer this question without more information about your specific context.  However, I think it’s safe to say that Swift expresses a preference for value types.  OTOH, reference types exist for a reason: sometimes you really do want to model shared mutable state.

My approach to this is to design the data structure as a value type and see how that works out for clients.  If the client code looks good, you’re set.  OTOH, if the client code is painful, you need to rethink.

Share and Enjoy
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware




More information about the swift-users mailing list