HEhuda elhadyinhudaios.hashnode.dev·Apr 15 · 3 min readThe Function That Never ReturnsSo what is the problem? func divide(_ a: Int, by b: Int) -> Int { if b == 0 { fatalError("b input must not be zero") } return a / b } func greeting(_ name: String) -> String { 00
HEhuda elhadyinhudaios.hashnode.dev·Apr 3 · 3 min readMutable Dictionary Keys in Swift: A Bug Waiting to HappenLet's imagine we have cartItems dictionary that has product as key and number of items as value struct Product: Hashable { var id: Int var name: String } var cartItems = [Product: Int]() var00
HEhuda elhadyinhudaios.hashnode.dev·Mar 23 · 2 min readSwift Performance: Stop Creating Intermediate Arrays with .lazyso what happens when we write this code struct User { let name: String let isActive: Bool let avatarURL: URL } func search(query: String, in users: [User]) -> [UserRow] { Array( 00
HEhuda elhadyinhudaios.hashnode.dev·Mar 7 · 3 min readSwift: Copy on Write Automatic vs ManualFor a long time I thought CoW happens automatically in Swift and I found that this is not entirely correctAutomatically CoW:so for array, dictionary, set, string and data it happens automatically // a00
HEhuda elhadyinhudaios.hashnode.dev·Mar 6 · 1 min readSwift: High-Level Code, Zero Performance Cost Today I learned something new about Swift — we can write high-level elegant code with zero cost.I wanted to write a simple code that goes through array elements and multiplies each element by 2, and I00