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
118
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
  • 4,078
  • 3
  • 15
  • 35
114
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,664
  • 4
  • 17
  • 27
113
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
  • 12,745
  • 9
  • 57
  • 95
109
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,757
  • 2
  • 16
  • 34
108
votes
6 answers

What's ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES with CocoaPods, Swift 3 and Xcode 8

after installing cocoapods and adding pod "SwiftCarousel" to pod file and uncomment the platform :ios, '9.0' I got this ERROR ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES and what should I do? mohammed.elias$ pod install Analyzing…
MEH
  • 1,777
  • 3
  • 15
  • 34
108
votes
8 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
  • 2,077
  • 2
  • 16
  • 15
106
votes
11 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
  • 4,390
  • 4
  • 22
  • 30
106
votes
10 answers

How to apply the type to a NSFetchRequest instance?

In Swift 2 the following code was working: let request = NSFetchRequest(entityName: String) but in Swift 3 it gives error: Generic parameter "ResultType" could not be inferred because NSFetchRequest is now a generic type. In their documents they…
Deniss
  • 1,675
  • 2
  • 12
  • 13
103
votes
4 answers

How to get first four letters from string in Swift 3?

I am trying to do IFSCCode validation in swift, but the problem I'm facing is I am not able to fetch the first four letters in string. IFSC Code example: ABCD0200000 This is how an IFSC Code looks: First four characters in IFSC Code are always…
Rani
  • 3,333
  • 13
  • 48
  • 89
100
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,123
  • 3
  • 11
  • 14
96
votes
8 answers

Swap rootViewController with animation?

Im trying to swap to another root view controller with a tab bar; via app delegate, and I want to add transition animation. By default it would only show the view without any animation. let tabBar = self.instantiateViewController(storyBoard: "Main",…
Chris Mikkelsen
  • 3,987
  • 9
  • 29
  • 41
95
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,751
  • 6
  • 26
  • 22
94
votes
6 answers

Attempt to insert non-property list object when trying to save a custom object in Swift 3

I have a simple object which conforms to the NSCoding protocol. import Foundation class JobCategory: NSObject, NSCoding { var id: Int var name: String var URLString: String init(id: Int, name: String, URLString: String) { …
Isuru
  • 30,617
  • 60
  • 187
  • 303
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
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,968
  • 12
  • 68
  • 113