Sending trial notifications with provisional authorization on iOS
LostMoa
by
1M ago
Sending trial notifications with provisional authorization on iOS In the world of iOS app development, engaging users effectively while respecting their preferences is crucial. Notifications can be a powerful tool for keeping users informed and engaged, but the challenge often lies in obtaining permission to send these notifications. Apple's User Notifications framework offers a solution that strikes a balance between engagement and user consent: provisional notifications. This feature allows apps to send notifications without upfront permission, providing a gentle introduction to our app's no ..read more
Visit website
User-friendly descriptions and recovery suggestions for custom errors in Swift
LostMoa
by
2M ago
User-friendly descriptions and recovery suggestions for custom errors in Swift Creating a seamless user experience in Swift involves not just managing errors but also communicating them effectively. By defining user-friendly descriptions and recovery suggestions for custom errors, we can guide users through resolving issues, making our applications more intuitive and supportive. We can begin by categorizing our custom errors using an enum. Then we should make the enum conform to the LocalizedError protocol to enrich the errors with detailed, localized descriptions and actionable recovery sugge ..read more
Visit website
Use cases for self, Self and Self.self in Swift
LostMoa
by
2M ago
Use cases for self, Self and Self.self in Swift The Swift language constructs self, Self, and Self.self can sometimes be a source of confusion, even for experienced developers. It's not uncommon to pause and recall what each is referring to in different contexts. In this post I aim to provide some straightforward examples that clarify the distinct roles and uses of these three constructs. Whether it's managing instance references, adhering to protocol conformance, or accessing metatype information, understanding these concepts is key to harnessing the full potential of Swift in our projects ..read more
Visit website
Case insensitive string comparison in Swift
LostMoa
by
3M ago
Case insensitive string comparison in Swift String comparison is a fundamental aspect of many programming tasks, from sorting and searching to data validation. The simplest method to compare two strings ignoring case we might think of is converting them to a common case and using ==. However, this approach has significant limitations. Languages and locales have specific rules for case mappings, making simple case conversion unreliable. Let's look at an example in German. let string1 = "Fußball" let string2 = "FUSSBALL" // Prints `false` print(string1.lowercased() == string2.lowercased()) Th ..read more
Visit website
Pattern matching for custom types in Swift
LostMoa
by
4M ago
Pattern matching for custom types in Swift Pattern matching in Swift is a technique that allows us to check and de-structure data in a concise way. It's most often seen in switch statements, where it can match against a variety of patterns. An expression pattern is used in a switch case to represent the value of an expression. The magic behind matching these patterns lies in the ~= operator, which Swift uses under the hood to determine if the pattern matches the value. By default, ~= compares two values of the same type using the == operator, but we can overload it to provide custom behavior ..read more
Visit website
Trigger property observers from initializers in Swift
LostMoa
by
4M ago
Trigger property observers from initializers in Swift In Swift, property observers such as willSet and didSet are not called when a property is set in an initializer. This is by design, as the initializer's purpose is to set up the initial state of an object, and during this phase, the object is not yet fully initialized. However, if we need to perform some actions similar to what we'd do in property observers during initialization, there are some workarounds. # Set properties after initialization One approach is to set the properties after the object has been initialized. class MyClass ..read more
Visit website
Create an AsyncStream from withObservationTracking() function
LostMoa
by
5M ago
Create an AsyncStream from withObservationTracking() function After Natalia wrote her previous post on how to implement the observer pattern in Swift in iOS 17 Using Observation framework outside of SwiftUI, I've been wondering if it would be possible to wrap observation into an AsyncStream. That would let me use an asynchronous for loop to iterate over changes. In this post I will share how I implemented it. I used the same User class from Natalia's post marked with @Observable macro. @Observable class User { var name: String var age: Int init(name: String, age: Int ..read more
Visit website
Using Observation framework outside of SwiftUI
LostMoa
by
5M ago
Using Observation framework outside of SwiftUI This year at WWDC 2023 Apple introduced the new Observation framework which provides an implementation of the observer design pattern in Swift. Classes marked with @Observable macro provided by the framework are now a better alternative to the older ObservableObject when combined with SwiftUI. The new observable classes can be used with existing data flow primitives like State and Environment and trigger view updates only when properties read in the view's body change. But we can also leverage the power of the Observation framework outside of Swif ..read more
Visit website
Filtering logs in Xcode 15
LostMoa
by
6M ago
Filtering logs in Xcode 15 We have some great new features in the debug console in Xcode 15. I'm particularly excited about improved filtering functionality that makes it much easier to view console logs. In this post I'm going to highlight the main changes and show how we can take advantage of them. To benefit from all the nice new features, we have to make sure that we are using unified logging and not print statements in our projects. For the demo purposes in this post, let's imagine that we have the following simple logs already in place. import OSLog ... let welcomeScreenLogger = Logge ..read more
Visit website
IOS app setup for remote push notifications
LostMoa
by
8M ago
iOS app setup for remote push notifications Remote push notifications are messages that app developers can send to users directly on their devices from a remote server. These notifications can appear even if the app is not open, making them a powerful tool for re-engaging users or delivering timely information. They are different from local notifications, which are scheduled and triggered by the app itself on the device. Adding remote notifications capability to an iOS app is a quite involved process that includes several steps and components. This post will walk you through all the necessary ..read more
Visit website

Follow LostMoa on FeedSpot

Continue with Google
Continue with Apple
OR