[swift-users] dynamic requires @objc in Framework, but not in monolithic project

Rick Mann rmann at latencyzero.com
Wed Sep 13 23:34:12 CDT 2017


Very helpful, thank you. 

-- 
Rick Mann
rmann at latencyzero.com

> On Sep 13, 2017, at 21:24, Hooman Mehr <hooman at 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 at latencyzero.com> wrote:
>> 
>> Ah. That's the difference. Okay.
>> 
>> Nevertheless, the Apple docs on the matter are unclear at best (https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html):
>> 
>> "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 at 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 at 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 at latencyzero.com
>>>> 
>>>> 
>>>> _______________________________________________
>>>> swift-users mailing list
>>>> swift-users at swift.org
>>>> https://lists.swift.org/mailman/listinfo/swift-users
>>> 
>> 
>> 
>> -- 
>> Rick Mann
>> rmann at latencyzero.com
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170913/e78a6541/attachment.html>


More information about the swift-users mailing list