RSSAmplifier

Blog

Mobile Dev Diary

Recent content on Mobile Dev Diary

mobiledevdiary.comRSS feed ↗30 posts

Latest posts

Say hello to the Apple's new Liquid Glass design

At this year’s WWDC, Apple introduced a major visual update the “Liquid Glass” design - a dynamic new material arriving with iOS 26. Yes, you read that right: all the rumours were true, and we’re jumping straight from iOS 18 to iOS 26. How do I feel about the new design? Honestly, I like it. I did a small side by side comparison using Simulator between iOS 18 and iOS 26.…

WWDC25 - New possibilities have arrived!

New possibilities have arrived! 🛬 This year, Apple released 14 new beta frameworks, bringing powerful tools for product builders to craft outstanding features. As the platform grows, so does its complexity. Don’t worry! You don’t have to master all of them at once (most you may never even use). Instead, focus on understanding each framework’s core purpose. This will broaden your…

Will enter foreground or won't?

Intro All across iOS dev blogs and posts you read about AppDelegate being deprecated in the next major iOS release. AppDelegate has been a go-to for app lifecycle handling since iOS 2. From iOS 13, SceneDelegate lives alongside AppDelegate handling per-scene lifecycle. Do the methods applicationWillEnterForeground and sceneWillEnterForeground actually behave the same? Difference 1 - App-wide vs…

Turning Singleton Usage into Testable Code

See how you can wrap any singleton behind a protocol to make it injectable and your code fully testable 💯 The blog post shows how to deal with URLSession.shared usage. The same strategy can be applied to all other singletons in your code! The problem Service uses URLSession.shared directly. Tight coupling makes unit testing impossible without real network calls. struct PostsAPISerivce { func…

Swift Concurrency Riddle - TaskLocal

Intro If you’re able to solve this, it means you understand TaskLocal really well. Riddle Look at the attached code snippet and guess: What will be printed at each step? Is the order of prints always the same? class Riddler { @TaskLocal static var message = 'Hello' static func riddleMe () { Self . $ message .withValue( 'Bye' , operation: { print( 'Print 1: \( Self .message ) ' ) // ??? Task…

Concurrency-Safe Testing in Swift 6.1 with @TaskLocal and Test Scoping

Today’s example shows a static property providing the current date. Perfect mechanism when we don’t want to inject it everywhere where it’s used. How to test it? Check it out ⤵️ Initial setup let currentDateFormatter: DateFormatter = { let formatter = DateFormatter() formatter.dateStyle = .short formatter.timeStyle = . none return formatter }() var currentDateFormatted: String {…

3 Ways to Name Parameters in Swift Parametrised Tests

Mind your argument names in Swift Testing’s parametrised tests! As a follow up to my recent post on refactoring to use Swift Testing’s parametrised tests, I’m diving into the crucial - yet often overlooked topic of how to name your parametrised test inputs. Option 1: First Named Tuples Only the first tuple is named, all others rely on positional matching to (a, b, result). ✅…

Swift Testing Challange - Can you refactor this?

Intro Have you already started using Swift Testing instead of XCTest? I’m curious to see how you can refactor the test function ( add_returnsCorrectSum ) from the code snippet to use all powers of the Swift Testing framework. Could you explain what benefits does your refactored version has compared to my original code snippet? My approach In both approaches the test gives the same result.…

#3 Swift code refactor in action - a sneaky problem hidden in code snippet

Swift code refactor in action 👨🏻‍💻 Take a close look at the validate function. There’s a sneaky problem hidden in this code snippet. What will the function call return when passed nil ? What problem is hidden here? First, the guard statement is redundant here. We can simplify the function to ⤵️ func validate (password: String?) -> Bool { password?.count ?? 0 > 8 } There’s no need to…

Imperative, Functional, Functional Reactive: Do you know the difference?

Paradigms Imperative In the imperative approach, we have a sequence of instructions that describe step by step how the program’s state is modified. Let’s look on the example ⤵️ var value = 0 func increment () { value += 1 // Mutating the state } print(value) // 0 increment() print(value) // 1 In the code we have a mutable variable value and a function increment that mutates the state (…

Imperative, Functional, Functional Reactive

Do You Know the Difference Between Imperative, Functional, and Reactive Programming? Test your understanding of imperative, functional, and functional reactive programming with this interactive quiz. These questions cover the key concepts from the main post to help you solidify your knowledge for your next interview. --- primary_color: green secondary_color: lightgray text_color: black…

#7 XCTest vs Swift Testing: A modern way of linking bugs

What’s the difference? In XCTest we relied on the old fashioned simple comments to add more context to our test case e.g link to the bug description. With Swift Testing, we now have a special bug trait that can be passed to the @Test macro. The bug trait takes a URL String as argument and optionally a title for the bug allowing us to add short description of it. The key advantage over regular…

#6 XCTest vs Swift Testing - Parameterized tests in the fight for more reusable code

What’s the difference? XCTest doesn’t provide a built-in solution for parameterized tests. To achieve this, we create test cases as structs or tuples, defining test inputs and expected results. Then, we write a loop to iterate through these test cases and execute the necessary assertions. Swift Testing simplifies this process by allowing tests to be parameterized directly. Using the @Test…

#2 Swift code refactor in action - price $$$

Swift code refactor in action 👨🏻‍💻 Today, let’s talk about refactoring for clarity, maintainability, and scalability! This time, the scenario is calculating the final price depending on the price and membership status. This initial code has a few code smells: 1️⃣ nested ifs - impacts general readability, making the code hard to understand, 2️⃣ duplicated conditions - “price > 100”…

#5 XCTest vs. Swift Testing - Conditional disabling - when a test needs a nap

Today we check the diff in conditional disabling. In XCTest there is XCTSkipIf function that takes Bool argument to decide whether a test should run or not. In Swift Testing there’s “disable” trait accepting Bool argument and behaving like XCTSkipIf from XCTest. XCTSkipIf - are you surprised this kind of function exists? To be honest - I was I can admit I learned about it when…

#4 XCTest vs. Swift Testing - Disable tests - handle with care

This week with Swift Testing starts with checking how test disabling differs from XCTest. In XCTest, Xcode identifies a function as a test only if its name starts with the “test” prefix, so putting e.g. “disabled” instead makes the test inactive. Swift Testing simplifies that approach by introducing the @Test macro with a .disabled trait that you can pass as an argument.…

Two types of Swift macros

What is macro? 💡 Macro is a feature that generates code during compilation. Unlike macros in C, which work like “find and replace”, Swift macros are type-safe and context aware, making them powerful tools reducing boilerplate code. Two types of macros attached - use @ prefix, tied to a declaration adding extra logic to it, like: @Test , @Model , @Observable freestanding - use # prefix, standalone…

#3 XCTest vs. Swift Testing - Unwrapping optionals

Optionals are a core of Swift - we deal with them daily, both in production and testing code. Whether you write tests with XCTest or Swift Testing, unwrapping optionals is a common case. In XCTest there is XCTUnwrap operator. Swift Testing introduces #require macro. Is there any difference between them? Not really! Both require the test function to handle exceptions and try keyword before. Gif ⤵️…

#1 Swift code refactor in action - user profile name

Swift code refactor in action 👨🏻‍💻 Common scenario: formatting user profile name - I bet any of you faced this kind of task. At first glance, it look straightforward, but when you take a closer look, you’ll notice two potential improvements: 1️⃣ One single return - simplification of the function flow. 2️⃣ Centralised formatting logic - reduces the chance of bugs. Check out the animated gif and…

#2 XCTest vs. Swift Testing - Has error testing been simplified?

Today we check how testing error has changed in the new framework. In XCTest, we use XCTAssertThrowsError to check if a specific error is thrown. This assertion comes with the error handler closure where we can perform additional checks like e.g. verifying the exact error type. With Swift Testing, this process is even simpler, especially when an error conforms to Equatable . We can directly…

#1 XCTest vs. Swift Testing - fresh look on a new testing framework

New Series! XCTest vs. Swift Testing - fresh look on a new testing framework. Swift Testing was presented at WWDC24 as a new, modern, simplified framework for writing automated tests. It’s a perfect candidate to replace XCTest unit tests, so it’s definitely worth learning. I haven’t had a chance yet to use Swift Testing in production and the series is my motivation for me to discover…

TDD with SwiftUI - Triggering API request

Recap Hello everyone and welcome to the next chapter of the series about SwiftUI code automated testing! In the previous post we defined acceptance criteria for the Joke app that we’re implementing we covered by snapshot tests all UI cases mentioned in the acceptance critieria That’s what the app looks like ⤵️ Here’s the link to the previous blog post ⤵️ (Worth reading before…

Swift Testing parametrized tests

Swift Testing can elevate your unit tests writing 🚀 Hello Apple Developer! I prepared a special post that will help you write better unit tests using the new SwiftTesting framework 🫢 The Swift Testing framework is the successor to XCTest for unit tests. It was introduced at this year’s WWDC24 and is worth learning 📚 One of the main features of Swift Testing are parameterized tests 🧪…

Insights about Swift Testing Tags

Today, I have a special post about Apple’s new testing framework - Swift Testing! 🤩 Swift Testing was presented at WWDC24 as a new, modern, simplified framework for writing automated tests. It’s a perfect candidate to replace XCTest unit tests, so it’s definitely worth learning 🧑‍🏫 The topic of Swift Testing is quite broad, so I decided to break it down into more digestible…

My WWDC 2017 Scholarship submission

Intro This year’s WWDC is just around the corner, and I decided to write about how I ended up at WWDC in 2017. At that time, I was a computer science student and Apple was organizing Swift Student Challange for which I was eligible for. As a young iOS apprentice, I couldn’t miss this opportunity - I signed up. How did I get there? That’s what I want to share with you today. ⤵️

Testing SwiftUI Code - The beginning (UI)

Intro Hello everyone and welcome to my first (ever) blog series! Today, I’m going to begin experimenting with SwiftUI. The mission is to build a small application and having it fully tested 💯. I decided to go for that quest to broaden my knowledge around SwiftUI and verify the rumors that it cannot be tested. To keep it relatively readable I decided to split it up and we’re going to…

Combine: flatMap, map + switchToLatests (flatMapLatest) demystified

Intro Combine is a framework made by Apple designed to support us in writing code that could be way more complex if written in an imperative way. It’s often said that with great power comes great responsibility. Therefore, as developers, it’s essential for us to understand how to harness it, so it does not backfire. Today, we’re going to take a closer look 👀 at a few Combine…

Testing SwiftData and the Query property wrapper through an example

We’re just after this year’s WWDC where we had a chance to witness the unveiling of a new persistence framework called SwiftData. Naturally, I couldn’t resist delving deeper into it. One particular topic that caught my attention was the observation of local storage using Query and its testability. SwiftData SwiftData makes it easy to persist data using declarative code. You can query and filter…

Keep your project clean using synx

A tool written in Ruby which can keep your project and a .pbxproj file clean. A valuable ally when solving complex conflicts inside the project file. Keeping a project file clean during a project life could be tough especially while working in a team, and we conflict our branches from time to time. Solving multiple conflicts in a .pbxproj can lead to mistakes that can cause duplicated references,…

About

My adventure with the iOS platform started over eight years ago. I belong to a generation of developers who started out learning how to create mobile iOS applications in Swift , but I’m also familiar with Objective-C. During over eight years of work, I’ve created 7 applications in Swift from scratch. The experience allowed me to test many solutions, as well as design patterns (MVC, MVVM,…