草庐IT

self-referencing

全部标签

generics - 使用 Self 作为通用类型

Self可以用作方法的返回类型:funcdoSomething()->Self{}是否可以以某种方式将Self用作像这样的泛型类型?funcdoSomething()->Wrapper{}示例如果我可以将ChristmasPresent子类化并让它有一个wrapped函数返回一个WrappedPresent并且泛型设置为子类是什么,那就太好了。classChristmasPresent{funcwrapped()->WrappedPresent{returnWrappedPresent(present:self)}}classWrappedPresent{varpresent:Tini

generics - 使用 Self 作为通用类型

Self可以用作方法的返回类型:funcdoSomething()->Self{}是否可以以某种方式将Self用作像这样的泛型类型?funcdoSomething()->Wrapper{}示例如果我可以将ChristmasPresent子类化并让它有一个wrapped函数返回一个WrappedPresent并且泛型设置为子类是什么,那就太好了。classChristmasPresent{funcwrapped()->WrappedPresent{returnWrappedPresent(present:self)}}classWrappedPresent{varpresent:Tini

ios - 属性 'self.*' 未在 super.init 调用时初始化

我刚刚将我的xcode更新到6.3.1。问题是我从Swift1.2开始收到这个奇怪的错误消息。我收到了这种错误信息/Users/MNurdin/Documents/iOS/xxxxx/Library/SideBar.swift:32:15:Property'self.originView'notinitializedatsuper.initcall/Users/MNurdin/Documents/iOS/xxxxx/Library/SideBar.swift:38:20:Immutablevalue'self.originView'mayonlybeinitializedonce关于这

ios - 属性 'self.*' 未在 super.init 调用时初始化

我刚刚将我的xcode更新到6.3.1。问题是我从Swift1.2开始收到这个奇怪的错误消息。我收到了这种错误信息/Users/MNurdin/Documents/iOS/xxxxx/Library/SideBar.swift:32:15:Property'self.originView'notinitializedatsuper.initcall/Users/MNurdin/Documents/iOS/xxxxx/Library/SideBar.swift:38:20:Immutablevalue'self.originView'mayonlybeinitializedonce关于这

swift - 非最终类中的方法必须返回 `Self` 以符合协议(protocol)

在协议(protocol)扩展中实现返回Self的静态协议(protocol)函数时,在扩展中函数的实现中出现错误(显示没有上下文的最小简化场景):importFoundationprotocolP{staticfuncf()->Selfstaticfuncg()->Self}extensionP{staticfuncf()->Self{//Method'f()'innon-finalclass'NSData'mustreturn`Self`toconformtoprotocol'P'returng()}}extensionNSData:P{staticfuncg()->Self{re

swift - 非最终类中的方法必须返回 `Self` 以符合协议(protocol)

在协议(protocol)扩展中实现返回Self的静态协议(protocol)函数时,在扩展中函数的实现中出现错误(显示没有上下文的最小简化场景):importFoundationprotocolP{staticfuncf()->Selfstaticfuncg()->Self}extensionP{staticfuncf()->Self{//Method'f()'innon-finalclass'NSData'mustreturn`Self`toconformtoprotocol'P'returng()}}extensionNSData:P{staticfuncg()->Self{re

swift - 为什么闭包在 Swift 3 中默认都是非转义的而需要显式的 `self`?

我注意到在Swift2.2中,使用@noescape标记为非转义的闭包不需要显式的self。在Swift3中,默认情况下所有闭包都是非转义的,现在如果您希望它们能够转义,则需要使用@escaping标记它们。鉴于默认情况下Swift3中的所有闭包都是非转义的,为什么它们需要显式的self?finalclassSomeViewController:NSViewController{varsomeClosure:()->()={_in}overridefuncviewDidLoad(){super.viewDidLoad()someClosure={view.layer=CALayer()

swift - 为什么闭包在 Swift 3 中默认都是非转义的而需要显式的 `self`?

我注意到在Swift2.2中,使用@noescape标记为非转义的闭包不需要显式的self。在Swift3中,默认情况下所有闭包都是非转义的,现在如果您希望它们能够转义,则需要使用@escaping标记它们。鉴于默认情况下Swift3中的所有闭包都是非转义的,为什么它们需要显式的self?finalclassSomeViewController:NSViewController{varsomeClosure:()->()={_in}overridefuncviewDidLoad(){super.viewDidLoad()someClosure={view.layer=CALayer()

swift - 协议(protocol)扩展中的 'where self' 是什么

我看到了很多格式如下的例子extensionProtocolnamewhereSelf:UIViewController协议(protocol)扩展中的whereSelf是什么。我找不到这方面的文档。 最佳答案 语法是:https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html#//apple_ref/doc/uid/TP40014097-CH25-ID521考

swift - 协议(protocol)扩展中的 'where self' 是什么

我看到了很多格式如下的例子extensionProtocolnamewhereSelf:UIViewController协议(protocol)扩展中的whereSelf是什么。我找不到这方面的文档。 最佳答案 语法是:https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html#//apple_ref/doc/uid/TP40014097-CH25-ID521考