Skip to content

Commit 05d33b5

Browse files
committedOct 20, 2018
swift-learnings
0 parents  commit 05d33b5

File tree

356 files changed

+8736
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

356 files changed

+8736
-0
lines changed
 

‎.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Xcode
2+
#
3+
build/
4+
*.pbxuser
5+
!default.pbxuser
6+
*.mode1v3
7+
!default.mode1v3
8+
*.mode2v3
9+
!default.mode2v3
10+
*.perspectivev3
11+
!default.perspectivev3
12+
xcuserdata
13+
*.xccheckout
14+
*.moved-aside
15+
DerivedData
16+
*.hmap
17+
*.ipa
18+
*.xcuserstate
19+
20+
# CocoaPods
21+
#
22+
# We recommend against adding the Pods directory to your .gitignore. However
23+
# you should judge for yourself, the pros and cons are mentioned at:
24+
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
25+
#
26+
# Pods/
27+
28+
# Carthage
29+
#
30+
# Add this line if you want to avoid checking in source code from Carthage dependencies.
31+
# Carthage/Checkouts
32+
33+
Carthage/Build
34+
35+
# Ignore those pesky DS_Store files!
36+
.DS_Store
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//: [Previous](@previous)
2+
//: ### Associated Values
3+
//: Associated values are defined alongside enum cases. Associated values are not required; some enum cases may have an associated value while others do not. In the example below, `LibraryFee` has three cases with associated values and a case without an associated value.
4+
//:
5+
enum LibraryFee {
6+
case overdueBook(Int)
7+
case lostBook(Double)
8+
case lostLibraryCard(Int)
9+
case annualDues
10+
}
11+
12+
let fee = LibraryFee.overdueBook(4)
13+
//: It can be very helpful to name associated values so that their intent is easily understood.
14+
//:
15+
enum DescriptiveLibraryFee {
16+
case overdueBook(days: Int)
17+
case lostBook(price: Double)
18+
case lostLibraryCard(timesLost: Int)
19+
case annualDues
20+
}
21+
22+
let weekLateFee = DescriptiveLibraryFee.overdueBook(days: 7)
23+
//: Associated values are actually tuples. Therefore, an associated value can contain mutliple values. Recall from [Apple's documentation](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5-ID329) that tuples are multiple values grouped into a single compound value.
24+
//:
25+
import UIKit
26+
27+
enum ImageFilter {
28+
case sepia
29+
case verticalGradient(from: UIColor, to: UIColor)
30+
case horizontalGradient(from: UIColor, to: UIColor)
31+
case sketch(penThickness: Double?)
32+
}
33+
34+
let fadeToBlack = ImageFilter.horizontalGradient(from: .gray, to: .black)
35+
//: - Callout(Watch Out!):
36+
//: If all enum cases have an associated value of the same type, and it is static, then you might consider using a raw value instead.
37+
//:
38+
// the associated values for `AudioRateAssociated` should be raw values
39+
enum AudioRateAssociated {
40+
case slow(value: Int)
41+
case normal(value: Int)
42+
case fast(value: Int)
43+
case custom(value: Int)
44+
}
45+
46+
enum AudioRateRaw: Int {
47+
case slow, normal, fast, custom
48+
}
49+
//: [Next](@next)

0 commit comments

Comments
 (0)
Please sign in to comment.