草庐IT

Any-Integer

全部标签

arrays - 上下文类型 'Any' 不能与字典文字 Swift 一起使用

我在两个文件中使用此代码,但只有一个文件显示此错误。Contextualtype'Any'cannotbeusedwithdictionaryliteral为什么?这2个代码是一样的,为什么只有一个出错了?这段代码有什么问题?letuserId=user!["userId"]as!StringletbookCid=NSUUID().uuidStringletparam=["message":"addAccBook","accountbook":["bookcid":bookCid!,"accbookname":"","accbooktype":"","category":"","use

Swift 将 Integer 转换为 Int

我正在做泛型编程并且有一些符合Integer的东西.我需要以某种方式将其具体化Int我可以使用。extensionCountableRange{//Extendeachboundawayfrommidpointby`factor`,aportionofthedistancefrombegintoendfuncextended(factor:CGFloat)->CountableRange{lettheCount=Int(count)//orlowerBound.distance(to:upperBound)letamountToMove=Int(CGFloat(theCount)*fa

ios - Swift 转换,CGFloat 到 Integer

如何将@IValueCGFloat转换为Int?我一直收到cannotconvert@IValueCGFloattoInteger的消息如下:@IBOutletvaruserObject:UIImageViewfuncreturnYPosition(yPosition:Integer)->Integer{returnuserObject.center.y} 最佳答案 你需要来回传递Int类型,然后才转换:funcreturnYPosition(yPosition:Int)->Int{returnInt(userObject.cent

ios - 类型 'Any' 不符合协议(protocol) 'Sequence'

我在我的代码中遇到了问题,在尝试解析JSON数据(数组的每个数据,比如它应该如何完成)并尝试设置forin循环时,错误出现了。这是我的代码ifletjsonDataArray=try?JSONSerialization.jsonObject(with:data!,options:[]){print(jsonDataArray)varallStops=[busStops]()foreachDatainjsonDataArray^//thisiswheretheerrorislocated{ifletjsonDataDictionary=eachDataas?[String:AnyObje

Array<Any> 上的 Swift 模式匹配

swift1.2我正在尝试在一个以Any类型作为参数的函数中的switch案例中进行模式匹配,以便分派(dispatch)给一个更专业的私有(private)init。这是一个Playground推断:importFoundationstructmyStruct{}funcswitchOnAny(any:Any)->String{println("DynamicType==\(any.dynamicType)")switchany{caseletarrayas[Any]:return"Array"caseletarrayasNSArray:return"NSArray"default:

swift - 如何在 Swift 3 中将 Any 转换为 CGFloat

我需要Any到CGFloat。但是,我遇到了一个fatalerror。为什么不能将Any分配给CGFloat?如何转换?letlx=ixas!CGFloat错误信息:Thread1:EXC_BAD_INSTRUCTION(code=EXC_l386_INVOP,subcode=0x0)0x1040dcbf1:movsd-0xc0(%rbp),%xmm0;xmm0=mem[0],zero打印日志:CGFloat:-0.5CGFloat:-0.5代码:importFoundationimportUIKit//creationofblocksclassBlock{varblockRect=[

json - Swift3 JSONSerialization with [String :Any] rather than NSDictionary

假设你有一个json字符串someText并且你想将它解析为字典。以前我做过这个......letjsonResult:NSDictionary=tryJSONSerialization.jsonObject(with:someText.data(using:.utf8)!,options:JSONSerialization.ReadingOptions.mutableContainers)as!NSDictionary但这只是一个蹩脚的NSDictionary。看来你确实可以做到这一点......letjsonResult:[String:Any]=tryJSONSerializat

ios - 类型 'Any?' 没有下标成员

这个问题在这里已经有了答案:Type'Any'hasnosubscriptmembers(firebase)(2个答案)关闭5年前。我正在尝试在我的应用程序中登录fb后检索电子邮件ID。但是,当我尝试从结果中获取值时出现错误。错误是:键入“Any?”没有下标成员。funcfetchProfile(){print("FetchProfile")letparameters=["fields":"email,first_name,last_name,picture.type(large)"]FBSDKGraphRequest(graphPath:"me",parameters:paramet

arrays - 展平 [Any] 数组 Swift

使用this堆栈溢出问题我有以下代码。letnumbers=[1,[2,3]]as[Any]varflattened=numbers.flatMap{$0}print(flattened)//[1,[2,3]]我不想将flattened设置为[1,[2,3]][1,2,3]。在Swift中实现这一目标的最简单/最干净的方法是什么? 最佳答案 可能有更好的方法来解决这个问题,但一个解决方案是编写您自己的数组扩展:extensionArray{funcanyFlatten()->[Any]{varres=[Any]()forvalins

ios - 无法使用类型为 '[NSObject : Any]' 的索引下标类型为 'String' 的值

我在Internet上找到了不同的方法,但没有任何帮助。我是新人,我来帮你。我会收到消息:Cannotsubscriptavalueoftype'[NSObject:Any]'withanindexoftype'String'privatefuncimagePickerController(picker:UIImagePickerController,didFinishPickingMediaWithInfoinfo:[NSObject:Any]){letchosenImage=info[UIImagePickerControllerEditedImage]asUIImageletne