草庐IT

Controllers-Swift

全部标签

swift 3 : Converting enum case with associated value to closure with protocol parameter results in a compiler error

我有一个枚举,其关联值为结构。当我编写这段代码时,它编译没有错误:protocolMyProtocol{}structMyAssociatedValue:MyProtocol{}enumMyEnum{casemyCase(MyAssociatedValue)}funcmyEnumClosureMapping()->(MyAssociatedValue)->MyEnum{returnMyEnum.myCase}但是我添加了另一个这样的函数:funcmySecondEnumClosureMapping()->(MyProtocol)->MyEnum{returnMyEnum.myCase}

swift - SKEase action,如何使用Float changing Action Setter Block?

在以下用例中,我尝试为SKShapeNode的lineWidth设置动画。SKEase属于精彩SpriteKitEasing来自CraigGrummitt的github存储库。它的一个功能是float更改缓动Action,它似乎会随时间改变float的值。但是我不知道如何使用它。Xcode在输入时给出以下建议:letlineWeight=SKEase.createFloatTween(Void))对于此库中的其他SKEase操作,Xcode对轻松类型非常有帮助,并有助于确定要输入的内容。有了这个,我不知道AHEasingFunctions有哪些选项...我可能会找到。但我完全不知道最后

regex - 如何在 Swift 中用 NSRegularExpression 替换大写字符串?

我试图通过这段代码(Swift3.0)将hello_world更改为helloWorld:importFoundationletoldLine="hello_world"letfullRange=NSRange(location:0,length:oldLine.characters.count)letnewLine=NSMutableString(string:oldLine)letregex=try!NSRegularExpression(pattern:"(_)(\\w)",options:[])regex.replaceMatches(in:newLine,options:[]

swift - 使 Sprite 出现在随机位置

我试图让Sprite“cometd”随机出现在随机位置。到目前为止,我想测试我的随机位置代码是否有效,但是,我似乎甚至看不到Sprite。这是我的代码:funcspawnAtRandomPosition(){letheight=self.view!.frame.heightletwidth=self.view!.frame.widthletrandomPosition=CGPointMake(CGFloat(arc4random())%height,CGFloat(arc4random())%width)letsprite=SKSpriteNode(imageNamed:"comet"

swift - 错误 - 无法在不可变值 : function call returns immutable value 上使用可变成员

所以我有这个自定义结构publicstructFeature{varfeatureID:String=""varfeatureName:String=""varmatchingFieldValue:String=""varpolygonCollection=[MyPolygon]()mutatingfuncsetFeatureID(featureID:String){self.featureID=featureID}funcgetMatchingFieldValue()->String{returnmatchingFieldValue}mutatingfuncsetMatchingFi

swift - 类型 'NSFastEnumerationIterator.Element'(又名 'Any')不符合协议(protocol) 'AnyObject'

我正在尝试将我的应用程序更新到Swift3.0,但遇到了错误:Type'NSFastEnumerationIterator.Element'(又名'Any')不符合协议(protocol)'AnyObject'在线:self.friends.append(Friend(userName:(detailDataasAnyObject).value["userName"]as!String,phoneNumber:detailData.value["phoneNumber"]as!String,status:"Friend",statusSort:2,name:detailData.val

swift - 字符串日期到日期返回错误的时间

我有以下dateFormatter:vardate=Date()vardateFormatter=DateFormatter()dateFormatter.dateFormat="yyyy-MM-ddHH:mm:ss"lettimeZone=NSTimeZone(name:"UTC+01:00")dateFormatter.timeZone=timeZoneasTimeZone!letsweDate=dateFormatter.string(from:date)当我打印出来时,我得到了这些值:1:print(date)//2016-11-0110:16:19+00002:print("

ios - 无法在 Swift 框架中导入 Common Crypto

这个问题在这里已经有了答案:ImportingCommonCryptoinaSwiftframework(16个答案)关闭6年前。在Xcode中,当我尝试通过Swift框架中的桥接header文件添加ObjectiveC库CommonCrypto(使用#import)时,我收到一条错误消息,指出当目标为框架时不允许桥接header。当我将它添加到umbrella头文件时,出现此错误:“在框架模块中包含非模块化头文件”这个链接似乎是关于同样的问题:ImportingCommonCryptoinaSwiftframework但是那里的解决方案非常复杂,而且对于仅将ObjectiveC库包含

swift - SceneKit 渲染器功能不能 Swift 工作?

我目前正在使用Swift3和SceneKit。我的问题似乎是我的渲染器功能无法正常工作。我不知道我做错了什么。该程序运行但没有代码:funcrenderer(_renderer:SCNSceneRenderer,updateAtTimetime:TimeInterval)似乎执行。这是渲染器函数之前的代码。导入UIKit导入QuartzCore导入SceneKitGameViewController类:UIViewController、SCNSceneRendererDelegate{letscene=SCNScene()letcameraNode=SCNNode()varperson

ios - Swift:动态刷新标签栏背景颜色

我已经创建了一个配置管理器来更新UI设置而无需重新启动。大多数设置您都可以强制重绘,但它似乎更受标签栏的限制。当我收到配置更改通知时,我使用以下内容更新了我的UITabBarController中的选项卡栏(注意:这可能是在viewDidLoad之后的任何时间):self.tabBar.backgroundColor=tabBarBackgroundColour这确实会更新颜色,但只会在大约5-10秒之后。我已经尝试了各种方法,在标签栏和View上使用setNeedsLayout和setNeedsDisplay来强制更新,但它们都不起作用。self.tabBar.setNeedsLay