草庐IT

model_instance

全部标签

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 - 无法将 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

model-view-controller - 在 Swift 中删除类实例

我试图完全理解在Swift中创建类对象的过程。秉承MVC的思想,我有以下简单的类来表示我的数据模型://Person.swiftimportFoundationclassPerson{varfirst:String="first"varlast:String="last"}在我的ViewController中,我有两个IBOutlets连接到UITextFields。使用IBAction方法,我使用文本字段中的文本设置了first和last变量。//ViewController.swiftimportUIKitclassViewController:UIViewController{@

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

ios - swift 4 可编码 : Common struct for all model

在这里我得到了我所有api的API响应。{"success":true,"message":"","data":{/multipaldataparameter/}}这是我的可编码模型structLogin:Codable{letsuccess:Boolletmessage:Stringletdata:DatastructData:Codable{}}如何为success和message参数创建通用的Sturct。 最佳答案 您可以使代表网络响应的根结构成为通用的,这将允许您在所有专门的响应中保持success和message部分通用

swift - Steam 3 API : embed Future<Model> in response object

假设我有一个名为Estimate的模型.我有一个Vapor3API,我想返回这些模型的列表,按查询参数过滤。目前这样做会返回Future,这会导致API返回如下所示的JSON:[{estimateobject},{estimateobject},...]相反,我想让它返回这样的东西:{"estimates":[{estimateobject},{estimateobject},...]}所以,和以前一样,但用一个键包裹在一个JSON对象中,"estimates".Accordingtothedocumentation,任何时候我想返回一些非默认的东西,我应该为它创建一个新类型;这向我建

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

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

ios - Xcode 8 无法打开 Model.xcdatamodeld

我正在运行macOSSierra(Build16A320),使用Xcode8.0(8A218a)并将我的所有代码迁移到Swift3。我无法再打开我的Model.xcdatamodeld文件。在项目导航器中选择它不会打开“核心数据模型编辑器”View(不确定它叫什么)。我试过重新启动Xcode,但它不起作用。我试过删除派生数据,清理,不起作用。我试过双击,不起作用。Model.xcdatamodeld在ProjectnavigatorView中可见,但不可能与之交互(右键单击除外),当我单击或双击它。编辑:问题已解决,请参阅myanswerbelow 最佳答案

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