swift3

How do I write a for-loop in Swift 3 for an array that I modify during the for loop?

柔情痞子 提交于 2019-12-31 10:17:25
问题 So, I have a for-loop that looks similar to this: for var i = 0; i < results.count ; i += 1 { if (results[i] < 5) { results.removeAtIndex(i) i -= 1 } } This used to work. But when I changed it to the preferred Swift 3.0 syntax: for var i in 0..<results.count { if (results[i] < 5) { results.removeAtIndex(i) i -= 1 } } I get an array IOOBE exception because it doesn't re-check the count and continues on until the original results.count . How do I fix this? It works now, but I don't want to get

'openURL' was deprecated in iOS 10.0: Please use openURL:options:completionHandler: instead in Swift 3 [duplicate]

烂漫一生 提交于 2019-12-31 09:11:47
问题 This question already has answers here : how to open an URL in Swift3 (6 answers) Closed 2 years ago . I have working open webLink url codes in Swift3 but when I use it gives me this warning; 'openURL' was deprecated in iOS 10.0: Please use openURL:options:completionHandler: instead How can I resolve it, my codes under below. let myUrl = "http://www.google.com" if !myUrl.isEmpty { UIApplication.shared.openURL(URL(string: "\(myUrl)")!) } Thank you. 回答1: Use like //inside scope use this let

Usage of where in if let assignment in Swift

爷,独闯天下 提交于 2019-12-31 08:34:27
问题 The Swift documentation at page 61 of the Swift manual hints to the possibility of using where to join an optional binding with a regular condition. Yet when I do it I have a warning suggesting me to substitute the where with a comma like in the following piece of code: if let geocodingError = error as? NSError where geocodingError.code == 2 回答1: Example with two conditions if let x = y, let a = b, a == x && !x.isEmpty { 回答2: In Swift 3 this syntax has changed. What was if let x = y, a = b

How to pass data back to ViewController holding Container View and TableViewController that is embedded in the Container? Swift 3

和自甴很熟 提交于 2019-12-31 07:43:07
问题 How can I call func checkField when nextButton is tapped? If no field is empty in ManagedTableEleventhViewController, I'd like to segue to TwelvethViewController. I have a UIViewController ElevethViewController which holds a container view. The container view has an embed segue to a UITableViewController ManagedTableEleventhViewController . From ElevethViewController there is a Show segue to a UIViewController TwelevethViewController The View hierarchy looks like this: ElevethViewController

How to pass data back to ViewController holding Container View and TableViewController that is embedded in the Container? Swift 3

女生的网名这么多〃 提交于 2019-12-31 07:42:07
问题 How can I call func checkField when nextButton is tapped? If no field is empty in ManagedTableEleventhViewController, I'd like to segue to TwelvethViewController. I have a UIViewController ElevethViewController which holds a container view. The container view has an embed segue to a UITableViewController ManagedTableEleventhViewController . From ElevethViewController there is a Show segue to a UIViewController TwelevethViewController The View hierarchy looks like this: ElevethViewController

Swift 3 - full width of UITabBarItem for selectionIndicatorImage

…衆ロ難τιáo~ 提交于 2019-12-31 07:15:07
问题 i have a UITabBar with three tabs. Now I want to assign or lets say to fill the complete width of one tab to the related selectionIndicatorImage cause currently I got a border if a tab is selected. Like the tab on the left side shows in the following screenshot: I made a subclass of UITabBar with a new property: var activeItemBackground:UIColor = UIColor.white { didSet { let numberOfItems = CGFloat((items!.count)) let tabBarItemSize = CGSize(width: frame.width / numberOfItems, height: frame

Daily scheduled notifications

感情迁移 提交于 2019-12-31 06:10:30
问题 I need a bit of guidance, so for my application i'm looking at using local notifications to send a notification every morning at 7 o'clock. The issue i'm having is how can i make the content for the local notification dynamic mainly the body and the attached image? As it will vary for the user on a daily basis. What would be the best way to go about this since you can't edit future notifications. 回答1: Here's a little lesson about notifications. First, what is a notification? It's basically an

Daily scheduled notifications

谁都会走 提交于 2019-12-31 06:10:10
问题 I need a bit of guidance, so for my application i'm looking at using local notifications to send a notification every morning at 7 o'clock. The issue i'm having is how can i make the content for the local notification dynamic mainly the body and the attached image? As it will vary for the user on a daily basis. What would be the best way to go about this since you can't edit future notifications. 回答1: Here's a little lesson about notifications. First, what is a notification? It's basically an

I am getting data from json web services but unable to display it on my ui

巧了我就是萌 提交于 2019-12-31 05:27:09
问题 here I am having problem that I am able to get the data from json web services but unable to display on my ui in the program I mentioned where I am getting error and what it is also mentioned there can anyone help me ? class DetailsViewController: UIPageViewController{ @IBOutlet var navigationBar: UINavigationBar! @IBOutlet var imageView: UIImageView! @IBOutlet var pageControl: UIPageControl! @IBOutlet var nameLabel: UILabel! @IBOutlet var priceLabel: UILabel! @IBOutlet var textview:

Check Landscape/Portrait orientation in an iMessage app (extension)

ε祈祈猫儿з 提交于 2019-12-31 05:23:10
问题 Have seen a lot of solutions to check the orientation, but strangely, none works!! Below is the code snippet, override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { let screenSize = UIScreen.main.bounds let screenWidth = screenSize.width let screenHeight = screenSize.height print("Screen Width = \(screenWidth)") print("Screen Height = \(screenHeight)") if (screenWidth > screenHeight) { print("Landscape") alertView.removeFromSuperview()