草庐IT

member-initialization

全部标签

ios - Swift- 错误 : Variable 'self.___' used before being initialized

我正在尝试在Playground中使用手势识别器,但遇到了一些问题。这是我的类(class):classfoo{varfooVarSwipe:AnyvarfooVarTap:Anyinit(){letgr=UISwipeGestureRecognizer(target:self,action:#selector(foo.bar))lettr=UITapGestureRecognizer(target:self,action:#selector(foo.tar))helloApple.addGestureRecognizer(gr)helloApple.addGestureRecogni

ios - 在 Swift 中使用 block 给出错误 "Variable used within its own initial value"

这是我在obj-c中的代码:__blockNSString*requestReference=[selfoperation:methodurl:urlparameters:parametersheaders:headerssuccess:^(NSURLSessionDataTask*task,idresponseObject){NSError*error=[NSErrorerrorWithSessionTask:taskresponseObject:responseObject];if(error){NSLog(@"error-%@",error);[delegaterequestWi

swift 3 转换 : value of type 'characterset' has no member 'characterIsMember'

我目前正在将我的代码转换为swift3,但我在使用以下代码时遇到了上述错误。funccontainsAlphabets()->Bool{//Checksifallthecharactersinsidethestringarealphabetsletset=NSCharacterSet.lettersreturnself.utf16.contains({returnset.characterIsMember($0)})}有好心人可以帮忙吗? 最佳答案 在Swift3中,CharacterSet被重新设计为与UnicodeScalar而

ios - watchOS 2 : setting properties on initial Interface Controller

从watchOS2开始,我们有一个ExtensionDelegate对象,它类似于UIApplicationDelegate(对应用程序生命周期事件作出react)。我想获得对第一个界面Controller对象的引用,该对象将在启动时显示,以在其上设置属性(例如,传入数据存储对象)。根据docs,WKExtension上的rootInterfaceController属性返回初始Controller:Therootinterfacecontrollerislocatedintheapp’smainstoryboardandhastheMainEntryPointobjectassoci

ios - Xcode 10 beta2 : Cannot invoke initializer for type 'UIView' with no arguments

我已经下载了Xcode10beta2并重建了我的项目,代码如下:letsomeView=UIView()出现以下错误:无法调用不带参数的“UIView”类型的初始值设定项很奇怪。有人在使用Xcode10beta2时遇到过这些构建错误吗? 最佳答案 对我来说,这是通过扩展NSObjectProtocol来推断的:extensionNSObjectProtocolwhereSelf:UIView我通过将NSObjectProtocol替换为UIView符合的任何其他协议(protocol)来修复它。在我的例子中是UIAppearance

ios - swift 'does not have a member named'

这个问题有解决办法吗?classViewController:UIViewController{letcollectionFlowLayout=UICollectionViewFlowLayout()letcollectionView=UICollectionView(frame:CGRectZero,collectionViewLayout:collectionFlowLayout)}xcode给我以下错误ViewController.swift:'ViewController.Type'doesnothaveamembernamed'collectionFlowLayout'我可以

ios - 开关错误 : Expected member name or constructor call - what's wrong?

我想对我的3个案例进行切换,但我遇到了无法解决的错误:错误:在类型名称之后需要成员名称或构造函数调用自从我一直在使用类似的代码以来,一定有什么地方被我忽略了。但是现在我的项目几乎是空的,无法弄清楚出了什么问题?importUIKitclassViewController:UIViewController{enumMyStateStatus{caseReadycaseRunningcaseStopped}@IBActionfuncactionPressed(sender:UIButton){switchMyStateStatus{caseMyStateStatus.Ready:print

swift - 在子类 : Swift and SpriteKit 中循环 Initialization 的 drain

我想创建一个比SpriteNode的touchesBegan级别更高的SKShapeNode,所以当我想从这个Sprite的touchesBegun事件将SKShapeNode添加到屏幕时,形状已经存在,我只需将它添加到来自touchesBegan覆盖的屏幕。TL;DR,在我的SKSpriteNode中,我正在尝试预构建SKShapeNode,它将在Sprite被触摸时用作动画环。我想用变量/常量创建SKShapeNode,这样我就可以轻松地编辑它的值...因此在子类的根目录中我有颜色、大小和线宽的变量,准备用于创建SKShapeNode...classBalls:SKSpriteNo

swift : Enum 'cannot be constructed because it has no accessible initializers'

我很快就得到了这个错误'BlockColor'cannotbeconstructedbecauseithasnoaccessibleinitializersimportFoundationimportSpriteKitletNumberOfColors:UInt32=6enumBlockColor:Int,Printable{caseBlue=0,Orange,Purple,Red,Teal,YellowvarspriteName:String{switchself{case.Blue:return"blue"case.Orange:return"orange"case.Purple:

iOS Swift 可解码 : Error: Cannot invoke initializer for type with no arguments

我在初始化结构时遇到错误,请参阅下面的屏幕截图。调试后我发现在结构中包含review变量会产生问题。我不知道我做错了什么。谁能帮帮我?发送我正在复制代码以防你需要尝试一下importUIKitstructRootValue:Decodable{privateenumCodingKeys:String,CodingKey{casesuccess="success"casecontent="data"caseerrors="errors"}letsuccess:Boolletcontent:[ProfileValue]leterrors:[String]}structProfileValu