Linked Questions

1 vote
2 answers
3k views

What are the main differences between classes and structs in swift 3? [duplicate]

The only thing I found is that a struct cannot inherit but a class does, and that a struct is passed by value while a class is passed by reference, but I couldn't understand what is that exactly. Can ...
user avatar
0 votes
1 answer
89 views

I am confuse structure vs class in swift language [duplicate]

I am confused about structure vs class. I have seen this example According to this example structure-vs-class According to link may be code output is 15,15,15,20 BUT code output is because ...
Nishant Chandwani's user avatar
929 votes
17 answers
183k views

What is PECS (Producer Extends Consumer Super)?

I came across PECS (short for Producer extends and Consumer super) while reading up on generics. Can someone explain to me how to use PECS to resolve confusion between extends and super?
peakit's user avatar
  • 29.6k
569 votes
17 answers
196k views

Why Choose Struct Over Class?

Playing around with Swift, coming from a Java background, why would you want to choose a Struct instead of a Class? Seems like they are the same thing, with a Struct offering less functionality. Why ...
bluedevil2k's user avatar
  • 9,501
374 votes
32 answers
232k views

What is the difference between `let` and `var` in Swift?

What is the difference between let and var in Apple's Swift language? In my understanding, it is a compiled language but it does not check the type at compile time. It makes me confused. How does the ...
Edward's user avatar
  • 4,987
491 votes
9 answers
202k views

Static vs class functions/variables in Swift classes?

The following code compiles in Swift 1.2: class myClass { static func myMethod1() { } class func myMethod2() { } static var myVar1 = "" } func doSomething() { myClass....
Senseful's user avatar
  • 92.6k
205 votes
12 answers
114k views

Mutable vs immutable objects

I'm trying to get my head around mutable vs immutable objects. Using mutable objects gets a lot of bad press (e.g. returning an array of strings from a method) but I'm having trouble understanding ...
Alex Angas's user avatar
  • 60.2k
141 votes
10 answers
118k views

Is Swift Pass By Value or Pass By Reference

I'm really new to Swift and I just read that classes are passed by reference and arrays/strings etc. are copied. Is the pass by reference the same way as in Objective-C or Java wherein you actually ...
gran_profaci's user avatar
  • 8,513
141 votes
8 answers
73k views

Swift and mutating struct

There is something that I don't entirely understand when it comes to mutating value types in Swift. As the "The Swift Programming Language" iBook states: By default, the properties of a value type ...
Mike Seghers's user avatar
  • 2,075
110 votes
6 answers
70k views

When to use @objc in Swift?

In Swift, I see some methods like: @objc private func doubleTapGestureRecognized(recognizer: UITapGestureRecognizer) I was wondering, when to use @objc? I read some documents, but they are saying ...
Wingzero's user avatar
  • 9,804
90 votes
5 answers
25k views

Swift - what's the difference between metatype .Type and .self?

What's the difference between metatype .Type and .self in Swift? Do .self and .Type return a struct? I understand that .self can be used to check with dynamicType. How do you use .Type?
Boon's user avatar
  • 41.6k
82 votes
4 answers
44k views

Swift stack and heap understanding

I want to understand what is stored in the stack and heap in swift. I have a rough estimation: Everything that you print and the memory address appears not the values, those are stored in the stack, ...
Dániel Nagy's user avatar
51 votes
7 answers
23k views

What are the differences between functions and methods in Swift?

I always thought functions and methods were the same, until I was learning Swift through the "Swift Programming Language" eBook. I found out that I cannot use greet("John", "Tuesday") to call a ...
Ricky's user avatar
  • 10.5k
57 votes
3 answers
16k views

What is a 'non-nominal type' in Swift?

I see this error when trying to extend unorthodox 'types' like (Int, Int), or Any: Non-nominal type 'Any' cannot be extended So what makes a type non-nominal? What's the difference between a non-...
Joseph Mark's user avatar
  • 9,418
40 votes
8 answers
16k views

What is Protocol Oriented Programming in Swift? What added value does it bring?

From Apple's own website: "At the heart of Swift's design are two incredibly powerful ideas: protocol-oriented programming and first class value semantics." Can someone please elaborate what exactly ...
mfaani's user avatar
  • 37.2k

15 30 50 per page