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
61
votes
1 answer

What does an exclamation mark in a property in Swift language?

There are three way to declare a property in Swift: var optStr: String? var normStr: String = "normStr" var exactStr: String! The first one is property with an optional type, a type that can contain either nil or the String in our case. The…
Artem Abramov
  • 4,701
  • 4
  • 27
  • 38
61
votes
3 answers

Swift numerics and CGFloat (CGPoint, CGRect, etc.)

I'm finding Swift numerics particularly clumsy when, as so often happens in real life, I have to communicate with Cocoa Touch with regard to CGRect and CGPoint (e.g., because we're talking about something's frame or bounds). CGFloat vs.…
matt
  • 515,959
  • 87
  • 875
  • 1,141
61
votes
17 answers

UITableView in Swift

I'm struggling to figure out what's wrong with this code snippet. This is currently working in Objective-C, but in Swift this just crashes on the first line of the method. It shows an error message in console log: Bad_Instruction. func…
DBoyer
  • 3,062
  • 4
  • 22
  • 32
61
votes
8 answers

How to bring NSWindow to front and to the current Space?

I'm using this code to bring up my window: [self.window makeKeyAndOrderFront:self]; [self.window setOrderedIndex:0]; But often it will be beneath other windows or displayed in other Space desktop that I last open it in. How do I make it always…
Teo Choong Ping
  • 12,512
  • 18
  • 64
  • 91
60
votes
5 answers

Cannot convert value of type 'Published.Publisher' to expected argument type 'Binding'

When trying to compile the following code: class LoginViewModel: ObservableObject, Identifiable { @Published var mailAdress: String = "" @Published var password: String = "" @Published var showRegister = false @Published var…
Jan Koch
  • 603
  • 1
  • 5
  • 4
60
votes
6 answers

How to set addObserver in SwiftUI?

How do I add NotificationCenter.default.addObserve in SwiftUI? When I tried adding observer I get below error Argument of '#selector' refers to instance method 'VPNDidChangeStatus' that is not exposed to Objective-C But when I add @objc in front…
O-mkar
  • 5,430
  • 8
  • 37
  • 61
60
votes
3 answers

What is Geometry Reader in SwiftUI?

I am learning SwiftUI. And I come across to "GeometryReader". And I want to know why and when to use it?
Md Shafiul Islam
  • 1,579
  • 1
  • 13
  • 19
60
votes
10 answers

Prevent dismissal of modal view controller in SwiftUI

At WWDC 2019, Apple announced a new "card-style" look for modal presentations, which brought along with it built-in gestures for dismissing modal view controllers by swiping down on the card. They also introduced the new isModalInPresentation…
Jumhyn
  • 6,687
  • 9
  • 48
  • 76
60
votes
1 answer

Difference between DispatchSourceTimer, Timer and asyncAfter?

I am struggling to understand the key differences between DispatchSourceTimer, Timer and asyncAfter (in my case for scheduling a task that needs to be ran every X seconds, although understanding the differences in timers can be useful to) (Or is…
J. Doe
  • 12,159
  • 9
  • 60
  • 114
60
votes
7 answers

How to set the tab bar badge with swift?

How to set the tab bar badge with swift ? for example when I get new message showing number 1 on the message icon ! Do I have to use the UITabBarItem.swift and write the code in it ! I'm not really sure how I can do it Thank you !
Faris
  • 1,206
  • 1
  • 12
  • 18
60
votes
2 answers

Why is 'throws' not type safe in Swift?

The biggest misunderstanding for me in Swift is the throws keyword. Consider the following piece of code: func myUsefulFunction() throws We cannot really understand what kind of error it will throw. The only thing we know is that it might throw…
Noobass
  • 1,974
  • 24
  • 26
60
votes
12 answers

How to programmatically set action for barButtonItem in swift 3?

Here is what I used previously, var barButtonItem = UIBarButtonItem(image: backImgs, style: UIBarButtonItemStyle.plain, target: self, action: Selector("menuButtonTapped:")) But there is some syntax changes for Swift 3.
Bhanupriya
  • 1,202
  • 1
  • 9
  • 20
60
votes
9 answers

Convert Apple Emoji (String) to UIImage

I need all Apple Emojis. I can get all the emojis and put them into a String by copying them from the site getemoji but in my app i need the emojis in the right order as images. Is there a nice way to convert the emojis I copy into a String to a…
DanielZanchi
  • 2,708
  • 1
  • 25
  • 37
60
votes
5 answers

Subview on top of window view in Swift

I want to place a UIView over the entire screen (including the navigation bar). This view will be black with 0.3 opacity. I want to do this to darken out the screen content and push a view on top of this. I am using this…
Kex
  • 8,023
  • 9
  • 56
  • 129
60
votes
10 answers

In iOS, how do I create a button that is always on top of all other view controllers?

No matter if modals are presented or the user performs any type of segue. Is there a way to keep the button "always on top" (not the top of the screen) throughout the entire app? Is there any way to make this button draggable and snappable to the…
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
1 2 3
99
100