草庐IT

lazy-init

全部标签

ios - 'required' initializer 'init(coder:)' 必须由 'UITableViewCell' 的子类提供`

据说此代码有效here和here,但我似乎无法让它发挥作用。IBOutlets连接到Storyboard中的对象。prototypeCell已命名,因此我可以将它与dequeueReusableCellWithIdentifier一起使用,并且它的自定义类属性设置为commentCell。第一个错误(我可以解决,但上面的链接都不需要它,这让我觉得我做错了什么。我是对的吗?):Overridingmethodwithselector'initWithStyle:reuseIdentifier:'hasincompatibletype'(UITableViewCellStyle,Strin

ios - Xcode UIView.init(帧 :) must be used from main thread only

我正在尝试在后台线程中渲染一些View以不影响主线程。在Xcode9之前,这从来都不是问题。DispatchQueue.global(qos:.background).async{letcustomView=UIView(frame:.zero)DispatchQueue.main.async{self.view.addSubview(customView)}}UIView.init(frame:)mustbeusedfrommainthreadonly这个错误出现在第二行。更新AppleUIView文档实际上在线程注意事项部分中说:Manipulationstoyourapplica

swift - 在 Swift 中,从 init() 调用时 didSet 不会触发

我有车和司机。他们相互引用。在汽车的init()中,我创建了一个驱动程序并将其分配给驱动程序成员。driver成员有一个didSet方法,该方法应该设置司机的车,从而将它们相互链接起来。classGmDriver{varcar:GmCar!=nil}classGmCar{vardriver:GmDriver{didSet{driver.car=self}}init(){driver=GmDriver()}}letmyCar=GmCar()println(myCar.driver.car)//nil但是,didSet永远不会触发。为什么? 最佳答案

arrays - 具有容量的 Swift init 数组

如何快速初始化具有特定容量的数组?我试过:vargrid=Array()grid.reserveCapacity(16)但是报错expecteddeclaration 最佳答案 怎么样:classSquare{}vargrid=Array(count:16,repeatedValue:Square());尽管这将为每个方block调用构造函数。如果您使数组具有可选的Square实例,您可以使用:vargrid2=Array(count:16,repeatedValue:nil);编辑:在Swift3中,此初始化程序签名已更改为以下内

ios - fatal error : init(coder:) has not been implemented error despite being implemented

我收到一条错误消息:fatalerror:init(coder:)hasnotbeenimplemented对于我的自定义UITableViewCell。该单元格未注册,在Storyboard中和使用dequeasreusablecell时具有标识符cell。在自定义单元格中,我将初始化设置为:代码:overrideinit(style:UITableViewCellStyle,reuseIdentifier:String?){print("test")super.init(style:style,reuseIdentifier:reuseIdentifier)}requiredini

initialization - Swift 子类化——如何覆盖 Init()

我有以下类,有一个init方法:classuser{varname:Stringvaraddress:Stringinit(nm:String,ad:String){name=nmaddress=ad}}我正在尝试对此类进行子类化,但我在super.init()部分不断收到错误消息:classregisteredUser:user{varnumberPriorVisits:Int//Thisiswherethingsstarttogowrong-assoonasItype'init'it//wantstoautocompleteitformewithallofthesuperclass

swift - convenience init vs init in swift, explicit examples better 有什么区别

我很难理解两者之间的区别,或者convenienceinit的目的。 最佳答案 标准初始化:Designatedinitializersaretheprimaryinitializersforaclass.Adesignatedinitializerfullyinitializesallpropertiesintroducedbythatclassandcallsanappropriatesuperclassinitializertocontinuetheinitializationprocessupthesuperclasscha

c# - 通过 Lazy<T> 或任何 lambda 表达式访问非静态成员

我有这个代码:publicclassMyClass{publicintX{get;set;}publicintY{get;set;}privateLazylazyGetSum=newLazy(newFunc(()=>X+Y));publicintSum{get{returnlazyGetSum.Value;}}}给我这个错误:Afieldinitializercannotreferencethenon-staticfield,method,orproperty.我觉得通过lazy访问一个非静态成员是很合理的,怎么办?*编辑*接受的答案完美地解决了问题,但要一如既往地了解问题的详细和深入

postgresql - Docker 错误 : standard_init_linux. go:185: exec 用户进程导致 "no such file or directory"

我正在尝试将我的elixir-phoenix应用程序与postgresql数据库一起设置为与Docker一起运行。这就是我的Dockerfile的样子:#./Dockerfile#StartingfromtheofficialElixir1.5.2image:#https://hub.docker.com/_/elixir/FROMelixir:1.5.2ENVDEBIAN_FRONTEND=noninteractive#InstallhexRUNmixlocal.hex#InstallrebarRUNmixlocal.rebar#InstallthePhoenixframeworki

postgresql - Docker 错误 : standard_init_linux. go:185: exec 用户进程导致 "no such file or directory"

我正在尝试将我的elixir-phoenix应用程序与postgresql数据库一起设置为与Docker一起运行。这就是我的Dockerfile的样子:#./Dockerfile#StartingfromtheofficialElixir1.5.2image:#https://hub.docker.com/_/elixir/FROMelixir:1.5.2ENVDEBIAN_FRONTEND=noninteractive#InstallhexRUNmixlocal.hex#InstallrebarRUNmixlocal.rebar#InstallthePhoenixframeworki