Explore tweets tagged as #100DaysOfPROSwift
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
2 months
Day 31 of #100DaysOfPROSwift. πŸ” Don’t use UUID().uuidString to generate identifiers unless you truly need a string. Instead of this:. 🚫 let id = UUID().uuidString.😬 You lose type safety and introduce fragile string-based comparisons. Do this:. βœ… let id = UUID().Swift’s UUID
Tweet media one
0
0
0
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
2 months
Day 26 of #100DaysOfPROSwift. πŸ‘οΈ Observe property changes with KVO β€” clean, automatic, and no delegates needed. Instead of this:. 🚫 Manually updating state or using custom delegate.😬 More boilerplate, easy to forget updates. Do this:. βœ… Use @objc dynamic + observe to track
Tweet media one
0
0
0
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
2 months
Day 34 of #100DaysOfPROSwift. πŸ” Use enum with associated values to model complex state β€” cleanly and safely. Instead of this:. var isLoading = false .var errorMessage: String? .var data: Data? . Scattered state, easy to mismanage and misrepresent. Do this:. enum LoadState {
Tweet media one
0
0
0
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
2 months
Day 37 of #100DaysOfPROSwift. πŸ” Use zip(_:_:) to iterate over two collections in parallel β€” cleanly and safely. Instead of this:. for i in 0. <min(names.count, ages.count) { . print("\(names[i]) is \(ages[i]) years old") .} . 😬 Manual index math is error-prone and ugly. Do
Tweet media one
0
0
0
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
2 months
Day 35 of #100DaysOfPROSwift. πŸ” Use typealias to simplify complex types and improve readability. Instead of this:. let handler: (Result<Data, NetworkError>) -> Void . Hard to read, especially when reused in multiple places. Do this:. typealias DataResultHandler = (Result<Data,
Tweet media one
0
0
0
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
2 months
Day 32 of #100DaysOfPROSwift. πŸ” Prefer using .contains(_:) over manual loops to check for values in collections. Instead of this: .for item in array { . if item == target { . found = true . } .} .😬 Verbose and error-prone β€” too much boilerplate. Do this:.βœ…
Tweet media one
0
0
0
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
2 months
Day 28 of #100DaysOfPROSwift. πŸ” Use swapAt(_:_:) to swap elements in an array β€” safely and concisely. Instead of this:. 🚫 Manual temp variables.😬 Verbose and error-prone. Do this:. βœ… array.swapAt(i, j). Swift gives you a built-in method to swap elements directly by index.
Tweet media one
0
0
2
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
1 month
Day 39 of #100DaysOfPROSwift. πŸ” Use @autoclosure to delay evaluation of expressions β€” without changing your function call syntax. Instead of this:. func log(_ message: () -> String) { . if debugMode { print(message()) } .} . log({ "Heavy log: \(expensiveCalculation())" })
Tweet media one
0
0
0
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
2 months
Day 38 of #100DaysOfPROSwift. πŸ” Use trailing closure syntax to keep function calls clean and expressive. Instead of this:. let result = { name in . name.uppercased() .}). Cluttered with unnecessary parentheses and syntax. Do this:. let result =
Tweet media one
0
0
0
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
2 months
Day 27 of #100DaysOfPROSwift. πŸ›‘ Safely access array elements with a custom subscript. Developers often do this:. 🚫 let item = array[3].😬 Risky β€” crashes if the index is out of bounds. Do this instead:. extension Array {. subscript(safe index: Int) -> Element? {
Tweet media one
0
0
0
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
1 month
Day 40 of #100DaysOfPROSwift. Use guard case let to elegantly unwrap and pattern-match tuples. Instead of this:. if let status = response.status,. let data = . status == .success {. handle(data).} else {. return.}. 😬 Nested if chains get messy
Tweet media one
0
0
0
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
2 months
Day 29 of #100DaysOfPROSwift. πŸ” Use Swift’s KeyPath to dynamically access or sort properties β€” without hardcoding field names. Instead of this:.🚫 users.sorted { $0.name < $1.name }.😬 Repetitive and fragile in generic contexts. Do this:.βœ… users.sorted(by: \.name). KeyPaths
Tweet media one
0
0
0
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
2 months
Day 36 of #100DaysOfPROSwift. πŸ” Use Dictionary(grouping:by:) to organize items by category β€” in one line. Instead of this:. var grouped: [String: [User]] = [:] .for user in users { . grouped[user.role, default: []].append(user) .} .😬 Verbose and easy to mess up. Do this:
Tweet media one
0
0
0
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
2 months
Day 33 of #100DaysOfPROSwift. πŸ” Use CaseIterable to access all cases of an enum β€” no manual lists needed. Instead of this:. let allOptions = [.optionA, .optionB, .optionC]. Manual case lists break easily if the enum changes. Do this:. enum Option: CaseIterable {. case a, b, c
Tweet media one
0
0
0
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
2 months
Day 30 of #100DaysOfPROSwift. πŸ” Use first(where:) to find the first element in a collection that matches a condition β€” efficiently and elegantly. Instead of this:. 🚫 Manual loops to check each element.😬 Risk of out-of-bounds errors or verbose code. Do this:. βœ…
Tweet media one
0
0
0
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
1 month
Day 44 of #100DaysOfPROSwift. Use String(repeating:count:) to quickly generate patterns πŸ”. Instead of this:.😬.var dashes = "".for _ in 0. <10 {. dashes += "-".}. Do this:. let dashes = String(repeating: "-", count: 10). βœ… Shorter, clearer, and more efficient. Swift’s.
0
0
2
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
1 month
Day 43 of #100DaysOfPROSwift. Use Swift’s new native Regex for powerful pattern matching 🧠.Instead of this: . let range = text.range(of: "[a-z]+", options: .regularExpression). Do this:. if let match = try? /[a-z]+/.firstMatch(in: text) {. // use match.}. βœ… Native syntax,.
0
0
4
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
1 month
Day 41 of #100DaysOfPROSwift. Use switch with tuples to match multiple conditions at once. Instead of this:. if user.isLoggedIn && user.hasPremium {. showDashboard().} else if user.isLoggedIn {. showUpgradeScreen().} else {. showLogin().}. 😬 Too many chained if conditions.
0
0
2
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
1 month
Day 42 of #100DaysOfPROSwift. Build strings the Swifty way with interpolation 🧩. Instead of this: 😬. let message = "Hello, " + name + "! You have " + String(count) + " new messages.". Do this:. let message = "Hello, \(name)! You have \(count) new messages.". βœ… Safer, cleaner,.
0
0
0
@ruiaureliano
πŸ‘¨πŸ»β€πŸ’» Rui Aureliano
1 month
Day 45 of #100DaysOfPROSwift. Super-charge your data processing with concurrent mapping via TaskGroup ⚑️. Instead of this:. 😬 Traditional loop, one network call at a time. var images: [UIImage] = [].for url in urls {. if let img = try? await fetchImage(url) {.
0
0
4