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
420
votes
15 answers

How to create dispatch queue in Swift 3

In Swift 2, I was able to create queue with the following code: let concurrentQueue = dispatch_queue_create("com.swift3.imageQueue", DISPATCH_QUEUE_CONCURRENT) But this doesn't compile in Swift 3. What is the preferred way to write this in Swift…
user4790024
406
votes
8 answers

How to program a delay in Swift 3

In earlier versions of Swift, one could create a delay with the following code: let time = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), 4 * Int64(NSEC_PER_SEC)) dispatch_after(time, dispatch_get_main_queue()) { //put your code which should…
owlswipe
  • 19,159
  • 9
  • 37
  • 82
391
votes
5 answers

What is the 'open' keyword in Swift?

The ObjectiveC.swift file from the standard library contains the following few lines of code around line 228: extension NSObject : Equatable, Hashable { /// ... open var hashValue: Int { return hash } } What does open var mean in this…
Clashsoft
  • 11,553
  • 5
  • 40
  • 79
311
votes
7 answers

How to provide a localized description with an Error type in Swift?

I am defining a custom error type with Swift 3 syntax and I want to provide a user-friendly description of the error which is returned by the localizedDescription property of the Error object. How can I do it? public enum MyError: Error { case…
Evgenii
  • 36,389
  • 27
  • 134
  • 170
281
votes
3 answers

Command Line Tool - Error - xcrun: error: unable to find utility "xcodebuild", not a developer tool or in PATH

I am getting this error while building the SwiftJSON framework to the Some Xcode project through Carthage Dependency Manager. Sivaramaiahs-Mac-mini:GZipDemoApp vsoftMacmini5$ carthage update --platform iOS *** Fetching GzipSwift *** Fetching…
Sivaram Yadav
  • 3,141
  • 3
  • 13
  • 15
263
votes
6 answers

How do I dispatch_sync, dispatch_async, dispatch_after, etc in Swift 3, Swift 4, and beyond?

I have lots of code in Swift 2.x (or even 1.x) projects that looks like this: // Move to a background thread to do some long running work dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { let image =…
rickster
  • 124,678
  • 26
  • 272
  • 326
254
votes
11 answers

CGRectMake, CGPointMake, CGSizeMake, CGRectZero, CGPointZero is unavailable in Swift

After converting code to latest swift 3.0 I am shown this error. Also tell me solution for CGSize = CGSizeMake(0,0) static var frameAtStartOfPan: CGRect = CGRectZero static var startPointOfPan: CGPoint = CGPointZero Which is also unavailable.
niravdesai21
  • 4,818
  • 3
  • 22
  • 33
221
votes
14 answers

Figure out size of UILabel based on String in Swift

I am trying to calculate the height of a UILabel based on different String lengths. func calculateContentHeight() -> CGFloat{ var maxLabelSize: CGSize = CGSizeMake(frame.size.width - 48, CGFloat(9999)) var contentNSString = contentText as…
Cody Weaver
  • 4,756
  • 11
  • 33
  • 51
199
votes
1 answer

try, try! & try? what’s the difference, and when to use each?

In Swift 2.0, Apple introduced a new way to handle errors (do-try-catch). And few days ago in Beta 6 an even newer keyword was introduced (try?). Also, knew that I can use try!. What's the difference between the 3 keywords, and when to use each?
Abdurrahman
  • 6,306
  • 3
  • 19
  • 20
188
votes
3 answers

Closure use of non-escaping parameter may allow it to escape

I have a protocol: enum DataFetchResult { case success(data: Data) case failure } protocol DataServiceType { func fetchData(location: String, completion: (DataFetchResult) -> (Void)) func cachedData(location: String) ->…
Lukasz
  • 19,816
  • 17
  • 83
  • 139
186
votes
1 answer

Swift 3.0 Result of call is unused

I am writing in swift 3.0 I have this code which gives me the warning result of the call is unused public override init(){ super.init() } public init(annotations: [MKAnnotation]){ super.init() addAnnotations(annotations: …
Aryan Kashyap
  • 1,913
  • 2
  • 10
  • 6
168
votes
14 answers

Swift 3 URLSession.shared() Ambiguous reference to member 'dataTask(with:completionHandler:) error (bug)

Hello I have working json parsing code for swift2.2 but when i use it for Swift 3.0 gives me that error ViewController.swift:132:31: Ambiguous reference to member 'dataTask(with:completionHandler:)' My code is here: let listUrlString = …
SwiftDeveloper
  • 7,244
  • 14
  • 56
  • 85
167
votes
7 answers

How to pass data using NotificationCenter in swift 3.0 and NSNotificationCenter in swift 2.0?

I'm implementing socket.io in my swift ios app. Currently on several panels I'm listening to the server and wait for incoming messages. I'm doing so by calling the getChatMessage function in each panel: func getChatMessage(){ …
user3766930
  • 5,629
  • 10
  • 51
  • 104
164
votes
4 answers

Difference between DispatchQueue.main.async and DispatchQueue.main.sync

I have been using DispatchQueue.main.async for a long time to perform UI related operations.

 Swift provides both DispatchQueue.main.async and DispatchQueue.main.sync, and both are performed on the main queue.

 Can anyone tell me the difference…
Aman.Samghani
  • 2,151
  • 3
  • 12
  • 27
163
votes
5 answers

How to open an URL in Swift?

openURL has been deprecated in Swift 3. Can anyone provide some examples of how the replacement openURL:options:completionHandler: works when trying to open an url?
Shane O'Seasnain
  • 3,534
  • 5
  • 24
  • 31
1
2 3
99 100