swift3

Swift 3; Range 'Out of bounds'

限于喜欢 提交于 2019-12-22 08:13:53
问题 I've just updated Xcode to 8.0 beta 2 and swift 3.0. After updating from swift 2.3 i'm getting a lot of errors. I have a String-extension that's converting a Range in the "self"-string to a NSRange: extension String { func NSRangeFromRange(_ range : Range<String.Index>) -> NSRange { let utf16view = self.utf16 let from = String.UTF16View.Index(range.lowerBound, within: utf16view) let to = String.UTF16View.Index(range.upperBound, within: utf16view) print("to: \(to) from: \(from)") print(self

Crash requesting authorisation to Photos Library in iOS 10

回眸只為那壹抹淺笑 提交于 2019-12-22 08:11:45
问题 I have a sample iOS 10 application requesting authorisation to the Photos Library and crashing on a real device with the following crash error: PhotosAuthorizationCrashTest[2014:42551] [access] <private> The repo can be found here Here's the code that requests authorisation (Swift 3.0): private func requestAuthorizationIfNeeded() { DispatchQueue.main.async { let status = PHPhotoLibrary.authorizationStatus() if status == .authorized { return } PHPhotoLibrary.requestAuthorization({ (status) in

White line below UIRefreshControl when pulled.. tableView

余生颓废 提交于 2019-12-22 08:04:14
问题 I am implementing a very basic Refresh control... var refreshControl = UIRefreshControl() refreshControl.addTarget(self, action: Selector(("refresh:")), for: UIControlEvents.valueChanged) refreshControl.backgroundColor = UIColor.red self.tableView.addSubview(refreshControl) for some reason though whenever I pull down to refresh it's like the refresh control cannot keep up with the table view and there is a white gap between the two. here is the problem on the simulator... it is worse on the

How to select buttons in tvOS menu for SpriteKit game

家住魔仙堡 提交于 2019-12-22 07:59:54
问题 I am extending my iOS game for tvOS. Most of the game controls are handled by touchesBegan , touchesMoved and touchesEnded . All my select buttons are handled in the following way: if button1.contains(location){ let gameplayScene = GamePlayScene(size: self.size) self.view?.presentScene(gameplayScene) } if button2.contains(location){ let settingsScene = SettingsScene(size: self.size) self.view?.presentScene(settingsScene) } if button3.contains(location){ let helpScene = HelpScene(size: self

Firebase Accessing Snapshot Value Error in Swift 3

血红的双手。 提交于 2019-12-22 06:59:23
问题 I recently upgraded to swift 3 and have been getting an error when trying to access certain things from a snapshot observe event value. My code: ref.child("users").child(userID!).observeSingleEvent(of: .value, with: { (snapshot) in let username = snapshot.value!["fullName"] as! String let homeAddress = snapshot.value!["homeAddress"] as! [Double] let email = snapshot.value!["email"] as! String } The error is around the three variables stated above and states: Type 'Any' has no subscript

Unable to update local scheduled notification content

早过忘川 提交于 2019-12-22 06:35:22
问题 In one of the WWDC sessions I got code snippet for updating existing notifications. I don't think it works. Trying to update notification content. First I request pending notifications from UNUserNotificationCenter which always works. Then I am creating new request to update notification with existing unique identifier. There's 1 new variable content: String . // Got at least one pending notification. let triggerCopy = request!.trigger as! UNTimeIntervalNotificationTrigger let interval =

swift 3.0 How can I access `AnyHashable` types in `Any` in Swift 3?

不打扰是莪最后的温柔 提交于 2019-12-22 06:33:13
问题 I'm using sqlite file to get the diaryEntriesTeacher from the authorId. it generates the following object of authorId when I print the variable authorId is nil Code :- func applySelectQuery() { checkDataBaseFile() objFMDB = FMDatabase(path: fullPathOfDB) objFMDB.open() objFMDB.beginTransaction() do { let results = try objFMDB.executeQuery("select * from diaryEntriesTeacher", values: nil) while results.next() { let totalCount = results.resultDictionary let authorId = totalCount?["authorId"]!

FileManager and urlsForDirectory Error in Swift 3 Xcode 8

末鹿安然 提交于 2019-12-22 05:50:05
问题 I just went to Xcode 8 beta 4 from beta 3 but for what ever reason I am getting this error that has worked with no errors or issued until beta 4. here is the error" Value of type 'FileManager' has no member 'urlsForDirectory' " my code: func setupRecorder(){ let audioSession:AVAudioSession = AVAudioSession.sharedInstance() //ask for permission if (audioSession.responds(to: #selector(AVAudioSession.requestRecordPermission(_:)))) { AVAudioSession.sharedInstance().requestRecordPermission({

How to get the current displaying UIViewController not in AppDelegate?

杀马特。学长 韩版系。学妹 提交于 2019-12-22 05:35:56
问题 I'm trying to get the currently display UIViewController that is not in the AppDelegate, but it seems to always get the initial top UIViewController , and not the present one. The following code in AppDelegate DOES get the current UIViewController present, but this same function does not work when I use it in any one of my View Controllers: func getTopViewController() -> UIViewController { var topViewController = UIApplication.sharedApplication().delegate!.window!!.rootViewController! while

Error: Attemped to add a SKNode which already has a parent

﹥>﹥吖頭↗ 提交于 2019-12-22 05:14:20
问题 I'm doing a game with Swift 3 and SpriteKit and I'm trying to declare a global variable to work with it in the rest of the GameScene class but I can't. What I did: class GameScene: SKScene { ... let personaje = SKSpriteNode(imageNamed: "Ball2.png") ... After the global declaration I tried to use it in the sceneDidLoad just like that: ... personaje.position = CGPoint.zero addChild(personaje) ... I don't know why but Xcode returns this error: *** Terminating app due to uncaught exception