Questions tagged [swift3]

Use this tag only for questions directly related to changes in version 3 of Apple's Swift programming language. Use the tag [swift] for more general language questions, or the tags [ios], [cocoa], [apple-watch] etc for questions about developing on Apple platforms.

Swift 3 is the version of Apple's programming language Swift. It was released on September 13, 2016. The language is open source and available on Github (see ).

The development of Swift 3 and its goals can be viewed on the Swift Programming Language Evolution repository on Github.

For more information, please visit Swift's Getting Started page.

18453 questions
64
votes
10 answers

Decimal to Double conversion in Swift 3

I'm migrating a project from Swift 2.2 to Swift 3, and I'm trying to get rid of old Cocoa data types when possible. My problem is here: migrating NSDecimalNumber to Decimal. I used to bridge NSDecimalNumber to Double both ways in Swift 2.2: let…
Zaphod
  • 6,758
  • 3
  • 40
  • 60
64
votes
16 answers

Change Status Bar Background Color in Swift 3

In XCode 7.3.x ill changed the background Color for my StatusBar with: func setStatusBarBackgroundColor(color: UIColor) { guard let statusBar = UIApplication.sharedApplication().valueForKey("statusBarWindow")?.valueForKey("statusBar") as? UIView…
derdida
  • 14,784
  • 16
  • 90
  • 139
64
votes
17 answers

Xcode 8.0 Swift 3.0 slow indexing and building

I've installed Xcode 8.0 and converted Swift 2.2 to 3.0 (that process also took a lot of time, I just left my Mac running all night). I have not a big project (about 20 files). I am also using Pods. Indexing of previous Xcode version (< 8.0) worked…
Danny
  • 3,975
  • 4
  • 22
  • 35
64
votes
5 answers

Swift saving and retrieving custom object from UserDefaults

I have this in Playground using Swift 3, Xcode 8.0: import Foundation class Person: NSObject, NSCoding { var name: String var age: Int init(name: String, age: Int) { self.name = name self.age = age } required…
user773881
  • 845
  • 1
  • 8
  • 10
63
votes
2 answers

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

I have working open webLink url code 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 code under below. let myUrl =…
SwiftDeveloper
  • 7,244
  • 14
  • 56
  • 85
63
votes
3 answers

Usage of where in if let assignment in Swift

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…
Fabrizio Bartolomucci
  • 4,948
  • 8
  • 43
  • 75
63
votes
10 answers

Swift 3 Core Data Delete Object

Unfortunately the new Core Data semantics make me crazy. My previous question had a clean code that didn't work because of incorrect auto generation of header files. Now I continue my work with deleting objects. My code seems to be very simple:…
user6485277
63
votes
2 answers

How can I disambiguate a type and a module with the same name?

I'm trying to use Károly Lőrentey's B-tree based OrderedSet in a project. However, I'm running into an issue where I can't declare an unqualified OrderedSet because the name conflicts between Foundation's NSOrderedSet (imported as OrderedSet in…
zneak
  • 134,922
  • 42
  • 253
  • 328
62
votes
11 answers

Swift 3 - find number of calendar days between two dates

The way I did this in Swift 2.3 was: let currentDate = NSDate() let currentCalendar = NSCalendar.currentCalendar() var startDate : NSDate? var endDate : NSDate? // The following two lines set the `startDate` and `endDate` to the…
Vinod Vishwanath
  • 5,821
  • 2
  • 26
  • 40
61
votes
7 answers

Take a photo and save to photo library in Swift

I have a button "take a photo" and when pressed, it opens the camera, you take a photo and when you select "Use Photo", I want it saved to the photo library. I am able to do all but save to the library. This is the code I have to open the camera:
LizG
  • 2,246
  • 1
  • 23
  • 38
61
votes
7 answers

How set swift 3 UITextField border color?

Hello i have working no error codes for UITextfield border color change but when using it in Swift 3 dont change textfield border color and dont gives error. I need your help my codes under below. @IBOutlet weak var email: UITextField! @IBOutlet…
SwiftDeveloper
  • 7,244
  • 14
  • 56
  • 85
60
votes
12 answers

How to programmatically set action for barButtonItem in swift 3?

Here is what I used previously, var barButtonItem = UIBarButtonItem(image: backImgs, style: UIBarButtonItemStyle.plain, target: self, action: Selector("menuButtonTapped:")) But there is some syntax changes for Swift 3.
Bhanupriya
  • 1,202
  • 1
  • 9
  • 20
60
votes
3 answers

Swift 3 UnsafePointer($0) no longer compile in Xcode 8 beta 6

My code snipet as follows …: let defaultRouteReachability = withUnsafePointer(to: &zeroAddress) { SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0)) } … does no longer compile with the following error which I don't…
Stéphane de Luca
  • 12,745
  • 9
  • 57
  • 95
59
votes
7 answers

How to get country code using NSLocale in Swift 3

Could you please help on how to get country code using NSLocale in Swift 3 ? This is the previous code I have been using. NSLocale.currentLocale().objectForKey(NSLocaleCountryCode) as! String I can get Language Code as below in Swift…
digidhamu
  • 717
  • 1
  • 6
  • 12
59
votes
5 answers

Save dictionary in userdefaults in swift 3 with xcode 8

I am using the following code to save an object to UserDefaults (previously NSUserDefaults) using xcode 8: let defaults = UserDefaults.standard() defaults.set(someObject, forKey: "someObject") print(defaults.object(forKey: "someObject")) someObject…
alionthego
  • 8,508
  • 9
  • 52
  • 125