dynamic requires @objc in Framework, but not in monolithic project

I have an iOS app in which I'm factoring out code into a Framework. In Xcode 9 GM (Swift 4), the code builds fine when it's a monolithic app, but some of the files I've pulled into the framework are no longer compiling. One of the errors is:

Model.swift:471:14: 'dynamic' var 'dateCreated' must also be '@objc'

The class looks like:

import Foundation

class
MPObject : NSObject
{
    ....
    dynamic var dateCreated : Date?
    ....
}

If I add @objc to each dynamic member, it seems to silence the errors, but the @objc should be implicit due to inheriting from NSObject, and as I said, it builds without error as a monolithic app.

···

--
Rick Mann
rmann@latencyzero.com

When you create a new project in Xcode 9, the defaults for compiler settings are different. The errors you see are the result of running in full (strict) Swift 4.0 mode which has some such breaking changes.

···

On Sep 13, 2017, at 3:56 PM, Rick Mann via swift-users <swift-users@swift.org> wrote:

I have an iOS app in which I'm factoring out code into a Framework. In Xcode 9 GM (Swift 4), the code builds fine when it's a monolithic app, but some of the files I've pulled into the framework are no longer compiling. One of the errors is:

Model.swift:471:14: 'dynamic' var 'dateCreated' must also be '@objc'

The class looks like:

import Foundation

class
MPObject : NSObject
{
   ....
   dynamic var dateCreated : Date?
   ....
}

If I add @objc to each dynamic member, it seems to silence the errors, but the @objc should be implicit due to inheriting from NSObject, and as I said, it builds without error as a monolithic app.

--
Rick Mann
rmann@latencyzero.com

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

Ah. That's the difference. Okay.

Nevertheless, the Apple docs on the matter are unclear at best (Swift | Apple Developer Documentation):

"Declarations marked with the dynamic modifier must also be explicitly marked with the @objc attribute unless the @objc attribute is implicitly added by the declaration’s context. For information about when the @objcattribute is implicitly added, see Declaration Attributes in The Swift Programming Language (Swift 4)."

The referenced doc has a lot of stuff, so it's hard to zero in on the discussion of implicit-objc, but there's this:

"The compiler implicitly adds the objc attribute to subclasses of any class defined in Objective-C."

To me, this means that my NSObject-derived class is implicitly @objc, and so the members within it (the declaration context) shouldn't need @objc as well.

To help me understand better, can you have dynamic without an implicit or explicit @objc? It seems not, and if not, why isn't it enough for dynamic to then just imply @objc to the compiler?

Thanks,
Rick

···

On Sep 13, 2017, at 17:06 , Hooman Mehr <hooman@mac.com> wrote:

When you create a new project in Xcode 9, the defaults for compiler settings are different. The errors you see are the result of running in full (strict) Swift 4.0 mode which has some such breaking changes.

On Sep 13, 2017, at 3:56 PM, Rick Mann via swift-users <swift-users@swift.org> wrote:

I have an iOS app in which I'm factoring out code into a Framework. In Xcode 9 GM (Swift 4), the code builds fine when it's a monolithic app, but some of the files I've pulled into the framework are no longer compiling. One of the errors is:

Model.swift:471:14: 'dynamic' var 'dateCreated' must also be '@objc'

The class looks like:

import Foundation

class
MPObject : NSObject
{
  ....
  dynamic var dateCreated : Date?
  ....
}

If I add @objc to each dynamic member, it seems to silence the errors, but the @objc should be implicit due to inheriting from NSObject, and as I said, it builds without error as a monolithic app.

--
Rick Mann
rmann@latencyzero.com

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

--
Rick Mann
rmann@latencyzero.com

Documentation is behind the actual state.

What you see is the result of this change: SE-0160 Limiting @objc inference <https://github.com/apple/swift-evolution/blob/master/proposals/0160-objc-inference.md&gt;

···

On Sep 13, 2017, at 5:18 PM, Roderick Mann <rmann@latencyzero.com> wrote:

Ah. That's the difference. Okay.

Nevertheless, the Apple docs on the matter are unclear at best (Swift | Apple Developer Documentation):

"Declarations marked with the dynamic modifier must also be explicitly marked with the @objc attribute unless the @objc attribute is implicitly added by the declaration’s context. For information about when the @objcattribute is implicitly added, see Declaration Attributes in The Swift Programming Language (Swift 4)."

The referenced doc has a lot of stuff, so it's hard to zero in on the discussion of implicit-objc, but there's this:

"The compiler implicitly adds the objc attribute to subclasses of any class defined in Objective-C."

To me, this means that my NSObject-derived class is implicitly @objc, and so the members within it (the declaration context) shouldn't need @objc as well.

To help me understand better, can you have dynamic without an implicit or explicit @objc? It seems not, and if not, why isn't it enough for dynamic to then just imply @objc to the compiler?

Thanks,
Rick

On Sep 13, 2017, at 17:06 , Hooman Mehr <hooman@mac.com> wrote:

When you create a new project in Xcode 9, the defaults for compiler settings are different. The errors you see are the result of running in full (strict) Swift 4.0 mode which has some such breaking changes.

On Sep 13, 2017, at 3:56 PM, Rick Mann via swift-users <swift-users@swift.org> wrote:

I have an iOS app in which I'm factoring out code into a Framework. In Xcode 9 GM (Swift 4), the code builds fine when it's a monolithic app, but some of the files I've pulled into the framework are no longer compiling. One of the errors is:

Model.swift:471:14: 'dynamic' var 'dateCreated' must also be '@objc'

The class looks like:

import Foundation

class
MPObject : NSObject
{
....
dynamic var dateCreated : Date?
....
}

If I add @objc to each dynamic member, it seems to silence the errors, but the @objc should be implicit due to inheriting from NSObject, and as I said, it builds without error as a monolithic app.

--
Rick Mann
rmann@latencyzero.com

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

--
Rick Mann
rmann@latencyzero.com <mailto:rmann@latencyzero.com>

Very helpful, thank you.

···

--
Rick Mann
rmann@latencyzero.com

On Sep 13, 2017, at 21:24, Hooman Mehr <hooman@mac.com> wrote:

Documentation is behind the actual state.

What you see is the result of this change: SE-0160 Limiting @objc inference

On Sep 13, 2017, at 5:18 PM, Roderick Mann <rmann@latencyzero.com> wrote:

Ah. That's the difference. Okay.

Nevertheless, the Apple docs on the matter are unclear at best (Swift | Apple Developer Documentation):

"Declarations marked with the dynamic modifier must also be explicitly marked with the @objc attribute unless the @objc attribute is implicitly added by the declaration’s context. For information about when the @objcattribute is implicitly added, see Declaration Attributes in The Swift Programming Language (Swift 4)."

The referenced doc has a lot of stuff, so it's hard to zero in on the discussion of implicit-objc, but there's this:

"The compiler implicitly adds the objc attribute to subclasses of any class defined in Objective-C."

To me, this means that my NSObject-derived class is implicitly @objc, and so the members within it (the declaration context) shouldn't need @objc as well.

To help me understand better, can you have dynamic without an implicit or explicit @objc? It seems not, and if not, why isn't it enough for dynamic to then just imply @objc to the compiler?

Thanks,
Rick

On Sep 13, 2017, at 17:06 , Hooman Mehr <hooman@mac.com> wrote:

When you create a new project in Xcode 9, the defaults for compiler settings are different. The errors you see are the result of running in full (strict) Swift 4.0 mode which has some such breaking changes.

On Sep 13, 2017, at 3:56 PM, Rick Mann via swift-users <swift-users@swift.org> wrote:

I have an iOS app in which I'm factoring out code into a Framework. In Xcode 9 GM (Swift 4), the code builds fine when it's a monolithic app, but some of the files I've pulled into the framework are no longer compiling. One of the errors is:

Model.swift:471:14: 'dynamic' var 'dateCreated' must also be '@objc'

The class looks like:

import Foundation

class
MPObject : NSObject
{
....
dynamic var dateCreated : Date?
....
}

If I add @objc to each dynamic member, it seems to silence the errors, but the @objc should be implicit due to inheriting from NSObject, and as I said, it builds without error as a monolithic app.

--
Rick Mann
rmann@latencyzero.com

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

--
Rick Mann
rmann@latencyzero.com