Tag: swift2

com.apple.product-type.bundle.ui-testing,但是'iphonesimulator'平台没有这样的产品types

我使用Xcode 7 Beta来开发这个项目 现在我切换到Xcode 6.4 所以我现在有这个问题 我已经尝试干净,但它不工作 target指定产品types“com.apple.product-type.bundle.ui-testing”,但“iphonesimulator”平台没有这种产品types

在Swift中使用Object InitializerreplaceAllocWithZone

我最近从Xcode 7 beta 4更新了我的Xcode到Xcode 7 beta 5,并开始出现以前没有的错误。 那就是:“AllocWithZone在Swift中不可用:改为使用Object Initializers”。 这里是find错误的代码: public func copyWithZone(zone: NSZone) -> AnyObject { let copy = self.dynamicType.allocWithZone(zone) as ChartDataSet copy.colors = colors copy.label = self.label return copy } 我用什么替代“.allocWithZone”,以便它利用对象初始值设定项代替这个对象C组件?

在for语句中使用String.CharacterView.Index.successor()

将来, C语言的语句将从Swift中删除 。 虽然有很多替代方法可以使用C语言,比如使用stride或..<运算符,但这些运算符只能在某些条件下使用 例如,在旧版本的swift中,可以循环使用C风格的string中的每一个索引String.CharacterView.Index , for var index = string.startIndex; index < string.endIndex; index = string.successor().successor(){ //code } 然而这已经被弃用了。 有一种方法可以做同样的事情,使用while循环 var index = string.startIndex while index < string.endIndex{ //code index = index.successor().successor() } 但它不是一个解决方法。 有一个..<运算符,这对于循环每个string的索引来说是完美的 for index in string.startIndex..<string.endIndex 然而,这并不能帮助循环遍历string的每一个索引,或者每个string的第n个索引 除了while循环之外,是否还有更多的“swifty”方式循环其他string的其他索引? 这个问题不仅适用于string索引,而且只适用于具有诸如.successor()函数的对象,其中stride和..<不起作用。

AVAudioPlayer不能播放声音

我有一个WatchKit应用程序,当在手表上点击一个button时,它会通知iOS应用程序播放声音。 出于某种原因,当我使用自定义类来处理设置AVAudioPlayer的实例并播放声音时,声音不会播放。 如果我在session:didReceiveMessage:replyHandler:做了这个部分session:didReceiveMessage:replyHandler:它会正常播放。 这是自定义类: import AVFoundation class ChildClass { let mySound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("test", ofType: "wav")!) var audioPlayer: AVAudioPlayer! func playSound() { do { print("Playing sound") self.audioPlayer = try AVAudioPlayer(contentsOfURL: mySound) self.audioPlayer.play() } catch { print("Error getting audio file") } } } 在我的ViewController中实例化的是: class ViewController: UIViewController, WCSessionDelegate { var session: WCSession! override func viewDidLoad() { […]

如何在MyAppUITests和MyApp目标之间dynamic共享数据?

在MyAppUITests我可以通过以下方式将一些parameter passing给MyApp: app.launchEnvironment = ["my_param": "value"] app.launch() 这是MyApp可见,我可以读这个: if let value = NSProcessInfo.processInfo().environment["my_param"] { //do sth with value } 但是,这是我可以设置之前,我启动应用程序。 出于某种原因,我需要在运行后改变"my_param" 后启动应用程序。 有什么build议么? 我将不胜感激任何帮助。 为什么我需要这样做? 启动应用程序后,我需要"my_param"才能在MyAppUITests进行更改。 "my_param"需要在MyApp中的任何地方都可见。 my_param可能是我的networking客户端的模拟响应,或者当时我需要的任何东西。 注意: App和它的扩展之间也有类似的function。 有App Group解决scheme,并共享NSUserDefaults 。 这里是什么? 我必须将它保存在设备上才能将其分享给另一个目标? 更新: App Group在这里不起作用。

Game Center框架图像找不到Xcode 7.0 Beta 4的错误

有没有人试图使用Xcode 7 Beta 4在真正的iPhone(iOS版本8.4)上运行应用程序时遇到此问题? dyld:Library not loaded:/System/Library/Frameworks/GameCenter.framework/GameCenter引用自:/ private / var / mobile / Containers / Bundle / Application / CC713E5A-7839-43F1-9AEB-932AE2A3DF8A / ….原因:图像未find 为了您的信息,在切换到Xcode 7之前,它一直没有错误…

将datestring转换为Int Swift

我想转换string: let time = "7:30" 整数: let hour : Int = 7 let minutes : Int = 30 我目前正在循环的string: for char in time.characters { } 但我不知道如何将一个字符转换为一个int。 任何帮助将不胜感激。

是快速性能不好的扩展?

Swift提供了编写扩展的function。 我做了很多工作,使我的代码更易于阅读。 不知道他们是否是无害的。 我想知道,由于性能的原因,最好是省略扩展?

NSValue(CMTime:)在swift 3?

我有这个代码 var times = [NSValue]() for time in timePoints { times.append(NSValue(CMTime : time)) } 我得到一个错误,他们是没有什么叫CMTime在迅速3我不能真正find任何参数厘米时间..

添加Parse.com 1.11.0到watchOS 2

在parsingSDK更新到1.11.0它说它支持watchOS和tvOS。 我想知道如何使用Cocoapods将框架添加到我的watchOS应用程序中。 该pod文件包含pod 'Parse' ,我已经运行pod update然后pod install但是当我添加一个桥接头到watchOS 2扩展它说没有find文件。 你知道我应该做什么吗? 谢谢