[swift-users] Non-objc protocol inheritance from objc protocol

Pavel Ivashkov m8r67csx6+swiftusers at gmail.com
Sun Feb 5 05:14:09 CST 2017


Hello,

What is the current view on inheriting non-objc protocol from objc
protocol? Is it supported? Is it a valid construct?


import Foundation

@objc protocol Base {}

protocol Some : Base {}

class Nada : NSObject, Some {}

let x: NSObject = Nada()

print("Nada is Some? \(x is Some)")
print("Nada is Base? \(x is Base)")


There are two statements in the docs on @objc attribute:
a) The compiler also implicitly adds the objc attribute to a class that
inherits from another class marked with the objc attribute or a class
defined in Objective-C.
b) Protocols marked with the objc attribute can’t inherit from protocols
that aren’t.

But they don't spec the other way round about protocols.


Currently the output is

swift main.swift
Nada is Some? true
Nada is Base? false

Which is not what I would expect.

Here is extended example: http://stackoverflow.com/q/42023977

swift --version
Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
Target: x86_64-apple-macosx10.9

(same on 3.1-dev)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170205/cd60a740/attachment.html>


More information about the swift-users mailing list