swift2

Runtime complexity of getting the length of a string in different representations

你说的曾经没有我的故事 提交于 2020-01-01 19:26:13
问题 In Swift 2, given a string s , what's the runtime complexity of these statements: s.characters.count s.endIndex s.utf8.count s.utf16.count s.unicodeScalars.count Also, if I know a string contains alphabets only, what's the most efficient way of getting the n-th character? 回答1: OK, I'm trying to answer my own question. Feel free to correct me if I'm wrong. s.characters.count // O(N) s.endIndex // O(1) s.utf8.count // O(N) s.utf16.count // O(N) s.unicodeScalars.count // O(N) Apple's

Reflection in swift 2

被刻印的时光 ゝ 提交于 2020-01-01 16:43:10
问题 I have a class User: import UIKit import ObjectMapper class User: NSObject, CustomStringConvertible, Mappable { var FirstName: NSString! ; var LastName: NSString! ; required init?(_ map: Map){ } func mapping(map: Map) { FirstName <- map["FirstName"] LastName <- map["LastName"] } override var description:String { var s:String="" //USE REFLECTION TO GET NAME AND VALUE OF DATA MEMBERS for var index=1; index<reflect(self).count; ++index { s += (reflect(self)[index].0 + ": "+reflect(self)[index].1

Nested Closures in Swift 2.1

别说谁变了你拦得住时间么 提交于 2020-01-01 14:36:58
问题 I want to clear about Nested Closures in Swift 2.1 Here I declare a nested closure, typealias nestedDownload = (FirstItem: String!)-> (SencondItem: String!)->Void Then I use this nestedDownload closure as a parameter of the following function and try to complete the compliletion parameter value in function like as func nestedDownloadCheck(compliletion:nestedDownload){ compliletion(FirstItem: "firstItem") } But this says the error, " Expression resolves to an unused function " Also , when I

Nested Closures in Swift 2.1

核能气质少年 提交于 2020-01-01 14:36:50
问题 I want to clear about Nested Closures in Swift 2.1 Here I declare a nested closure, typealias nestedDownload = (FirstItem: String!)-> (SencondItem: String!)->Void Then I use this nestedDownload closure as a parameter of the following function and try to complete the compliletion parameter value in function like as func nestedDownloadCheck(compliletion:nestedDownload){ compliletion(FirstItem: "firstItem") } But this says the error, " Expression resolves to an unused function " Also , when I

Nested Closures in Swift 2.1

拈花ヽ惹草 提交于 2020-01-01 14:36:13
问题 I want to clear about Nested Closures in Swift 2.1 Here I declare a nested closure, typealias nestedDownload = (FirstItem: String!)-> (SencondItem: String!)->Void Then I use this nestedDownload closure as a parameter of the following function and try to complete the compliletion parameter value in function like as func nestedDownloadCheck(compliletion:nestedDownload){ compliletion(FirstItem: "firstItem") } But this says the error, " Expression resolves to an unused function " Also , when I

Swift 2: AVAudioPlayers to play multiple sounds at once

你。 提交于 2020-01-01 12:15:24
问题 So hey I've been searching around, trying to find a way to solve this, but there's basically no solutions to this yet. I desperately need a way to instantiate and play a sound whenever I want, without it cutting out any other sounds. I know that AVAudioPlayer can only play one sound at a time, so I'm trying to figure out how to make a dynamic array of AVAudioPlayers that I can add to any time I need to play a sound. My current code, that I got from a different answer on this site, is this:

Swift 2: AVAudioPlayers to play multiple sounds at once

谁说胖子不能爱 提交于 2020-01-01 12:15:09
问题 So hey I've been searching around, trying to find a way to solve this, but there's basically no solutions to this yet. I desperately need a way to instantiate and play a sound whenever I want, without it cutting out any other sounds. I know that AVAudioPlayer can only play one sound at a time, so I'm trying to figure out how to make a dynamic array of AVAudioPlayers that I can add to any time I need to play a sound. My current code, that I got from a different answer on this site, is this:

Allow users background music in swift 2.0

喜你入骨 提交于 2020-01-01 09:04:03
问题 I am looking for some code to allow the user to play music from their phone while still using my app. Previously before swift 2.0 i would put this in the app delegate and it would work perfectly: AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient, error: nil) AVAudioSession.sharedInstance().setActive(true, error: nil) Does anyone know how to implement this in swift 2.0? 回答1: The following would be the syntax for Swift 2 calling setCategory and setActive on AVSession :

Allow users background music in swift 2.0

孤者浪人 提交于 2020-01-01 09:02:03
问题 I am looking for some code to allow the user to play music from their phone while still using my app. Previously before swift 2.0 i would put this in the app delegate and it would work perfectly: AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient, error: nil) AVAudioSession.sharedInstance().setActive(true, error: nil) Does anyone know how to implement this in swift 2.0? 回答1: The following would be the syntax for Swift 2 calling setCategory and setActive on AVSession :

SKAudioNode() crashes when plugging in/out headphones

时光毁灭记忆、已成空白 提交于 2020-01-01 08:34:06
问题 I am using a SKAudioNode() to play background music in my game. I have a play/pause function and everything is working fine until I plug in my headphones. There is no sound at all and when I call the pause/play function I get this error AVAudioPlayerNode.mm:333: Start: required condition is false: _engine->IsRunning() com.apple.coreaudio.avfaudio', reason: 'required condition is false: _engine->IsRunning() Does anyone knows what this means? Code: import SpriteKit class GameScene: SKScene {