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
41
votes
4 answers

How to set edgesForExtendedLayout to none in Swift 3

The problem is that my View, containing a UIView and a UITableView within a ScrollView, gets hidden under the UINavigationBar if set translucent. I have considered several threads like this, but they all suggest to set: self.edgesForExtendedLayout…
David Seek
  • 16,783
  • 19
  • 105
  • 136
41
votes
7 answers

Draw text along circular path in Swift for iOS

I am looking for some up to date help/hints on how to draw simple single line strings around the edge of a circle using Swift2 for iOS9. I see quite dated examples involving old ObjC fragments, and oft limited to OS X only. Is this even possible in…
Travis Griggs
  • 21,522
  • 19
  • 91
  • 167
40
votes
3 answers

What is the equivalent of a Java HashMap in Swift

I have an example written in Java that I would like to convert into Swift. Below is a section of the code. I would really appreciate if you can help. Map someProtocol = new HashMap<>(); someProtocol.put("one",…
Juventus
  • 661
  • 1
  • 8
  • 13
40
votes
2 answers

How to override localizedDescription for custom Error in Swift 3?

Error protocol has only one property localizedDescription. I tried to create custom object inherited from NSObject and Error but I can not override localizedDescription. How can I do that? This code does not allow me to get custom description: class…
Maxim Kholyavkin
  • 4,463
  • 2
  • 37
  • 82
40
votes
1 answer

Strange generic function appear in view controller after converting to swift 3

In my project, after converting to swift 3, a new function appeared before my ViewController class: fileprivate func < (lhs: T?, rhs: T?) -> Bool { switch (lhs, rhs) { case let (l?, r?): return l < r case (nil, _?): …
Bright
  • 5,699
  • 2
  • 50
  • 72
40
votes
1 answer

Error Handling in Swift 3

I'm migrating my code over to Swift 3 and see a bunch of the same warnings with my do/try/catch blocks. I want to check if an assignment doesn't return nil and then print something out to the console if it doesn't work. The catch block says it "is…
Bleep
  • 431
  • 1
  • 4
  • 8
40
votes
1 answer

How has the NSIndexPath initialization changed in Swift3?

I'm trying to follow along with Apple's Start Developing iOS Apps (Swift) tutorial and have almost completed it. I have had to amend several parts of the tutorial as I'm using Xcode 8 (which I think uses Swift 3 instead of Swift 2). However, I am…
Garry Pettet
  • 8,096
  • 22
  • 65
  • 103
39
votes
7 answers

Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font'

Just updated pods for xcode 9 and I'm getting the error below for Cosmos. Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font'
Chaudhry Talha
  • 7,231
  • 11
  • 67
  • 116
39
votes
2 answers

Read JSON file with Swift 3

I have a JSON file called points.json, and a read function like: private func readJson() { let file = Bundle.main.path(forResource: "points", ofType: "json") let data = try? Data(contentsOf: URL(fileURLWithPath: file!)) let jsonData =…
Xie
  • 627
  • 1
  • 8
  • 18
39
votes
1 answer

Type 'Any' Has no Subscript Members in xcode 8 Swift 3

My App is supposed to go to a specific location to pull down the website it needs to load. In 2.3 it worked like a charm, but since I've updated xcode (which I don't have a ton of experience in) it is giving me the error "type 'Any' has no subscript…
DaVinci1223
  • 391
  • 1
  • 3
  • 3
38
votes
3 answers

How to use Notification.Name extension from Swift to Objective-C?

I created an extension for Notification.Name as below: public extension Notification.Name { public static let blahblahblah = Notification.Name(rawValue: "blahblahblah") } Now I want to use this extension in Objective-C, but it's not accessible…
BARS
  • 629
  • 1
  • 6
  • 18
38
votes
10 answers

"Invalid Token" when trying to authenticate phone number using firebase

This is my code: import FirebaseAuth class AuthPhoneNum { static func getPhoneNum(phoneNumber: String) { PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber) { (verificationID, error) in if let error = error { …
Jordan Tate
  • 381
  • 1
  • 3
  • 7
38
votes
1 answer

What's the difference between Error and NSError in Swift?

I am creating a library that should return errors so I'm wondering which one should use for my purposes. UPDATE: I should clarify, the returned result will be from a asynchronous call so I need to inform to the user if there was an error and I…
Wilson
  • 9,006
  • 3
  • 42
  • 46
38
votes
7 answers

Download File Using Alamofire 4.0 (Swift 3)

In older version of Alamofire. This is how I download file let destinationPath = Alamofire.Request.suggestedDownloadDestination( directory: .documentDirectory, domain: .userDomainMask); Alamofire.download(.GET, urlString, destination:…
JayVDiyk
  • 4,277
  • 22
  • 70
  • 135
38
votes
2 answers

Why is 'nil' not compatible with 'UnsafePointer' in Swift 3?

Trying to create a CGMutablePath() as such: let path = CGMutablePath() CGPathMoveToPoint(path, nil, 30, 0) but the compiler keeps on giving me the following error: 'nil' not compatible with expected argument type…
cyril
  • 3,020
  • 6
  • 36
  • 61