This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Fruits: String { | |
case apple | |
case banana | |
case strawberry | |
case kiwi | |
static var allCases: [Fruits] { | |
return [.apple, .banana, .strawberry, .kiwi] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol CaseIterable { | |
/// A type that can represent a collection of all values of this type. | |
associatedtype AllCases : Collection where Self.AllCases.Element == Self | |
/// A collection of all values of this type. | |
public static var allCases: Self.AllCases { get } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Fruits: String, CaseIterable { | |
case apple | |
case banana | |
case strawberry | |
case kiwi | |
static func printFruits() { | |
for fruit in Fruits.allCases { | |
print(fruit) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct User: Equatable { | |
let userId: String | |
let email: String | |
let lovesFruits: Bool | |
static func == (lhs: User, rhs: User) -> Bool { | |
return lhs.userId == rhs.userId && | |
lhs.email == rhs.email && | |
lhs.lovesFruits == rhs.lovesFruits | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct User: Equatable { | |
let userId: String | |
let email: String | |
let lovesFruits: Bool | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct UserInfo { | |
let userArray1 = [User(userId: "1", email: "something@gmail.com", lovesFruits: true), | |
User(userId: "2", email: "something@gmail.com", lovesFruits: true)] | |
let userArray2 = [User(userId: "1", email: "something@gmail.com", lovesFruits: false), | |
User(userId: "2", email: "something@gmail.com", lovesFruits: false)] | |
func areArraysEqual() -> Bool { | |
return userArray1 == userArray2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array: Equatable where Element: Equatable { | |
static func ==(lhs: Array<Element>, rhs: Array<Element>) -> Bool { | |
let count = lhs.count | |
if count != rhs.count { return false } | |
for x in 0..<count { | |
if lhs[x] != rhs[x] { return false } | |
} | |
return true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if os(iOS) || os(tvOS) || os(watchOS) || os(macOS) | |
return Int(arc4random()) | |
#else | |
return random() // or Int(rand()) | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let randomIntFrom0To10 = Int.random(in: 0 ..< 10) | |
let randomFloat = Float.random(in: 0 ..< 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class CssParser { | |
/// Parses the CSS file string into an array of CSS styles. | |
/// | |
/// - Parameter fileContent: CSS file content. | |
/// - Returns: Array of CSS styles. | |
static func parse(fileContent: String) -> [CssStyle] { | |
var styles = [CssStyle]() | |
var pendingStyleName = "" | |
var pendingStyleProperties = [String: String]() |
OlderNewer