This file contains hidden or 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
for (index, user) in allUsers.enumerated() { | |
print("User: \(user) at index: \(index)") | |
/* | |
User: User(id: 654, name: "Chilly Mango") at index: 0 | |
User: User(id: 7, name: "Mike Biggles") at index: 1 | |
User: User(id: 234, name: "Midum Premium") at index: 2 | |
User: User(id: 99, name: "Jimmy Cho") at index: 3 | |
*/ | |
} |
This file contains hidden or 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 premiumUsers: Set<User> = [User(id: 654, name: "Chilly Mango"), | |
User(id: 234, name: "Midum Premium"), | |
User(id: 7, name: "Mike Biggles"), | |
User(id: 99, name: "Jimmy Cho")] | |
let firstHundredUsers: Set<User> = [User(id: 99, name: "Jimmy Cho"), | |
User(id: 7, name: "Mike Biggles")] | |
let intersection = premiumUsers.intersection(firstHundredUsers) | |
// {{id 99, name "Jimmy Cho"}, {id 7, name "Mike Biggles"}} |
This file contains hidden or 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
var countedAdmins: NSCountedSet = NSCountedSet(array: [user]) | |
countedAdmins.count(for: user) | |
// count is 1 | |
countedAdmins.add(user) | |
countedAdmins.count(for: user) | |
// count is 2 |
This file contains hidden or 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 { | |
let name: String | |
} | |
var users: [Int: User] = [] |
This file contains hidden or 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 user = User(name: "Medium Guest") | |
users[120] = user | |
print("users count: \(users.count)") | |
// users count: 1 | |
users.removeValue(forKey: 100) | |
print("users count: \(users.count)") | |
// users count: 1 | |
users.removeAll() |
This file contains hidden or 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
var users: [String: User] = [:] | |
users["admin"] = user | |
users["guest"] = User(name: "Antonio Guest") | |
if users.isEmpty { | |
print("User dictionary is empty") | |
} else { | |
let user = users["admin"] | |
print("Admin user is: \(String(describing: user))") | |
// "Admin user is: Optional(__lldb_expr_59.User(name: "Medium Guest"))\n" |
This file contains hidden or 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
var users: [String: User] = [:] | |
users["admin"] = user | |
users["guest"] = User(name: "Antonio Guest") | |
for item in users { | |
print("item: \(item)") | |
print("key: \(item.key)") | |
print("value: \(item.value)") | |
/* | |
item: (key: "admin", value: __lldb_expr_67.User(name: "Medium Guest")) |
This file contains hidden or 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 premiumUser = users["premium", default: User(name: "Anonymous")] | |
print("premiumUser: \(premiumUser)") | |
// Default result - "premiumUser: User(name: "Anonymous")\n" |
This file contains hidden or 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
users = ["123": User(name: "Max Guest"), "222": User(name: "Mark Towrn"), "333": User(name: "James Jo")] | |
let grouppedByFirstNameCharacter = Dictionary(grouping: users) { | |
return $0.value.name.first! | |
} | |
print("groupped: \(grouppedByFirstNameCharacter)") | |
// groupped: ["J": [(key: "333", value: __lldb_expr_82.User(name: "James Jo"))], "M": [(key: "222", value: __lldb_expr_82.User(name: "Mark Towrn")), (key: "123", value: __lldb_expr_82.User(name: "Max Guest"))]] |
This file contains hidden or 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
//: A UIKit based Playground for presenting user interface | |
import UIKit | |
import PlaygroundSupport | |
class HexagonView: UIView { | |
private let borderLineWidth: CGFloat = 4 | |
var borderLineColor: UIColor = .clear | |