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
37
votes
2 answers

Present a view controller, dismiss it and present a different one in Swift

I have a root view controller that has a button that when the user pushes it, another view controller is presented. This second controller has a dismiss option that just comes back to the root view controller and a button that when the user touches…
ravelinx
  • 1,557
  • 4
  • 18
  • 26
37
votes
7 answers

Conforming to Hashable protocol?

I'm trying to make a dictionary with the key as a struct I've created and the value as an array of Ints. However, I keep getting the error: Type 'DateStruct' does not conform to protocol 'Hashable' I'm pretty sure I've implemented the necessary…
MarksCode
  • 8,074
  • 15
  • 64
  • 133
37
votes
8 answers

How can I decode JWT (JSON web token) token in Swift?

I have a JWT token like this eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ How can I decode this so that I can get the payload like this { …
37
votes
4 answers

Swift 3 - How to verify class type of object

This line of code used to work with Swift 2, but now is incorrect in Swift 3. if gestureRecognizer.isMember(of: UITapGestureRecognizer) { } I get this error: Expected member name or constructor call after type name. What is the correct way to use…
Van Du Tran
  • 6,736
  • 11
  • 45
  • 55
37
votes
7 answers

Converting Int to Bool

In Swift 2.x I believe I could do: let number = 1 let result = Bool(number) print(result) // prints out: true But since Swift 3 I've been unable to do this and it gives me the error: Cannot invoke initialiser for type 'Bool' with an argument list…
Henny Lee
  • 2,970
  • 3
  • 20
  • 37
37
votes
3 answers

Deleting all data in a Core Data entity in Swift 3

Is there a way to do a batch delete of all data stored in all of the entities in core data? I read somewhere that in iOS 9 or 10 that apple introduced a way to do batch deletes, but I can't seem to find any good information on it. Ultimately, I just…
John Hubler
  • 877
  • 1
  • 11
  • 27
37
votes
8 answers

Xcode 8 very slow Swift compiling

Ever since Swift 3 and Xcode 8 my project compiles quite slowly. Every time I add so much as an empty line to a file, recompiling takes a full minute. When I check the output, there is no particular file that takes very long. (I also used this tool…
fancy
  • 2,077
  • 2
  • 23
  • 45
37
votes
3 answers

Can't use private property in extensions in another file

I can't use private property in extension. My extension is in another file. How can I use private property in extension?
Oniikal3
  • 567
  • 1
  • 6
  • 14
37
votes
1 answer

UIView.animate - Swift 3 - completion

How do I do a simple completion block in Swift 3? I want to set self.isOpen = true in the completion of the animation: UIView.animate(withDuration: 0.25, delay: 0.0, options: [], animations: { self.isOpen = true …
Chris Allinson
  • 1,837
  • 2
  • 26
  • 39
37
votes
5 answers

swift 3 error : Argument labels '(_:)' do not match any available overloads

Just converted a project to Swift 3 and cant figure out the following error. public func currencyString(_ decimals: Int) -> String { let formatter = NumberFormatter() formatter.numberStyle = .currency formatter.maximumFractionDigits =…
Mike U
  • 2,901
  • 10
  • 32
  • 44
37
votes
4 answers

Whats the Swift animate WithDuration syntax?

I'm porting an older app over to Xcode 7 beta and I'm getting an error on my animations: Cannot invoke 'animateWithDuration' with an argument list of type '(Double, delay: Double, options: nil, animations: () -> _, completion: nil)' Here's the…
Dan Beaulieu
  • 19,406
  • 19
  • 101
  • 135
36
votes
5 answers

Cyclomatic Complexity Violation: Function should have complexity 10 or less: currently complexity equals 13 (cyclomatic_complexity)

I have the following code in swift3 and i am using swift lint for linting the code. The code is given as follows: func selectedMenuInLoggedOutState(sender: UIButton) { switch sender.tag { case 1: if let menu =…
Chelsea Shawra
  • 1,593
  • 4
  • 22
  • 43
36
votes
9 answers

How to remove the ChildViewController from Parent View Controller in Swift 3

I am developing an IOS Application. I have added the UIViewController in View Pager. I want to reinitialize it when the language is changed. Here I want to remove all child UIViewController from UIViewPager and again back to add all UIViewController…
Noorul
  • 3,386
  • 3
  • 32
  • 54
36
votes
12 answers

Trim only trailing whitespace from end of string in Swift 3

Every example of trimming strings in Swift remove both leading and trailing whitespace, but how can only trailing whitespace be removed? For example, if I have a string: " example " How can I end up with: " example" Every solution I've…
Jason Sturges
  • 15,855
  • 14
  • 59
  • 80
36
votes
6 answers

What is the modulus operator (%) in swift 3?

I have this line: randomIndex = Int(drand48() % Double(alphabetColors.count)) And Xcode 8 (Swift 3) tells me: '%' is unavailable: Use truncatingRemainder instead Is there no operator anymore? How should I convert my code?
Kalzem
  • 7,320
  • 6
  • 54
  • 79