草庐IT

convert_it

全部标签

ios - swift 3 : How to convert struct to Parameters

我有一个结构如下structUserInfo{varuserId:IntvarfirstName:StringvarlastName:String}如何序列化UserInfo的实例以键入Parameters?varuser=UserInfo(userId:1,firstName:"John",lastName:"Skew")//ConvertusertoParametersforAlamofireAlamofire.request("https://httpbin.org/post",parameters:parameters) 最佳答案

ios - "Method does not override any method from its superclass" swift 3

这个问题在这里已经有了答案:Swift2to3MigrationforprepareForSegue[duplicate](1个回答)关闭6年前。这段代码是swift2overridefuncprepareForSegue(segue:UIStoryboardSegue,sender:AnyObject?){letplayerViewController=segue.destinationas!PlayerViewControllerplayerViewController.videoID=channelsDataArray[selectedVideoIndex]["videoID"]

iOS/swift : Dynamically size UIStackView when one of its items gets larger

我在垂直UIStackView中有两个项目:一个UILabel和一个UITableView。当动态数量的UITableViewCell在运行时添加到UITableView时,UIStackView不会变大。有没有通用的方法来增加UIStackView的大小? 最佳答案 您应该在stackView的subview上调用sizeToFit()和layoutIfNeeded()。像往常一样约束UIStackView,并像往常一样约束subview。此外,您需要将其设置为按比例填充,它会调整大小以适应新内容。

ios - NSKeyValueObservation : Cannot remove an observer for the key path from object because it is not registered as an observer

我的应用出现随机崩溃(我无法在我拥有的设备上重现),但有以下异常(exception):CannotremoveanobserverFoundation.NSKeyValueObservation0xaddressforthekeypath"readyForDisplay"fromAVPlayerLayer0xaddressbecauseitisnotregisteredasanobserver.当我释放一个包含AVPlayerLayer的UIView时会发生这种情况。我的初始化:privatevarplayerLayer:AVPlayerLayer{returnself.layera

ios - "The data couldn’ t be read because it is missing”在Swift中解码JSON时出错

我收到以下错误:无法读取数据,因为它丢失了。当我运行以下代码时:structIndicator:Decodable{letsection:Stringletkey:Intletindicator:Intletthreshold:Int}varindicators=[Indicator]()do{ifletfile=Bundle.main.url(forResource:"indicators",withExtension:"json"){indicators=tryJSONDecoder().decode([Indicator].self,from:tryData(contentsOf

swift 3.0 : Convert server UTC time to local time and vice-versa

我想将服务器UTC时间转换为本地时间,反之亦然。这是我的代码..varisTimeFromServer=truevartime:String!varperiod:String!lettimeString="6:59AM"//CurrentUTCtimeifisTimeFromServer{letindex=timeString.index(timeString.startIndex,offsetBy:5)lettwelve=timeString.substring(to:index)vardateString:String!letdateFormatter=DateFormatter(

cocoa - Swift 协议(protocol) : method does not override any method from its superclass

由于Xcode6仍然有很多Swift的错误,我不确定是一个错误还是我遗漏了什么。我的类采用协议(protocol)NSLayoutManagerDelegate。但似乎不可能覆盖我需要的方法。我按照文档描述的那样做:overridefunclayoutManager(_aLayoutManager:NSLayoutManager!,didCompleteLayoutForTextContaineraTextContainer:NSTextContainer!,atEndflag:Bool){}但我在这里遇到错误:方法没有覆盖其父类(superclass)中的任何方法。我该怎么办?

ios - swift 错误 : Variable used within its own initial value

当我初始化一个实体的实例时,出现错误Variableusedwithinitsowninitialvalue。这是抛出错误的代码:classfuncbuildWordDefinition(word:String,language:Language,root:TBXMLElement)->WordDefinition{letword=WordDefinition(word:word,language:language)错误指向word变量。这是WordDefinition类:classWordDefinition{letword:Stringletlanguage:Languageini

swift - "Protocol ... can only be used as a generic constraint because it has Self or associated type requirements"是什么意思?

我正在尝试创建一个以Swift中的自定义协议(protocol)为键的字典(实际上是一个HashSet),但它在标题中给出了错误:Protocol'myProtocol'canonlybeusedasagenericconstraintbecauseithasSelforassociatedtyperequirements而且我无法理解它的正反面。protocolObserving:Hashable{}varobservers=HashSet() 最佳答案 协议(protocol)Observing继承自协议(protocol)Ha

ios - Realm swift : Convert Results to Swift Array

我要实现的:classfuncgetSomeObject()->[SomeObject]?{letobjects=Realm().objects(SomeObject)returnobjects.count>0?objects:nil}如果Results,我如何将对象返回为[SomeObject]? 最佳答案 很奇怪,答案很直截了当。这是我的做法:letarray=Array(results)//lafin 关于ios-Realmswift:ConvertResultstoSwiftAr