在我的快速项目中,我有一种情况,我使用协议继承如下
protocol A : class{
}
protocol B : A{
}
Run Code Online (Sandbox Code Playgroud)
我接下来要实现的是声明另一个具有关联类型的协议,该类型必须从protocol继承A。如果我尝试将其声明为:
protocol AnotherProtocol{
associatedtype Type : A
weak var type : Type?{get set}
}
Run Code Online (Sandbox Code Playgroud)
它在编译时没有错误,但是AnotherProtocol在以下情况下尝试采用时:
class SomeClass : AnotherProtocol{
typealias Type = B
weak var type : Type?
}
Run Code Online (Sandbox Code Playgroud)
编译失败,SomeClass并声明与不一致的错误AnotherProtocol。如果我正确理解这一点,则意味着Im在尝试声明并询问如何声明从协议继承的关联类型时B
不采用?AA
我基于以下情况进行编译的事实做出了上述假设
class SomeDummyClass : B{
}
class SomeClass : AnotherProtocol{
typealias Type = SomeDummyClass
weak var type : Type?
}
Run Code Online (Sandbox Code Playgroud) 我是Swift的新手,我想知道是否有人可以帮助确认我在Apple的Swift中发布对象的理解?
这里CGPathCreateWithRect()描述的文档说明返回值是
"一条新的,不可变的路径.你有责任释放这个对象."
什么时候说"你有责任"就像说当你不再持有引用时垃圾收集器将删除对象一样简单?即你负责管理参考资料?在哪种情况下 - 是不是很明显?如果不是 - 这是什么意思?
谢谢
拜伦