zoukankan      html  css  js  c++  java
  • Cannot subclass a class with objc_subclassing_restricted attribute

    Unfortunately, that is the case. You cannot subclass a Swift class (even if it is a subclass of NSObject and available to the Objective-C runtime) because of deliberate limitations baked into Obj-C to block subclassing Swift classes in Obj-C code.

    I believe the reason for this limitation is that Swift includes features that cannot be utilised in Obj-C and therefore subclasses would be restricted and would get undefined behaviour when implementing methods that cannot cross into Obj-C.

    If Apple were to allow Obj-C -> Swift -> Obj-C subclassing, then it would be on a limited basis. Some methods wouldn’t do the same thing in Swift as they would in Obj-C selectors, and you could theoretically declare conflicting methods in your subclass that would have different actions depending on whether you were addressing the class in Swift and Obj-C. Additionally, the Swift Compiler couldn’t see beyond the Swift barrier and therefore may make optimisations that would break your Obj-C subclasses.

    While I understand the frustration behind this, both in personal projects and philosophically, I think that this is unfortunately the better of the two options.

    摘自:https://forums.swift.org/t/cannot-subclass-a-class-with-objc-subclassing-restricted-attribute/5674

    结论:OC里无法继承Swift类,即使Swift是@objc open 修饰也不行。(2021.07.18 记录)

  • 相关阅读:
    正则表达式的贪婪匹配(.*)和非贪婪匹配(.*?)
    jQuery + css 公告从左往右滚动
    C# process 使用方法
    存储过程与SQL的结合使用
    img标签的方方面面
    kibana 5.0.0-alpha5 安装
    es5.0 v5.0.0-alpha 编译安装
    奇怪的hosts文件
    阿里云 api 的文档拼写错误
    centos 7 systemd docker http proxy
  • 原文地址:https://www.cnblogs.com/akiha/p/15026649.html
Copyright © 2011-2022 走看看