Linked Questions

22 votes
3 answers
20k views

How do I make a private function in Swift? Here is an example: import UIKit class AnotherClass { var someVar = 1 let someConst = 2 func somePrivateFunc() -> Bool { return ...
SirRupertIII's user avatar
  • 12.6k
11 votes
1 answer
8k views

It seems that there is not a private, or for that matter public, keyword in swift language. So it is possible at all to have a private property? On a side note, Swift is very much similar to ...
Sean Dong's user avatar
  • 625
4 votes
0 answers
266 views

I have a very simple Swift question for which there is probably an obvious answer, but I can't seem to find it. How are methods and variables within a class declared as: Private? Protected (i.e. ...
Chase Miller's user avatar
398 votes
5 answers
152k views

The ObjectiveC.swift file from the standard library contains the following few lines of code around line 228: extension NSObject : Equatable, Hashable { /// ... open var hashValue: Int { ...
Clashsoft's user avatar
  • 11.9k
113 votes
11 answers
36k views

In the Introduction to Swift WWDC session, a read-only property description is demonstrated: class Vehicle { var numberOfWheels = 0 var description: String { return "\(...
Stuart's user avatar
  • 37.1k
48 votes
5 answers
39k views

I want to create a class that inherits from another class, which is in a different file. For example: Class1.swift class Class1 { protected var //Do Stuff } Class2.swift class Class2:Class1 {...
iProgram's user avatar
  • 6,637
30 votes
4 answers
34k views

So I'm working on an iOS project in Swift, and I wanted to create a Static library with some useful stuff in it. My problem is when I try to build my lib in Xcode (version 6.3) I have a "Build Failed"...
Que20's user avatar
  • 1,569
19 votes
6 answers
21k views

I read the Apple's reference about access modifiers in Swift 3. I read also about the same on stackoverflow but I didn't get an answer as the person who asked. As I understood correctly, there are ...
devshok's user avatar
  • 836
6 votes
2 answers
3k views

There are a cases where I might want to model data where it makes sense for a value to be restricted to a given range. For example, if I want to represent a "mammal", I might want to restrict a legs ...
j b's user avatar
  • 5,326
6 votes
3 answers
5k views

I've read the entire Swift book, and watched all the WWDC videos (all of which I heartily recommend). One thing I'm worried about is data encapsulation. Consider the following (entirely contrived) ...
zpasternack's user avatar
  • 17.9k
8 votes
2 answers
4k views

Swift offers 5 access modifiers: open, public, internal, fileprivate and private. Of what I know about these specifiers, (mainly from link & link_2) open means classes and class members can be ...
iCode's user avatar
  • 113
9 votes
1 answer
3k views

I know there are a few questions regarding with this already. And I know swift can only customise property setter and getter for computed properties. But I think this is the worst part of Swift. ...
Bagusflyer's user avatar
3 votes
1 answer
980 views

I am using the swift package manager. I have a module ModuleA which exports two types: ModuleA and Test. I have a module ModuleB which defines a single type: Test. In ModuleB, how can I refer to the ...
deaton.dg's user avatar
  • 1,370
2 votes
2 answers
387 views

I have a question regarding object oriented design principles and Swift. I am pretty familiar with Java and I am currently taking a udacity course to get a first hands on in Swift. In the Java ...
Christian's user avatar
  • 1,586
0 votes
1 answer
869 views

I have gone through the Apple provided document i.e https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/AccessControl.html Here, it explains: ...
am449's user avatar
  • 168

15 30 50 per page