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.

18403 questions
101
votes
3 answers

round trip Swift number types to/from Data

With Swift 3 leaning towards Data instead of [UInt8], I'm trying to ferret out what the most efficient/idiomatic way to encode/decode swifts various number types (UInt8, Double, Float, Int64, etc) as Data objects. There's this answer for using…
Travis Griggs
  • 18,930
  • 17
  • 76
  • 137
100
votes
14 answers

Type of expression is ambiguous without more context Swift

I am getting a 'Type of expression is ambiguous without more context ' on this part of code from a project I am trying to upgrade to latest Swift version. I can't seem to figure it out. I tried different things but can't get it to work. The problem…
Florian VIDAL
  • 1,011
  • 2
  • 6
  • 6
100
votes
14 answers

Swift 3 - Comparing Date objects

I'm updating my app to Swift 3.0 syntax (I know it's still in beta but I want to be prepared as soon as it released). Until the previous Beta of Xcode (Beta 5) I was able to compare two Date objects using the operands <, > and ==. But in the latest…
beeef
  • 2,404
  • 3
  • 14
  • 25
99
votes
13 answers

Removing object from array in Swift 3

In my application I added one object in array when select cell and unselect and remove object when re-select cell. I used that code but give me error. extension Array { func indexOfObject(object : AnyObject) -> NSInteger { return (self…
Kamlesh Shingarakhiya
  • 2,537
  • 1
  • 13
  • 34
95
votes
8 answers

How to solve "String interpolation produces a debug description for an optional value; did you mean to make this explicit?" in Xcode 8.3 beta?

Since beta 8.3, zillions warnings "String interpolation produces a debug description for an optional value; did you mean to make this explicit?" appeared in my code. For example, the warning popped in the following situation up, where options could…
Stéphane de Luca
  • 10,239
  • 7
  • 45
  • 74
95
votes
11 answers

Bundle.main.path(forResource:ofType:inDirectory:) returns nil

Try not to laugh or cry -- I'm just getting back into coding after 20 years out... I've spent more than 4 hours looking at references and trying code snippets to get Bundle.main.path to open my text file so I can read in data for my app (my next…
95
votes
10 answers

Generate your own Error code in swift 3

What I am trying to achieve is perform a URLSession request in swift 3. I am performing this action in a separate function (so as not to write the code separately for GET and POST) and returning the URLSessionDataTask and handling the success and…
Rikh
  • 3,710
  • 2
  • 12
  • 33
94
votes
11 answers

Swift 3 - device tokens are now being parsed as '32BYTES'

I just updated from Xcode 7 to the 8 GM and amidst the Swift 3 compatibility issues I noticed that my device tokens have stopped working. They now only read '32BYTES'. func application(_ application: UIApplication,…
user1537360
  • 4,385
  • 6
  • 23
  • 22
94
votes
10 answers

Check if location services are enabled

I've been doing some research about CoreLocation. Recently, I encountered a problem that has been covered elsewhere, but in Objective C, and for iOS 8. I feel kinda silly asking this, but how can you check if location services are enabled using…
Brendan Chang
  • 1,178
  • 1
  • 8
  • 10
92
votes
4 answers

NotificationCenter issue on Swift 3

I'm learning Swift 3 and I'm trying to using NSNotificationCenter. Here is my code: func savePost(){ let postData = NSKeyedArchiver.archivedData(withRootObject: _loadedpost) UserDefaults.standard().object(forKey: KEY_POST) } func…
RoccoBerry
  • 951
  • 1
  • 7
  • 10
91
votes
10 answers

How to get time (hour, minute, second) in Swift 3 using NSDate?

How can you determine the hour, minute and second from NSDate class in Swift 3? In Swift 2: let date = NSDate() let calendar = NSCalendar.currentCalendar() let components = calendar.components(.Hour, fromDate: date) let hour = components.hour Swift…
SaRaVaNaN DM
  • 3,884
  • 3
  • 16
  • 28
89
votes
6 answers

How to make phone call in iOS 10 using Swift?

I want my app to be able to call a certain number when a button is clicked. I've tried to google it but there doesn't seem to have one for iOS 10 so far (where openURL is gone). Can someone put an example for me on how to do so? For instance like:…
user3175707
  • 1,013
  • 1
  • 11
  • 14
89
votes
4 answers

Singleton with properties in Swift 3

In Apple's Using Swift with Cocoa and Objective-C document (updated for Swift 3) they give the following example of the Singleton pattern: class Singleton { static let sharedInstance: Singleton = { let instance = Singleton() //…
RobertJoseph
  • 7,336
  • 9
  • 58
  • 100
87
votes
7 answers

How to convert Data to hex string in swift

I want the hexadecimal representation of a Data value in Swift. Eventually I'd want to use it like this: let data = Data(base64Encoded: "aGVsbG8gd29ybGQ=")! print(data.hexString)
marius
  • 1,712
  • 1
  • 13
  • 15
83
votes
7 answers

Convert NSDate to String in iOS Swift

I am trying to convert a NSDate to a String and then Change Format. But when I pass NSDate to String it is producing whitespace. let formatter = DateFormatter() let myString = (String(describing: date)) formatter.dateFormat = "yyyy-MM-dd…
iOS
  • 1,486
  • 1
  • 10
  • 19