Questions tagged [swift]

Swift is a general-purpose programming language developed by Apple Inc first released in 2014 for its platforms and Linux. Swift is open-source. Use the tag only for questions about language features or requiring code in Swift. Use the tags [ios], [ipados], [macos], [watch-os], [tvos], [swiftui], [cocoa-touch], and [cocoa] for (language-agnostic) questions about the platforms or frameworks.

Swift is an application and systems programming language introduced by Apple on June 2, 2014, and distributed as open source. Swift interoperates with Objective-C and Cocoa/Cocoa Touch APIs for Apple's iOS, macOS, watchOS, tvOS, and iPadOS operating systems.


Current stable version is Swift 5.8.0 released on November 1, 2022 (download).

  • Swift is open-source, available on GitHub
  • Swift >=2.2 includes support for Swift on a Linux platform.
  • Swift >=5.3 includes support for Swift on a Windows platform.

Please use the tag for questions relating to OpenStack's object/blob store, and the tag for questions relating to the parallel scripting language.

Swift promises to modernize the developer experience over what Objective-C provides, offering features like:

  • Generics
  • Type safety
  • Type inference
  • Namespaces
  • Improved safety (some protection from overflow, use-before-initialization, etc.)
  • Higher-order functions (map, filter, sort)

among others.

The Swift syntax retains some elements from Objective-C while providing an extensive new vocabulary for its new features.

The language can use existing iOS and macOS frameworks, like Cocoa and Cocoa Touch, and can sit side-by-side with Objective-C in applications. Swift applications compile into standard binaries and can be run on OS X 10.9, iOS 7 (or higher), tvOS and watchOS.


Timeline

  • Swift 2.0 was introduced by Apple at WWDC on 8th June 2015. They added new features like the "Error handling model" with try, throw and catch.

  • Swift 2.2 was introduced with Xcode 7.3 on 21st March 2016. (release notes)

  • Swift 3.0 was introduced by Apple at WWDC on 13th June 2016, with the news that Swift will come to non-Apple platforms (Windows, Linux, Android, Raspberry Pi, and so on). (release notes)

  • Swift 3.1 was introduced with Xcode 8.3 on 27th March 2017. (release notes)

  • Swift 4.0 was introduced by Apple at WWDC on 5th June 2017. (release notes)

  • Swift 4.1 was introduced with Xcode 9.3 on 29th March 2018. (release notes)

  • Swift 4.2 was introduced by Apple at WWDC on 4th June 2018. (release notes)

  • Swift 5.0 was introduced with Xcode 10.2 on 25th March 2019. (release notes)

  • Swift 5.1 was introduced with Xcode 11 on 20th September 2019. (release notes)

  • Swift 5.2 was introduced with Xcode 11.4 on 24th March 2020. (release notes)

  • Swift 5.3 was introduced with Xcode 12 on 16th September 2020. (release notes)

  • Swift 5.4 was introduced with Xcode 12.5 on 26th April 2021. (release notes)

  • Swift 5.5 was introduced with Xcode 13 on 20th September 2021. (release notes)

  • Swift 5.6 was introduced with Xcode 13.3 on 14th March 2022. (release notes)

  • Swift 5.7 was introduced with Xcode 14 on 12th September 2022. (release notes)

  • Swift 5.8 was introduced with Xcode 14.3 on 30th March 2023. (release notes)


Resources

References

Books

Other resources


Related Tags

329921 questions
63
votes
5 answers

How to return value from Alamofire

I am making url calls thru an API that I created using swift as follows: class API { let apiEndPoint = "endpoint" let apiUrl:String! let consumerKey:String! let consumerSecret:String! var returnData = [:] init(){ self.apiUrl =…
u54r
  • 1,767
  • 2
  • 15
  • 26
63
votes
15 answers

How do you update a CoreData entry that has already been saved in Swift?

I'm not sure what I'm doing wrong here, but when I save the first time into coredata, it works just fine. When I try to overwrite that, it doesn't. func testStuff() { var token = loadLoginData() println("Token \(token)") …
slooker
  • 1,060
  • 2
  • 9
  • 16
63
votes
4 answers

Swift frameworks do not work with build configurations named other than 'Debug' or 'Release': No such module

Whenever I try to use a build configuration named other than 'Debug' or 'Release', Xcode suddenly cannot find my Swift frameworks. The configurations are the exact same other than their name (in fact, the new configuration was duplicated from the…
DJ Tarazona
  • 1,769
  • 14
  • 18
63
votes
8 answers

Swift UIAlertController -> ActionSheet iPad iOS8 Crashes

currently i'm running into big trouble with my ActionSheet. On iPhone it works great, but on iPad it only crashes I create a new project with only one button import UIKit extension ViewController : UIActionSheetDelegate { func…
Fabian Boulegue
  • 6,476
  • 14
  • 47
  • 72
63
votes
10 answers

Xcode 6 isn't autocompleting in Swift

I am trying to import various libraries which I can't remember their exact name. Unfortunately Xcode 6 (using swift) isn't auto completing them like was done in Xcode 5 using objective-c. For instance: ALAssetsLibrary MPMediaPlayer etc. I am…
Avba
  • 14,822
  • 20
  • 92
  • 192
63
votes
12 answers

Change button background color using swift language

I am new to the swift language. Can someone tell me how to change the background color of a button using the swift language?
kalim sayyad
  • 1,076
  • 1
  • 9
  • 13
62
votes
6 answers

How to remove Scene Delegate from iOS Application?

I have created the iOS Project in Xcode 11.1. I need to remove scene delegate from the application.
user12403575
62
votes
4 answers

How do you check if SwiftUI is in preview mode?

Is there a way to check if a SwiftUI app is in preview mode? For example, you can check if your app is in development or production mode using #if DEBUG. Can you do something similar to check if you're previewing or not?
Ken Mueller
  • 3,659
  • 3
  • 21
  • 33
62
votes
8 answers

Modifications to the > layout engine must not be performed from a background thread after it has been accessed from the main thread

I just downloaded iOS 13 for my iPhone and the new Xcode. I wanted to test my app for iOS 13, but when I try to run my app it will give me a error after a few seconds. Error: Terminating app due to uncaught exception …
Dani010
  • 627
  • 1
  • 5
  • 7
62
votes
4 answers

Swift 5.0: 'withUnsafeBytes' is deprecated: use `withUnsafeBytes(...)

I previously used this code in Swift 4.2 to generate an id: public static func generateId() throws -> UInt32 { let data: Data = try random(bytes: 4) let value: UInt32 = data.withUnsafeBytes { $0.pointee } // deprecated warning! return…
Baran
  • 2,710
  • 1
  • 23
  • 23
62
votes
12 answers

UITabBar items jumping on back navigation on iOS 12.1

I have an iOS app with UITabBarController on a master screen, navigating to a detail screen hiding the UITabBarController with setting hidesBottomBarWhenPushed = true. When going back to the master screen the UITabBarController does a strange "jump"…
Igor Kulman
  • 16,211
  • 10
  • 57
  • 118
62
votes
5 answers

Encode/Decode Array of Types conforming to protocol with JSONEncoder

I'm trying to find the best way to Encode/Decode an array of structs conforming to a swift protocol using the new JSONDecoder/Encoder in Swift 4. I made up a little example to illustrate the problem: First we have a protocol Tag and some Types that…
goesta
  • 649
  • 1
  • 6
  • 13
62
votes
8 answers

Xcode 8 Objective-C category warning

I'm using Xcode 8 and Swift 3.0. What does this error message mean? ld: warning: Some object files have incompatible Objective-C category definitions. Some category metadata may be lost. All files containing Objective-C categories should be built…
jherg
  • 1,696
  • 2
  • 13
  • 15
62
votes
21 answers

How to open Google Maps to show route using Swift

I read around the Internet but couldn't find a legit answer. I need to open Google Maps when the user clicks a button to show directions. Start and destination must be automatically filled. How can I achieve this in Swift? If anyone has a solution,…
sumesh
  • 2,179
  • 2
  • 21
  • 37
62
votes
4 answers

Change 'Return' button function to 'Done' in swift in UITextView

I would like to get rid of the "return" function of the keyboard while the user is typing, so there are no new lines, so instead I would like the 'return' key to function as 'Done' so it would hide the keyboard. I am using a UITextView, that is…
Bruno Recillas
  • 951
  • 1
  • 9
  • 18