Questions tagged [swift-language]

Swift is a programming language designed by Apple for creating iOS and OS X apps. Swift builds upon the foundation of C and Objective-C.

Swift is an application programming language for Apple's iOS and OS X operating systems, introduced by Apple at WWDC 2014. The language uses the LLVM compiler, with Swift code transformed into native code. Swift promises to modernize the developer experience over what Objective-C provides, offering features like:

  • generics
  • type inference
  • namespaces
  • improved safety (some protection from overflow, use-before-initialization, etc.)
  • functional programming elements (map, filter)

... 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 OS X frameworks, like Cocoa and Cocoa Touch, and can sit side-by-side with Objective-C in applications.

Apple provides documentation here:

108 questions
118
votes
5 answers

How can Swift be so much faster than Objective-C in these comparisons?

Apple launched its new programming language Swift at WWDC14. In the presentation, they made some performance comparisons between Objective-C and Python. The following is a picture of one of their slides, of a comparison of those three languages…
Yellow
  • 1,273
  • 2
  • 9
  • 6
70
votes
3 answers

How does garbage collection compare to reference counting?

I starting working through an online course on iOS development in the new language from Apple, Swift. The instructor made a point that raised this question in my mind. He said something to the effect of: There's no need to worry about memory…
Aaron Anodide
  • 5,463
  • 5
  • 28
  • 37
66
votes
1 answer

Swift Protocol Naming Conventions

Coming from a mainly c# background, I'm used to using the term "interface" for describing an object with no implementation that defines behaviour. In c#, the convention is to prepend interface names with "I", as in IEnumerable, etc. Of course, the…
Michael Daw
  • 763
  • 1
  • 5
  • 5
63
votes
10 answers

Why would a program use a closure?

After reading many posts explaining closures here I'm still missing a key concept: Why write a closure? What specific task would a programmer be performing that might be best served by a closure? Examples of closures in Swift are accesses of an…
55
votes
8 answers

Why design a modern language without an exception-handling mechanism?

Many modern languages provide rich exception handling features, but Apple's Swift programming language does not provide an exception handling mechanism. Steeped in exceptions as I am, I'm having trouble wrapping my mind around what this means. Swift…
orome
  • 703
  • 1
  • 5
  • 10
41
votes
2 answers

Do modern languages still use parser generators?

I was researching about the gcc compiler suite on wikipedia here, when this came up: GCC started out using LALR parsers generated with Bison, but gradually switched to hand-written recursive-descent parsers; for C++ in 2004, and for C and…
eatonphil
  • 561
  • 4
  • 8
32
votes
6 answers

Swift functions vs computed properties

Say I have have a class Event as follows: class Event { private var attendees: [Person] = [] // Case 1 //******* // Should I use a func… func countOfAttendees() -> Int { return attendees.count } // …or a var …
Ashley Mills
  • 713
  • 1
  • 5
  • 10
24
votes
3 answers

Struggling with cyclical dependencies in unit tests

I'm trying to practice TDD, by using it to develop a simple like Bit Vector. I happen to be using Swift, but this is a language-agnostic question. My BitVector is a struct that stores a single UInt64, and presents an API over it that lets you treat…
Alexander
  • 3,562
  • 1
  • 19
  • 24
23
votes
2 answers

Why does Swift not require semicolons?

I normally code in either c# or Objective-C and recently took it upon myself to learn Apple's new programming language - Swift. The first thing I noticed is that you don't need to add semicolons to end a line in Swift but if you do-at least from…
Memj
  • 335
  • 3
  • 8
14
votes
1 answer

Why does Swift need witness tables?

I'm trying to read up on implementation details of Swift, and one thing I can't nail down are its "witness tables". It looks like they're a separate vtable pointer used for structs. But why would you need that? Structs are copied by value, so you…
uliwitness
  • 251
  • 2
  • 6
13
votes
3 answers

For what reasons would you use a separate class extension for each delegate in Swift?

I was working through a Ray Wenderlich tutorial and noticed that the author uses class extensions to hold delegate callbacks rather than having them be handled in the class itself i.e.: delegate callbacks inside class extension: extension…
10
votes
3 answers

Is it good practice to wrap a related set of properties into its own struct/class?

Writing a User object in Swift, though my question relates to any strongly typed language. A User can have a bunch of links (FacebookProfile, InstagramProfile, etc). A few questions around this. Is it good practice to wrap links in their own…
Prabhu
  • 323
  • 3
  • 9
9
votes
3 answers

Why does Swift initialise subclass proper fields first?

In language Swift, to initialise an instance, one has to fill in all of the fields of that class, and only then call superconstructor: class Base { var name: String init(name: String) { self.name = name } } class Derived: Base…
Zomagk
  • 261
  • 1
  • 3
7
votes
4 answers

Struct vs class in Swift

One of the stated reasons that structs can be more performant than classes is that no ARC is needed for structs. But suppose we have the following struct in swift: struct Point { var x:Float var y:Float mutating func scale(_ a:Float){ …
gloo
  • 257
  • 2
  • 7
7
votes
4 answers

JSON API or Plain JSON

There is a debate in my company on whether we should use the JSON API specification or stick to plain JSON for developing APIs that will be consumed by mobile apps, mainly iOS and Android. One argument for JSON API is that since everything is…
gkaimakas
  • 193
  • 2
  • 9
1
2 3 4 5 6 7 8