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.

18403 questions
409
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
359
votes
6 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
  • 17,340
  • 8
  • 34
  • 78
356
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
  • 10,343
  • 4
  • 37
  • 68
252
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
  • 118,448
  • 25
  • 255
  • 308
247
votes
10 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,718
  • 3
  • 18
  • 32
242
votes
6 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
  • 33,381
  • 26
  • 125
  • 160
239
votes
2 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
  • 2,651
  • 3
  • 9
  • 15
198
votes
11 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,356
  • 8
  • 29
  • 50
184
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
  • 5,836
  • 3
  • 16
  • 19
169
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 codes here let listUrlString = …
SwiftDeveloper
  • 6,588
  • 11
  • 50
  • 75
166
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 call is unused public override init(){ super.init() } public init(annotations: [MKAnnotation]){ super.init() …
Aryan Kashyap
  • 1,713
  • 2
  • 7
  • 6
165
votes
2 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,014
  • 15
  • 77
  • 136
151
votes
6 answers

how to open an URL in Swift3

openURL has been deprecated in Swift3. Can anyone provide some examples of how the replacement openURL:options:completionHandler: works when trying to open an url?
Shane O'Seasnain
  • 3,024
  • 4
  • 18
  • 30
148
votes
10 answers

What is a good example to differentiate between fileprivate and private in Swift3

This article has been helpful in understanding the new access specifiers in Swift 3. It also gives some examples of different usages of fileprivate and private. My question is - isn't using fileprivate on a function that is going to be used only…
Nikita P
  • 4,066
  • 5
  • 27
  • 53
141
votes
6 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
  • 4,929
  • 9
  • 38
  • 91
1
2 3
99 100