Ivan
Ivan

Reputation: 1444

Cannot find 'isUniquelyReferencedNonObjC' in scope

import Foundation

final class Ref<T> {
  var val : T
  init(_ v : T) {val = v}
}

struct Box<T> {
    var ref : Ref<T>
    init(_ x : T) { ref = Ref(x) }

    var value: T {
        get { return ref.val }
        set {
          if (!isUniquelyReferencedNonObjC(&ref)) {
            ref = Ref(newValue)
            return
          }
          ref.val = newValue
        }
    }
}

Why doesn't the code above compile with "Cannot find 'isUniquelyReferencedNonObjC' in scope" error?

Upvotes: 0

Views: 336

Answers (1)

loverap007
loverap007

Reputation: 139

Looks like isUniquelyReferencedNonObjC is deprecated in swift 5

You must use isKnownUniquelyReferenced(_:) for copy on write optimization.

Apple docs has an examples of code for your case.

Upvotes: 1

Related Questions