草庐IT

instance_variables

全部标签

ios - 符合 Codable 协议(protocol)的类因 encodeWithCoder : unrecognized selector sent to instance 而失败

我知道有几个与此类似的问题,它们往往都围绕着未正确遵守协议(protocol)的类展开,但这不应该是这里的直接问题。以下是目前给我这个问题的代码的浓缩版:enumBinary:Int{casea=0caseb=1casec=9}finalclassMyClass:NSCoder{varstring:String?vardate:Date?varbinary:Binary=.coverrideinit(){}enumCodingKeys:CodingKey{casestring,date,binary}}extensionMyClass:Codable{convenienceinit(f

swift WKWebView : Can't find variable error when calling method

我正在尝试将GPS坐标传递给方法调用setIOSNativeAppLocation。我在下面有以下代码,但出现此错误:AJavaScriptexceptionoccurred"UserInfo={WKJavaScriptExceptionLineNumber=1,WKJavaScriptExceptionMessage=ReferenceError:Can'tfindvariable:setIOSNativeAppLocation,WKJavaScriptExceptionSourceURL=http://mywebsite.com,NSLocalizedDescription=AJa

swift - 无法将 Swift 4 字符串传递给 Obj-C++ -[_SwiftValue dataUsingEncoding :]: unrecognized selector sent to instance

我有一些像这样的Objective-C++代码://header@interfaceMyObjcClass-(void)myMethod:(NSString*)text;@end//implementation@implementationMyObjcClass-(void)myMethod:(NSString*)text{someInternalObject->useWstring(nsStringToWstring(text))}std::wstringnsStringToWstring(constNSString*text){NSData*data=[textdataUsingE

swift - 枚举 : Switch case for variables of type

当我尝试打开具有枚举friendstate的optional时,当我尝试在下面的switch语句中应用它时,为什么会出现错误?提供的错误是在类型“friendState!”中找不到枚举案例“已添加”(所有情况下都会出现错误)有没有办法解决这个错误?varusernameText:String!varUID:Int!varuserDetails:UserState?varbuttonText:String{switch(userDetails!.state){case.added:return"remove"//erroroccurscase.incoming:return"accept

ios - iOS Swift 中的 Braintree 插件 : Where to get variable PaymentMethodNonce:

我一直在按照此处的说明操作https://developers.braintreepayments.com/start/hello-client/ios/v4在iOSSwift中将直接支付表单与braintree集成。我的代码如下所示,据我所知,它与文档完全匹配。funcfetchClientToken(){//TODO:SwitchthisURLtoyourownauthenticatedAPIletclientTokenURL=NSURL(string:"https://braintree-sample-merchant.herokuapp.com/client_token")!l

swift - 隐式公共(public)访问 (Bool) 内部类型 'Builtin.Int1' : runtime exception if appending instances of 'Int1' to an array

问题我知道我可能不应该摆弄内置类型,但我很好奇,Builtin.Int1类型是否真的可以公开访问,如下所示?如果是这样,为什么将它用作数组元素会导致Swift崩溃?我很好奇,因为我从来没有遇到过我自己无法存储在数组中的自定义类型(但我猜内置类型与我可以使用“构建自己的类型不同”公共(public)swift”)。我使用的是Swift2.2和Xcode7.3。详情查看swift/stdlib/public/core/Bool.swift的源代码,我们注意到我们可以隐式访问内部类型Builtin.Int1(1位整数),它构成了Swift中Bool类型的基础。publicstructBool

swift - 如何消除 "variable not used"警告并保持强引用?

我想在不使用_=DispatchSource.createRepeating并且最好不打印它或在多余的方式。functestTimerIsStarted(){letexpectation=self.expectation(description:#function)lettimer=DispatchSource.createRepeating(interval:0,deadline:DispatchTime.now()){expectation.fulfill()}waitForExpectations(timeout:0.02)}Initializationofimmutableva

ios - "unrecognized selector sent to instance"在 react-native 上设置属性时

我正在尝试将我的SwiftView与我的React-Native项目链接起来。我想出了如何显示它,但现在当我尝试设置一个属性时,我收到了这条错误消息:Terminatingappduetouncaughtexception'NSInvalidArgumentException',reason:'-[SwitchsetMessage:]:unrecognizedselectorsenttoinstance0x7f96b270de70'在我的react-native代码中,我正在做:constSwitchNative=requireNativeComponent('Switch',Swit

ios - 错误 : Instance member cannot be used on type 'ViewController'

这个问题在这里已经有了答案:Instancemembercannotbeusedontypeofcustomclass(3个答案)关闭4年前。我正在按照斯坦福类(class)的在线讲座制作浓度游戏,但我的代码的一部分出现错误。我收到错误消息“实例成员‘cardButtons’不能用于类型‘ViewController’”,但代码似乎适用于讲师。有人可以帮我解决这个问题吗?这是代码的一部分。第4行出现错误importUIKitclassViewController:UIViewController{@IBOutletvarcardButtons:[UIButton]!lazyvargam

ios - Swift:自定义 UITableViewCell 中的 UIButton 'Unrecognised selector sent to instance' 错误

functableView(tableView:UITableView,cellForRowAtIndexPathindexPath:NSIndexPath)->UITableViewCell{letcellIdentifier="ExerciseMenuCell"letcell=tableView.dequeueReusableCellWithIdentifier(cellIdentifier,forIndexPath:indexPath)as!ExerciseOptionTableViewCellletcurrentWorkout=workouts[indexPath.row]ce