Tag: 迅速

错误使用Swift – 实例成员不能用于types'ViewController'

我一直在尝试使用Swift在Xcode 7中创build一个应用程序,我试图使用这个代码将文本字段内的数字转换为整数, let a = Int(percentLabel.text!) 但每次我尝试这个,我得到一个错误,说Instance Member 'percentLabel' cannot be used on type 'ViewController' 我不知道为什么我得到这个错误,也许这是我已经在Xcode 7中find的错误。 这是我的完整代码。 import UIKit class ViewController: UIViewController { @IBOutlet var tipSlider: UISlider! @IBOutlet var splitSlider: UISlider! @IBOutlet var billAmount: UITextField! @IBOutlet var totalLabel: UILabel! @IBOutlet var tipTotal: UILabel! @IBOutlet var totalPerPerson: UILabel! @IBOutlet var percentLabel: UILabel! @IBOutlet var splitLabel: […]

时间比较迅速

题: 我需要比较2次 – 当前时间和一个。 如果设定的时间是未来的时间,则查明在未来的时间内剩余多less分钟。 其他信息: 我目前正在使用 let date = NSDate() let calendar = NSCalendar.currentCalendar() let components = calendar.components(.CalendarUnitHour | .CalendarUnitMinute, fromDate: date) let hour = components.hour let minutes = components.minute 我从另一个关于如何以Int格式获取当前时间的答案偷了。 然后我把未来的时间分成小时(Int)和分钟(Int),然后比较这些……但是当你超过小时障碍时,这会变得很奇怪。

使用Swift从您的应用程序发送消息到WhatsApp?

对于我的一个应用程序,我想分享数据到WhatsApp联系人。 我尝试了几个解决scheme,超过了StackOverflow,但不能得到确切的解决scheme。 经过一些试验可以实现我所期望的,所以在这里分享给任何人的未来参考。

默认应用程序尚未configuration

我正在尝试将我的应用升级到新版本的Firebase。 我浏览了设置指南,并编辑了所有的代码以匹配新的语法。 但是,当我运行应用程序,我得到这两个错误。 The default app has not been configured yet. Terminating app due to uncaught exception 'MissingDatabaseURL', reason: 'Failed to get FIRDatabase instance: FIRApp object has no databaseURL in its FirebaseOptions object.' 我在AppDelegate中有FIRApp.configure() ,并将GoogleServices-Info.plist导入到我的项目中。 plist也有所有正确的信息。 任何人遇到这个问题或知道如何解决它?

从Any到Downcast协议

我有以下代码。 如何解决最后一行中的错误? protocol Animal { func walk() } struct Cat: Animal { func walk() {} init() { } } var obj: Any = Cat() var cat = obj as Animal // ERROR: cannot downcast from Any to unrelated type Animal

如何通过@objc标签传递快速枚举

我需要定义一个可以在一个使用Objective-ctypes的类中调用的协议 但是这样做不起作用: enum NewsCellActionType: Int { case Vote = 0 case Comments case Time } @objc protocol NewsCellDelegate { func newsCellDidSelectButton(cell: NewsCell, actionType: NewsCellActionType) } 你得到他的错误 Swift enums cannot be represented in Objective-C 如果我没有把@objc标签放在我的协议上,只要在一个类中调用应用程序就会使应用程序崩溃,这个类采用了从Objective-C类类(如UIViewController)inheritance的协议。 所以我的问题是,我应该如何声明并通过@objc标签传递我的枚举?

我如何轻松删除Realm中的所有对象

我有做迁移的select,但我宁愿删除我的defaultRealm()中的一切。 我怎样才能轻松做到这一点? realm.deleteObject(object) 是与.deleteObjects一起的唯一函数。 我已经尝试了下面的代码: 方法1 realm.deleteObjects(RLMObject.objectsInRealm(realm, withPredicate: NSPredicate(value: true))) 方法2 realm.deleteObjects(Dog.allObjectsInRealm(realm)) realm.deleteObjects(Person.allObjectsInRealm(realm)) realm.deleteObjects(Goal.allObjectsInRealm(realm)) realm.deleteObjects(Goals.allObjectsInRealm(realm)) 两者都无法阻止迁移exception。

在Swift中声明全局variables

我想创build一个可以在整个应用程序(AppDelegate,ViewController类,TableViewController类等)访问的自定义对象的全局数组。 我研究了一种方法来做到这一点,但还没有find答案。 我曾尝试使数组为公共范围,但我得到一个编译器警告说, Declaring public variable from internal class ,当我尝试访问它在不同的文件中,我得到一个错误,说Use of unresolved identifier 'arrayObjectives' 我将如何去使全局访问应用程序中的所有文件的数组,我将在哪里实例化该数组?

使用SceneKit行原始types的笔触宽度

我正在尝试使用场景工具包复制此多维数据集图像形状(来自原始创build者的许可)。 到目前为止,我有线和顶点的绘图代码。 我不能使用图像,因为背景必须是透明的。 我正在尝试解决的具体问题是如何编辑SCNGeometryPrimitiveType.Line元素的描边宽度。 我创build线条的基本方式是这样的: private func squareVertices(length: Float) -> [SCNVector3] { let m = length/Float(2) let topLeft = SCNVector3Make(-mq, m+q, m+q) let topRight = SCNVector3Make( m+q, m+q, m+q) let bottomLeft = SCNVector3Make(-mq, -mq, m+q) let bottomRight = SCNVector3Make( m+q, -mq, m+q) return [topLeft, topRight, bottomLeft, bottomRight] } private func cubeFace() -> SCNGeometry { let […]

Swift – 从远端URL下载video并保存在相册中

我目前在我的应用程序中显示video,我希望用户能够将其保存到其设备图库/相册照片/相机胶卷。 这是我在做什么,但video不保存在相册中:/ func downloadVideo(videoImageUrl:String) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { //All stuff here print("downloadVideo"); let url=NSURL(string: videoImageUrl); let urlData=NSData(contentsOfURL: url!); if((urlData) != nil) { let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]; let fileName = videoImageUrl; //.stringByDeletingPathExtension let filePath="\(documentsPath)/\(fileName)"; //saving is done on main thread dispatch_async(dispatch_get_main_queue(), { () -> Void in urlData?.writeToFile(filePath, atomically: true); print("videoSaved"); }) } }) } […]