Filters

Hide filters
Platform
Content Type
Difficulty

All Tutorials · 12 Results

Contained in: Expert Swift combine
iOS & Swift

Chapter in Expert Swift

Functional Reactive Programming

…developers have used these concepts with third-party frameworks such as RxSwift and ReactiveSwift. But became even more widespread with the introduction of Combine — Apple’s reactive programming framework, built into the SDK. Functional programming Functional programming, unsurprisingly, revolves around functions, but more specifically pure functions. Pure functions are functions…
iOS & Swift

Chapter in Expert Swift

Codable

…world — such as automatically synthesized encoding and decoding, support for value types and more. Enter Codable. What is Codable? Codable is a type alias combining two protocols: Encodable and Decodable. These let you define how objects are encoded and decoded to and from an external data representation, such as JSON…
iOS & Swift

Chapter in Expert Swift

API Design Tips & Tricks

…outside the scope of this chapter. You can even leverage string-based dynamic member lookup to make this a bit more robust. Combining @dynamicMemberLookup with @dynamicCallable and adding the following subscript to Command: subscript(dynamicMember member: String) -> Command { Command("\(base) \(member)") } Will concatenate the dynamically accessed member…
iOS & Swift

Chapter in Expert Swift

Strings

…represented like that or by two Unicode scalar values of the standard letter e U+0065 (Latin lowercase letter “e”) followed by U+0301 (combining acute accent). Open a new playground project and try the following: import Foundation let eAcute = "\u{E9}" let combinedEAcute = "\u{65}\u{301}" Those…
iOS & Swift

Chapter in Expert Swift

Generics

Swift — from complete beginners to seasoned veterans — has used generics, whether they know it or not. Generics power arrays and dictionaries, JSON decoding, optionals, Combine publishers and many other parts of Swift and iOS. Because you’ve already used many of these features, you know firsthand how powerful generics…
iOS & Swift

Chapter in Expert Swift

Sequences, Collections & Algorithms

AnySequence(self) } } This code adds an extension to Sequence that erases concrete sequences to AnySequence. It’s in the same spirit as when the Combine framework type erases publishers, which you might have seen before. Use the extension helper by adding: let seq = countDownFrom5State.eraseToAnySequence() print("---") for value in seq { print…
iOS & Swift

Chapter in Expert Swift

Conclusion

…want to read more, there are several books to check out. For building apps in the Apple ecosystem, look at SwiftUI by Tutorials and Combine: Asynchronous Programming with Swift. If you need to support older platforms, you might want to check out RxSwift: Reactive Programming with Swift…
iOS & Swift

Chapter in Expert Swift

Numerics and Ranges

Notice that this improved hierarchy de-emphasizes the importance of radix-two-only BinaryFloatingPoint. Instead, it creates a new empty protocol called Real that combines all the interesting protocols so you can write generic numeric algorithms like this: func compute<RealType: Real>(input: RealType) -> RealType { // ... } RealType…
iOS & Swift

Chapter in Expert Swift

Unsafe

…type inference to determine the same values: let zero = 0.0 MemoryLayout.size(ofValue: zero) // returns 8 In the next section, you’ll see how a combination of types affects the memory layout of the struct itself. Trivial Types You can copy a trivial type bit for bit with no indirection…
iOS & Swift

Chapter in Expert Swift

Objective-C Interoperability

Feed.swift. Make sure you have the BabyKit target selected. Next, replace the content of your new file with the following code: import Foundation import Combine import SwiftUI // 1 public class Feed: ObservableObject { // 2 @Published public var items: [FeedItem] = [] // 3 private let legacyFeed = __Feed() public init() { // 4 items = legacyFeed.loadItems() } // 5 public…
iOS & Swift

Chapter in Expert Swift

Instrumentation

…manage memory, and it’s been around since iOS 4. You know about weak, unowned and strong references. Those are the only possible combinations for any reference type. The compiler tracks the count of references for each object. When the count reaches zero, the compiler releases the object from memory…
iOS & Swift

Chapter in Expert Swift

Protocols

…just built a tiny networking library using protocol-oriented programming! You learned how to use protocols to make your code more flexible, how to combine dependency injection and inversion to make your code testable and how to make your own delegates. You also learned about static and dynamic dispatch…