草庐IT

question_type

全部标签

ios - Realm iOS : Cannot Convert value of type 'Dogs.Type' to expected argument type 'T.Type'

这是我的DBManager.swiftimportRealmSwiftclassDBManager{classfuncgetAllDogs()->[Dog]{letrealm=try!Realm()//COMPILERERROR:CannotConvertvalueoftype'Dogs.Type'toexpectedargumenttype'T.Type'returnrealm.objects(Dog.self)}}这是我的Dog.swift:importFoundationimportRealmSwiftclassDog:Object{dynamicvarfirstName=""d

ios - 自定义 UITableViewCell : Value of type 'UITableViewCell' has no member 'pointsNumber'

我的错误在下面的第一个代码中,在开关的情况2中。cell.pointsNumber.text="toto"Xcodeerror:Valueoftype'UITableViewCell'hasnomember'pointsNumber'我无法访问我的类PerformancesViewCell来填充标签。我的转换不起作用,我的单元格仍然像UITableViewCell而不是PerformancesViewCell。预先感谢您的帮助;)细胞标识符:letthirdCellIdentifier="thirdCell"表格View:functableView(tableView:UITableV

ios - Swift:利用 CLLocationManagerDelegate 和 CoreLocation.framework 导致 "Use of undeclared type"错误

我正在播放一个youtube视频,该视频提供了一个基本示例,说明如何利用Xcode的定位服务为程序编写一种map用户界面。我按照设置程序的视频中的步骤进行操作,并在尝试编译应用程序时收到一个假设简单的“使用未声明的类型”错误。https://www.youtube.com/watch?v=qrdIL44T6FQ-链接到youtube视频。问题出现在类创建行。importUIKitimportMapKitimportCoreLocationclassViewController:UIViewController,MKMapViewDelegate,CLLocationManagerDel

ios - "Type' 程序 ' does not conform to protocol ' 任何对象 '"

我更新了xcode,现在我的项目出现错误,我不知道该怎么办。structProgram{letname:Stringleturl:String}self.arrayOfPrograms=[Program(name:"First",url:"http://1.com"),Program(name:"Second",url:"http://2.com"),Program(name:"Third",url:"http://2.com")]我收到错误“Type'Program'doesnotconformtoprotocol'AnyObject'” 最佳答案

swift 3 : Cannot call value of non-function type '(() -> Void)?'

这个函数在curseofallcurses(也称为Swift3)之前有效。迁移到Swift3之后,我友好可爱的IDEXcode在SCNTransaction.completionBlock行显示这个令人沮丧的错误:Cannotcallvalueofnon-functiontype'(()->Void)?'其他几篇文章处理类似的错误,但这些解决方案均不适用。线路有什么问题???functest(_block:SCNNode,animated:Bool){//DostuffSCNTransaction.begin()SCNTransaction.animationDuration=anim

swift - 泛型 : Same-type constraint type 'G' does not conform to required protocol 'Generator'

我正在开发一个Generator类,它包装了另一个Generator并在其之上提供了一些额外的功能。我几乎所有的东西都可以工作,除了一件事:一个方便的init,它将一个序列作为参数并自动从中创建一个生成器。这是导致错误的代码:classMyGenerator:Generator{typealiasElement=G.Elementvargenerator:Ginit(_generator:G){self.generator=generator}//ERROR:Same-typeconstrainttype'G'doesnotconformto//requiredprotocol'Gen

ios - Swift 将泛型类型限制为 Type

如何将泛型类型限制为类型,而不是类型的实例?如果我有一个类:classSomeClass{}我怎样才能确保T只是AnyClass的一个实例(这只是AnyObject.Type)我的协议(protocol)只有静态方法,为了调用这些方法我必须做instance.dynamicType.protocolMethod而我想做someType.protocolMethod 最佳答案 据我所知,Swift不允许您将元类型用作泛型。(我相信这符合SamGiddinswishedforinSwift3的思路。)但是,您可以将其用作值。不要将T设为

swift : Cannot invoke 'filter' with an argument list of type '(@noescape (Int) throws -> Bool)'

我遇到了这个错误:funccompactCoords(coords:[Int])->[Int]{returncoords.filter({(value)->Boolinreturnvalue!=0})}无法使用类型为“(@noescape(Int)throws->Bool)”的参数列表调用“filter”感谢您的帮助! 最佳答案 您的代码在Xcode7.1中运行良好。您可能不小心尝试在Xcode6.x中运行此代码?你可以像这样缩短你的函数:funccompactCoords(coords:[Int])->[Int]{returnco

swift 错误 : cannot convert value of type 'Int32' to expected argument type 'Int32'

我正在尝试编写一对函数,将String转换为[UInt8]字节数组,然后再转换回来。作为[UInt8]->String函数的一部分,我试图将单个Int32转换为Character。letnum:Int32=5letchar=Character(_builtinUnicodeScalarLiteral:num)但是我遇到了这个奇怪的错误:error:cannotconvertvalueoftype'Int32'toexpectedargumenttype'Int32'letchar=Character(_builtinUnicodeScalarLiteral:num)^~~编辑:我设法使

swift 错误 : cannot convert value of type B to type A in coercion

我有一个泛型类A及其子类B:classA{letx:T1lety:T2init(_v1:T1,_v2:T2){self.x=v1self.y=v2}}classB:A{init(_v:T){super.init(v,v)}}我需要一个不同对象的集合,它们都属于A的子类:vararr=[A]()但是我不能将对象放入集合中,下面的代码会导致错误:lett=B(10)arr.append(tasA)错误是:cannotconvertvalueoftype'B'totype'A'(aka'A,protocol>')incoercion如何解决这个问题? 最佳答案