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
3 answers

What is the best practice to parse html in swift?

I'm a Swift newbie. I need for something like Python's BeautifulSoup in Swift iOS project. Precisely, I need to get all href of that ends with ".txt". What are the steps that I should take?
amazingbasil
  • 1,695
  • 3
  • 18
  • 23
61
votes
5 answers

.toInt() removed in Swift 2?

I was working on an application that used a text field and translated it into an integer. Previously my code textField.text.toInt() worked. Now Swift declares this as an error and is telling me to do textField.text!.toInt() and it says there is…
Amit Kalra
  • 4,085
  • 6
  • 28
  • 44
61
votes
6 answers

How to hide title/message frame in a UIAlertController?

When using a UIAlertController, if I want to present a UIActionSheet with an empty title and an empty message, the frame for the expected placement of the title and/or message remains. How do I change this so that I only present an ActionSheet that…
vlin
  • 825
  • 1
  • 6
  • 13
61
votes
5 answers

Return from initializer without initializing all stored properties

I have a simple class like this. public class User { let id: Int let firstName: String let lastName: String let email: String? init(id: Int, firstName: String, lastName: String) { self.id = id self.firstName =…
Isuru
  • 30,617
  • 60
  • 187
  • 303
61
votes
10 answers

How to unwrap an optional value from Any type?

Given an array of [Any] that has a mix of optional and non optional values, e.g: let int:Int? = 1 let str:String? = "foo" let values:[Any] = [int,2,str,"bar"] How can we extract the value of the Optional in the Any type (if there is one) so we can…
mythz
  • 141,670
  • 29
  • 246
  • 390
61
votes
11 answers

How do I detect if an SKSpriteNode has been touched

I am trying to detect if my sprite node has been touched and I have no idea where to start. let Pineapple = SKSpriteNode(imageNamed: "Pineappleimg") Pineapple.userInteractionEnabled = true Pineapple.position = CGPoint(x: CGRectGetMidX(self.frame) -…
James Brennan
  • 635
  • 1
  • 6
  • 7
61
votes
4 answers

IOS - How to create TableView with horizontal scrollable lists

I'm trying to implement a table view with scrollable horizontal items (with unknown number of items) like the illustration below: The UI should behave like so: At the init state the table cell shows a label and some text and the circle item pops…
Shlomi Schwartz
  • 8,693
  • 29
  • 109
  • 186
61
votes
5 answers

Swift .uppercaseString or .lowercaseString property replacement

Since Strings in Swift no longer have the .uppercaseString or .lowercaseString properties available, how would i go about performing that function? If I have for example: var sillyString = "This is a string!" let yellyString =…
Don Alejandro
  • 885
  • 1
  • 7
  • 16
61
votes
8 answers

Error after renaming Xcode 6 project: "linker command failed with exit code 1 (use -v to see invocation)"

So after I create an Xcode 6 project, even if I haven't written any code in it, if I try renaming it by double clicking the bolded program title in the upper left hand corner of the navigator and then confirming that I want the checked items' names…
blue
  • 7,175
  • 16
  • 81
  • 179
61
votes
1 answer

How to create a circular button in Swift?

I want to make a circular thumbs up and thumbs down button. Should I use a ImageView or a Button as the super class? How would I do this in Swift?
User
  • 23,729
  • 38
  • 124
  • 207
61
votes
15 answers

GestureRecognizer not responding to tap

After initialisation of by subclass of UIImageView I have the following line of code: self.userInteractionEnabled = true self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "handleTap:")) I created the necessary associated…
Didia
  • 1,396
  • 1
  • 12
  • 18
61
votes
5 answers

Multiple UILabels inside a self sizing UITableViewCell

In this iOS 8 app I'm creating, I have a tableview and I need them to be self resizing. I implemented it using Auto Layout and it works. Almost. Here's how it looks now. There are 3 labels inside a cell. Main label which has the lorem ipsum text.…
Isuru
  • 30,617
  • 60
  • 187
  • 303
61
votes
16 answers

UIView with shadow, rounded corners and custom drawRect

I have to create a custom UIView that will have round corners, a border, a shadow and its drawRect() method is overridden to provide custom drawing code with which several straight lines are drawn into the view (I need to use a fast, lightweight…
BadmintonCat
  • 9,416
  • 14
  • 78
  • 129
61
votes
3 answers

How to call Type Methods within an instance method

Apple has a nice explanation of Type (Class) Methods, however, their example looks like this: class SomeClass { class func someTypeMethod() { // type method implementation goes here } } SomeClass.typeMethod() I see this exact same…
Chris Marshall
  • 4,910
  • 8
  • 47
  • 72
61
votes
9 answers

Assign xib to the UIView in Swift

in objective c it can be done in init method by -(id)init{ self = [[[NSBundle mainBundle] loadNibNamed:@"ViewBtnWishList" owner:0 options:nil] objectAtIndex:0]; return self; } but when i do this in swift init(frame: CGRect) { self =…
Siu Chung Chan
  • 1,686
  • 1
  • 14
  • 31
1 2 3
99
100