草庐IT

self-documenting-code

全部标签

swift - 协议(protocol)中的 self

我正在学习Swift并使用Xcode。我总是深入研究定义。我看到了:publicprotocolGeneratorType{typealiasElement@warn_unused_resultpublicmutatingfuncnext()->Self.Element?}一个符合这个协议(protocol)的结构体:publicstructIndexingGenerator:GeneratorType,SequenceType{publicinit(_elements:Elements)publicmutatingfuncnext()->Elements._Element?}我知道“

swift - 通过 self 更新闭包内的 UI 是一种不好的做法吗?

我是多线程编程的新手,到目前为止,我一直在通过self.myview.setTitle等更新我的UI/View在闭包中。这是我如何在处理程序/闭包中更新我的UI的示例代码SFSpeechRecognizer.requestAuthorization{(authStatus)inswitchauthStatus{case.authorized:self.recordButton.isEnabled=truecase.denied:self.recordButton.isEnabled=falseself.recordButton.setTitle("Userdeniedaccesstos

Linux INFO: rcu_sched self-detected stall on CPU

如果串口持续打印下面的信息,说明代码中出现了异常,程序一直占据了cpu不释放。cpu在调度中检测到了这种异常,在串口中打印出内核异常位置的调用栈。这种检查内核缺省是打开的,CONFIG_RCU_CPU_STALL_TIMEOUT参数是时间,如果cpu占据时间超过该参数,则会打印。在我调试的单板上缺省为60秒。在openwrt系统上执行makekernel_menuconfig可以看到如下配置:这种问题一般出现在内核程序出现了死循环的现象。因此通过调用栈信息很快能够找到程序的异常点。[814.604208]INFO:rcu_schedself-detectedstallonCPU[814.614

swift/AppleScript : Cannot run apple script from Swift code

我尝试像这样从Swift代码运行AppleScript命令:varappleScriptCmd="tellapplication\"SystemEvents\"tomakeloginitematendwithproperties{path:\""+appPath+"\",hidden:false,name:\"SomeApp\"}";varappleScriptCmd2="tellapplication\"SystemEvents\"tosetvisibleofprocess\"Safari\"tofalse";然后我都试过了:letscript=NSAppleScript(sourc

swift - 在快速关闭中使用 `[weak self]` 是正确的方法吗?

我总是在swift闭包中使用[weakself]来防止引用循环。这是下面的代码,它是正确的方法吗?someTask(completion:{[weakself](result)inifself==nil{return}//isitsafewhenreachhere?self!.xxx=yyyself!.doLongTermWork()self!.finish()//willcrashwhenselfisnil?})弱小的self无法牢牢捕获实例。那么当self.doLongTermWork()时,self会不会在别的地方又被设置为nil呢? 最佳答案

ios - 协议(protocol) 'Line' 只能用作通用约束,因为它具有 Self 或关联类型要求

我正在快速处理协议(protocol)。我假设它类似于其他语言的“界面”。我正在测试它如何处理变量。协议(protocol)对我来说很新,因为我从未见过与非静态变量的接口(interface)。我创建了一个Station协议(protocol)。protocolStation{varid:String{getset}varname:String{getset}//stationnamevarlines:Array{getset}//alllinespersentinthisstation}然后是包含该站引用的线路。它还包括Hashable协议(protocol)。protocolLin

ios - 如何在 Swift 中从 UIViewController 卸载 self.view

根据ViewControllerProgrammingGuide,我们可以通过将nil分配给self.view来显式地从UIViewController卸载self.view。但是在Swift中,UIViewController中的view属性声明为varview:UIView它不是UIView!因此下面的代码无法编译overridefuncdidReceiveMemoryWarning(){super.didReceiveMemoryWarning()ifself.view.window==nil{self.view=nil//^Type'UIView'doesnotconformt

VS Code 使用 clang++ 编译,使用 cppvsdbg 或 lldb 调试的配置方法

需要安装的VSCodeLLVMVSCode需要安装的插件:C/C++(用来配置c_cpp_properties.json)CodeLLDB(如果你要用lldb调试,那么这个插件就需要安装,用来连接到lldb调试器)流程我们都知道配置编译器要设置三个json,task,launch,c_cpp_properties.jsontask.json直接通过terminal-configuredefaultbuildtask-C/C++:clang++.exebuildactivefile设置launch.json不再是通过C/C++:clang++.exebuildanddebugactivefile

swift - 具有 Self 类型属性的协议(protocol)只能用作泛型约束,为什么?

作为类型、容器类型、参数,不能使用带有Selfastype属性的协议(protocol)。我想我需要一个有意义的示例,即编译器无法推断类型。编译的定义internalprotocolLovable{varinLoveTo:Self?{get}}internalfinalclassHuman:Lovable{varinLoveTo:Human?=nil}internalfinalclassAnimal:Lovable{varinLoveTo:Animal?=nil}internalletthing11:Human=Human()internalletthing12:Animal=Anim

ios - 在 Swift 2.2 中呈现弹出窗口时在闭包错误中隐式使用 'self'

如果用户成功重置密码,我会尝试将ViewController呈现为弹出窗口。基本上,如果通过电子邮件发送密码重置说明电子邮件一切正常,那么将运行以下代码。但是,我收到了错误闭包中“self”的隐式用户;使用“.self”使捕获语义明确在下面的第一行:letVC=storyboard?.instantiateViewControllerWithIdentifier("ResetPasswordSuccessPopOver")as!ResetPasswordSuccessPopOverViewControllerVC.preferredContentSize=CGSize(width:UI