1

On a MacBook, running macOS 10.15.7 with Xcode 12.1, I wrote some classes in Swift that look like the following:

class A {
    @objc private var value: NSNumber {
        get { ... }
        set { ... }
    }
}

class B: A {
    @objc private var value: String {
        get { ... }
        set { ... }
    }
}

The property is marked @objc so I can bind an input to it. The code compiles and runs perfectly fine without issue, with the input properly binding to the value for either class, and I committed it to my repository.

I later checked out the repository on an iMac, also running macOS 10.15.7 with Xcode 12.1, and it refuses to compile with the following errors:

Getter for 'value' with Objective-C selector 'value' conflicts with getter for 'value' from superclass 'A' with the same Objective-C selector

Setter for 'value' with Objective-C selector 'setValue:' conflicts with setter for 'value' from superclass 'A' with the same Objective-C selector

Why am I getting the errors on one computer but not another, with the exact same project and software?? I'm sure I could rework it somehow to avoid the error, but it would be annoying to do so, especially when I don't really understand why I should rework it, given that it works fine on one machine.

Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
Gannet
  • 1,315
  • 13
  • 18
  • I would expect a compiler error, compare https://stackoverflow.com/q/29457720/1187415. – Did you try to clean the build on your first computer? Does it still compile? – Martin R Oct 27 '20 at 20:28
  • @MartinR I'm no Swift expert so while I don't know whether things should or shouldn't error, my only argument as to why it shouldn't error is that I've marked them as private so (in my mind) they shouldn't have any effect on each other. But yes, I have done a clean build on the first computer and it still works. – Gannet Oct 27 '20 at 20:43

0 Answers0