草庐IT

anyMethod

全部标签

ios - 没有 self 的自动释放池访问方法中的 Swift 闭包

这是示例代码funcanyMethod(){//Nothinghere}varmyVariable=""autoreleasepool{anyMethod()//Thisshouldshowerrorprint(myVariable)//Thisshouldshowerror}它应该显示错误Calltomethod'anyMethod'inclosurerequiresexplicit'self.'tomakecapturesemanticsexplicit但是我可以在没有self的情况下调用anyMethod,我想知道为什么这不显示错误为什么没有self也能正常工作?编辑复制粘贴这个