Filters

Hide filters
Platform
Content Type
Difficulty

All Tutorials · 8 Results

Contained in: Swift Internals strings
iOS & Swift

Chapter in Swift Internals

Metaprogramming

Mirror is quite simple. You create a Mirror to reflect any instance you want to inspect. Consider the following code: struct User { let name: String let age: Int } let michael = User(name: "Michael Scott", age: 44) // Create the mirror let mirror = Mirror(reflecting: michael) Once you have the mirror object…
iOS & Swift

Chapter in Swift Internals

Where the Memory Lies

…read-only data segment of the binary. These are initialized once at runtime in a thread-safe way and embedded into the binary alongside string literals and global constants. On the other hand, static var is stored in a global data section that supports write operations. Each static…
iOS & Swift

Chapter in Swift Internals

Protocols, Dispatch, Existential Types

…original method with that of the new method, effectively redirecting the dispatch. extension UIViewController { @objc func track_viewDidLoad() { print("View Did Load: \(String(describing: type(of: self)))") self.track_viewDidLoad() } static func swizzleViewDidLoad() { let originalSelector = #selector(viewDidLoad) let swizzledSelector = #selector(track_viewDidLoad) guard let originalMethod = class_getInstanceMethod(self, originalSelector), let swizzledMethod…
iOS & Swift

Chapter in Swift Internals

Metamorphosis: Ars Generalis

…components: a path, an HTTP method, an optional request body, and a specific response type you expect to receive. Something like: enum HTTPMethod: String { case post case get } protocol APIRequest { associatedtype RequestBody: Encodable associatedtype Response: Decodable var path: String { get } var method: HTTPMethod { get } } Here, the RequestBody represents the encodable…
iOS & Swift

Chapter in Swift Internals

Demystifying Swift Compiler Magic

…register numbers differ in your case, you should still be able to see the following under the sil @main. %45 = struct $String (%44 : $_StringGuts) // user: %47 // function_ref print(_:separator:terminator:) %46 = function_ref @$ss5print_9separator10terminatoryypd_S2StF : $@convention(thin) (@guaranteed Array<Any>, @guaranteed String, @guaranteed String) -> () // user…
iOS & Swift

Chapter in Swift Internals

Embracing Structured Concurrency

…created with a higher priority while the parent awaits their result. Consider the following example of an implicit child: struct UserProfile { var name: String var handle: String } struct ActivityItem { var description: String } func fetchProfile() async throws -> UserProfile { print("Child 1 (Profile): Fetching...") try await Task.sleep(for: .seconds(1)) // Simulate…
iOS & Swift

Chapter in Swift Internals

Architectural Dynamics: Modularization & Linking

…specifically a directory with a known structure. It bundles the Library (the code) together with the Module (the interface) and Resources (images, storyboards, localization strings, and so on). Apple operating system utilize frameworks because they provide a single, portable, self-contained unit that includes everything a user needs…
iOS & Swift

Chapter in Swift Internals

Unsafe Swift

…bounds” error instead of silently corrupting memory. Strict Type Safety: Swift is a strongly typed language. This helps prevent assigning an Int to a String type. Features like these make Swift a safe and productive language to work with. They eliminate many low-level issues that can cause problems…