Uploaded image for project: 'Swift'
  1. Swift
  2. SR-9044

Mutated CharacterSet bridges to Obj-C as NSMutableCharacterSet

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Foundation
    • Labels:
      None
    • Environment:

      Apple Swift version 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1)
      Target: x86_64-apple-darwin18.0.0

      Description

      After mutating a CharacterSet it's backed internally by an NSMutableCharacterSet. In this case, it turns out that bridging to Obj-C just returns the backing NSMutableCharacterSet without copying it, and so mutations to this returned NSMutableCharacterSet actually mutate the original CharacterSet.

      import Foundation
      var cs = CharacterSet(charactersIn: "foo")
      cs.insert(charactersIn: "bar")
      (cs as! NSMutableCharacterSet).addCharacters(in: "x")
      print(cs.contains("x")) // should be false, prints true
      

      Unfortunately, fixing this will have performance implications on any code that has to bridge it to Obj-C, especially if it does so repeatedly.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              lily Lily Ballard
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: