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
58
votes
6 answers

Get Weekday from Date - Swift 3

I have looked around a bit, but didnt find a quick answer for this in swift 3. I get todays weekday like this: let weekday = Calendar.current.component(.weekday, from: Date()) But instead, i would like to get the weekday of a given date. How is…
Martin Vidic
  • 763
  • 1
  • 6
  • 19
58
votes
7 answers

Whither dispatch_once in Swift 3?

Okay, so I found out about the new Swifty Dispatch API in Xcode 8. I'm having fun using DispatchQueue.main.async, and I've been browsing around the Dispatch module in Xcode to find all the new APIs. But I also use dispatch_once to make sure that…
rickster
  • 124,678
  • 26
  • 272
  • 326
56
votes
3 answers

Swift-3 error: '-[_SwiftValue unsignedIntegerValue]: unrecognized selector

Following code was perfectly worked with old swift. This is an extension of String func stringByConvertingHTML() -> String { let newString = replacingOccurrences(of: "\n", with: "
") if let encodedData = newString.data(using:…
Tapas Pal
  • 7,073
  • 8
  • 39
  • 86
55
votes
5 answers

Sending an email from swift 3

I am trying to set up an app with send email option. I have this code: import Foundation import MessageUI import UIKit class emailClass: UIViewController, MFMailComposeViewControllerDelegate { override func viewDidLoad() { …
H.N.
  • 1,207
  • 2
  • 12
  • 28
55
votes
6 answers

"oldValue" and "newValue" default parameters names inside willSet / didSet unrecognized

I am currently writing Swift 3 code in Xcode 8. When using oldValue and newValue default parameters inside the willSet and didSet blocks, I am getting "unresolved identifier" compiler error. I have a very basic code as below var…
Adithya
  • 4,545
  • 3
  • 25
  • 28
54
votes
3 answers

Swift 3 - dynamic vs @objc

What's the difference between marking a method as @objc vs dynamic, when would you do one vs the other? Below is Apple's definition for dynamic. dynamic Apply this modifier to any member of a class that can be represented by Objective-C. When you…
Boon
  • 40,656
  • 60
  • 209
  • 315
54
votes
8 answers

Compile Time Incredibly Slow

My project consists of ~350 Swift files and ~40 cocoa pod dependencies. As soon as the entire project was migrated to Swift 3, build times have been INCREDIBLY slow and took a little over 3 minutes to completely compile. I've noticed that if I…
dhint4
  • 1,132
  • 2
  • 11
  • 25
54
votes
15 answers

Extra argument 'method' in call

Getting error while calling Alamofire request method in the latest version(4.0.0). The syntax is: Alamofire.request(urlString,method: .post, parameters: requestParams, encoding: .JSON, headers: [:]) the type of requestParam is [String:Any]
CMA
  • 1,528
  • 1
  • 11
  • 22
54
votes
14 answers

Alamofire Swift 3.0 Extra argument in call

I have migrated my project to Swift 3 (and updated Alamofire to latest Swift 3 version with pod 'Alamofire', '~> 4.0' in the Podfile). I now get an "Extra argument in call" error on every Alamofire.request. Eg: let patientIdUrl = baseUrl +…
Agreensh
  • 1,305
  • 1
  • 12
  • 15
54
votes
3 answers

Update CGRectMake to CGRect in Swift 3 Automatically

Now that CGRectMake , CGPointMake, CGSizeMake, etc. has been removed in Swift 3.0, is there any way to automatically update all initializations like from CGRectMake(0,0,w,h) to CGRect(x:0,y:0,width:w,height:h). Manual process is.. quite a pain. Not…
yonasstephen
  • 2,645
  • 4
  • 23
  • 48
53
votes
8 answers

invalid redeclaration in auto code generate NSManagedObject Subclass Swift 3

Using Version 8.1 of Xcode. Create an entity named "MapRegionObject" in .xcdatamodeld file. Using auto code generator, click Editor on the navigation bar -> create NSManagedOject Subclass... Got two files : MapRegionObject+CoreDataClass.swift and…
icelemon
  • 827
  • 2
  • 11
  • 23
53
votes
12 answers

Check internet connection (iOS 10)

For iOS 9 I was using Reachability public class to check wether the device is connected to the internet or not. I converted my Swift 2 code to Swift 3, and the Reachability doesn't work anymore. Can someone tell me how to check the internet…
LOLXDXPLOL
  • 611
  • 1
  • 6
  • 9
52
votes
2 answers

Swiftlint warning : For Where Violation: `where` clauses are preferred over a single `if` inside a `for`. (for_where)

I am using swift for my application development and using Swift lint. But I am getting a warning regarding the following code: for settingsKeys in searchResults { if settingsKeys.key == settingsObject.key { settingsKeys.value =…
Chelsea Shawra
  • 1,593
  • 4
  • 22
  • 43
52
votes
4 answers

Swift 3: Expression implicitly coerced from 'UIView?' to Any

Someone else must have received this message while (or after) converting an iOS project to Swift 3, yet when I do a Google search, I get no relevant results. Anyway, after converting to Swift 3, I have about 30 warnings that say: Expression…
RyJ
  • 3,995
  • 6
  • 34
  • 54
52
votes
3 answers

Swift3 iOS - How to make UITapGestureRecognizer trigger function

I am trying to add a UITapGesture to a UIButton so it will trigger a function when tapped. I am using Swift 3 and is getting some error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SwiftRunner.ViewController…
iSebbeYT
  • 1,441
  • 2
  • 18
  • 29