Foundation bug or indended?

Hi there,

before filing a new issue I would like to ask if this is intended behaviour or a bug:

The Foundation class Operation which has it’s roots in Objective-C has a few readonly properties like the following one:

@available(iOS 2.0, *)
open class Operation : NSObject {
    ...
    open var isExecuting: Bool { get }
    ...
}
On the other hand the Objective-C header looks like this:

NS_CLASS_AVAILABLE(10_5, 2_0)
@interface NSOperation : NSObject {
...
@property (readonly, getter=isExecuting) BOOL executing;
...
@end
Now I want to create a custom subclass of Operation and override isExecuting, everything works fine until I try to create a private stored property named executing:

final class TransitionOperation : Operation {
    // error: cannot override with a stored property 'executing'
    private var executing = false

    override var isExecuting: Bool {
        ...
    }
}
I’m a little bit confused here:

Is this intended behaviour or a bug?
The Foundation implemented in Swift is not used for iOS deployment, instead the Obj-C one is used right?

It is intended.
The swift version you provided is the swift version of Objective-C header.
So they are the same.

Zhao Xin

···

On Mon, Sep 4, 2017 at 8:01 PM, Adrian Zubarev via swift-users < swift-users@swift.org> wrote:

Hi there,

before filing a new issue I would like to ask if this is intended
behaviour or a bug:

The Foundation class Operation which has it’s roots in Objective-C has a
few readonly properties like the following one:

@available(iOS 2.0, *)
open class Operation : NSObject {
    ...
    open var isExecuting: Bool { get }
    ...
}

On the other hand the Objective-C header looks like this:

NS_CLASS_AVAILABLE(10_5, 2_0)
@interface NSOperation : NSObject {
...
@property (readonly, getter=isExecuting) BOOL executing;
...
@end

Now I want to create a custom subclass of Operation and override
isExecuting, everything works fine until I try to create a private stored
property named executing:

final class TransitionOperation : Operation {
    // error: cannot override with a stored property 'executing'
    private var executing = false

    override var isExecuting: Bool {
        ...
    }
}

I’m a little bit confused here:

   - Is this intended behaviour or a bug?
   - The Foundation implemented in Swift is not used for iOS deployment,
   instead the Obj-C one is used right?

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

It's semi-intended. When the compiler imports (NS)Operation into Swift, it uses the Swift naming convention…but it also declares a property with the old name, 'executing', in order to give better error messages if someone tries to use the Objective-C name. That's what's colliding with your private 'executing' property.

We should improve this experience on the compiler side, either by having a 'nonoverride' attribute or similar, or just by noting that you wouldn't try to override something with a private property not declared 'override' in the first place. But since the workaround is so simple it hasn't been a priority.

Sorry for the trouble,
Jordan

···

On Sep 4, 2017, at 05:01, Adrian Zubarev via swift-users <swift-users@swift.org> wrote:

Hi there,

before filing a new issue I would like to ask if this is intended behaviour or a bug:

The Foundation class Operation which has it’s roots in Objective-C has a few readonly properties like the following one:

@available(iOS 2.0, *)
open class Operation : NSObject {
    ...
    open var isExecuting: Bool { get }
    ...
}
On the other hand the Objective-C header looks like this:

NS_CLASS_AVAILABLE(10_5, 2_0)
@interface NSOperation : NSObject {
...
@property (readonly, getter=isExecuting) BOOL executing;
...
@end
Now I want to create a custom subclass of Operation and override isExecuting, everything works fine until I try to create a private stored property named executing:

final class TransitionOperation : Operation {
    // error: cannot override with a stored property 'executing'
    private var executing = false

    override var isExecuting: Bool {
        ...
    }
}
I’m a little bit confused here:

Is this intended behaviour or a bug?
The Foundation implemented in Swift is not used for iOS deployment, instead the Obj-C one is used right?

_______________________________________________
swift-users mailing list
swift-users@swift.org <mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users