草庐IT

swift_FORCE_LOAD

全部标签

swift - Xcode SpriteKit SKAction 不改变 SKSpriteNode 的属性?

如果我创建一个SKSpriteNode,并在该节点上运行一个SKAction,Action会在模拟器上运行,但节点的属性没有改变。例如。在以下示例中,在模拟器中,节点从(50,50)开始并在1秒内移动到(0,0)。但是,末尾的print语句打印的是(50,50)而不是新位置(0,0)lettest=SKSpriteNode()test.position=CGPoint(x:50.0,y:50.0)test.size=CGSize(width:20.0,height:20.0)test.color=UIColor.blackaddChild(test)test.run(SKAction.

swift - 二元运算符 '*' 不能应用于类型 'Float' 和 'Float!' 的操作数

当我执行以下操作时:letgapDuration=Float(self.MONTHS)*Float(self.duration)*self.gapMonthly;我得到错误:Binaryoperator'*'cannotbeappliedtooperandsoftype'Float'and'Float!'但是当我这样做的时候:letgapDuration=12*Float(self.duration)*self.gapMonthly;一切正常。我不知道这个错误告诉我什么。self.gapMonthly是Float!类型,self.duration和self.MONTHS是类型Int!

ios - Swift UNUserNotification 不触发声音

这是我的UNUserNotification代码funcscheduleNotification(){UNUserNotificationCenter.current().getNotificationSettings{(notificationSettings)inswitchnotificationSettings.authorizationStatus{case.notDetermined:self.requestAuthorization(completionHandler:{(success)inguardsuccesselse{return}//ScheduleLocalN

swift - 无法在 UIView 中设置@IBInspectable 计算属性

我正在尝试向UIView添加IBInspectable颜色,以便我可以在Storyboard中设置它,然后在代码中使用它。在thispostregardingUITextField我已经看到我可以利用扩展和添加计算属性,但我不能让它适用于UIView。我遇到了一个崩溃:无法在(UIView)上设置(additionalColor1)用户定义的检查属性:[setValue:forUndefinedKey:]:此类对于键additionalColor1不符合键值编码。知道是什么导致了崩溃以及如何修复它吗?这是我的代码:extensionUIView{@IBInspectablevaradd

使用 switch、case 和 fallthrough 的 Swift 示例代码

在下面的代码示例中,我不明白为什么打印的是“Value7”而不是“Default”。情况7,即x=7不满足,因为x=6,那么为什么“值7”被打印而不是被跳过并且执行下降到默认值?letx=6 switchx{ case0...5:println("0through5") case6:fallthrough case7:println("Value7") default:println("Default")} 最佳答案 当x=6时,switch语句找到6的case然后它“落空”到下一个casenot默认的。如果您希望6的case执行d

Swift:在类中实现协议(protocol)初始化器

我试图理解为什么Swift强制执行一个符合协议(protocol)的类,该类的初始值设定项被标记为必需。这实质上强制任何子类也实现该初始化器。指定的父类(superclass)初始值设定项肯定会被继承吗?以下引述摘自《Swift语言指南》:https://developer.apple.com/library/prerelease/content/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html#//apple_ref/doc/uid/TP40014097-CH25-ID272Youcani

swift - iOS QR 代码扫描仪多次触发操作

我正在使用来自AppCoda(http://www.appcoda.com/qr-code-reader-swift/#comments)的二维码阅读器代码并将其转换为Swift3。基本代码运行良好。然而,我想要实现的是从QR阅读器中检索一个字符串,将其存储在一个变量中,并将该变量传递给下面的ViewController。所以我向其中添加了一些代码以获得以下内容:funccaptureOutput(_captureOutput:AVCaptureOutput!,didOutputMetadataObjectsmetadataObjects:[Any]!,fromconnection:A

ios - 将 UIKit 坐标转换为 Quartz/CoreImage (Swift)

有没有办法将UIKit坐标(左上角0,0)转换为Quartz/CoreImage(左下角0,0)?在这里找不到任何与swift相关的内容。 最佳答案 你可以使用仿射变换矩阵,这个片段取self的一段代码,用于将CoreImage/Coregraphics转换为UIKit:CGAffineTransformt=CGAffineTransformMakeScale(1,-1);t=CGAffineTransformTranslate(t,0,-imageView.bounds.size.height);基本上你需要:对y轴取反根据Vie

swift : Streaming/Writing out a CSV file

我正在使用我的手机记录一些传感器数据并通过SQLite通过SharkORM(DBAccess)将其存储在设备上。我现在想将该数据写入CSV文件,但是,我现在有多达160万条记录。目前,我正在遍历1000条记录,将它们添加到一个字符串中,最后将它们写出。但是,一定有更好的方法吗?funcwriteRawFile(){letfileName="raw"letDocumentDirURL=try!FileManager.default.url(for:.documentDirectory,in:.userDomainMask,appropriateFor:nil,create:true)le

swift - 当你在 swift 中运行弃用的代码时会发生什么?

例如在iOS10中有UserNotifications框架。在此之前,您只需使用:letsettings=UIUserNotificationSettings(types:[.alert,.badge,.sound],categories:nil)application.registerUserNotificationSettings(settings)application.registerForRemoteNotifications()(我在iOS10上运行上面的代码,没有任何反应)。我的一般性问题是:是否会一直运行已弃用的语法崩溃,什么也不做(就像现在一样)或者它如何处理是未知的