Modify Accessors

As this thread approaches its 2nd birthday :partying_face::birthday:, a quick summary of where thing stand:

  • (ABI stable) The standard library makes extensive use of _modify
  • (ABI stable) Foundation's new AttributedString makes use of _modify
  • (ABI stable) swift-system's FilePath.ComponentView makes use of _modify
  • swift-collections makes use of _modify (just one example, there are many)
  • swift-nio tries to do the right thing and has a modify method instead :pleading_face:. Bless 'em.

In my own projects, I of course avoid underscored functions or attributes, because they technically are not stable and could disappear or change semantics without notice. The only exception is _modify. Unlike most underscored features, using _modify accessors in third-party code is well within the realm of "acceptable risk" IMHO.

It's critical to many API designs, and used so extensively (by ABI stable libraries, no less), that the chance of it being removed or suddenly becoming incompatible with current behaviour is basically zero.

26 Likes