Recent articles
Jump to a random postTesting push notifications in the Simulator with Xcode 11.4
Published on: February 12, 2020For years we've had to resort to using physical devices when testing push notifications. With Xcode 11.4, Apple finally gives developers the tools needed to test push notifications on the iOS Simulator. I'm going to assume you already know how to add push notifications to your app. If you've never added push notifications to an app before, I have a post that describes how to set up and test push notifications without a third-party service. That post should get you all set up to follow along with this post. Sending a test push from the command line Xcode comes with...
Read more...Using Promises and Futures in Combine
Published on: February 10, 2020So far in my Combine series I have mostly focussed on showing you how to use Combine using its built-in mechanisms. I've shown you how Combine's publishers and subscribers work, how you can use Combine for networking, to drive UI updates and how you can transform a Combine publisher's output. Knowing how to do all this with Combine is fantastic, but your knowledge is also still somewhat limited. For example, I haven't shown you at all how you can take an asynchronous operation in your existing code, and expose its result using Combine. Luckily, that is exactly what I'm going...
Read more...Five ways to get better at receiving feedback
Published on: February 5, 2020When I just started my career as a developer there was a lot I didn't know yet. There also were a lot of things I didn't understand or had never done before. I have always been lucky enough to work in places where I was able to learn and grow as needed, and most importantly, I was allowed to make mistakes. One of the hardest things wasn't that I was constantly learning and figuring out. That actually was the fun part! The hard bit was often receiving feedback. Whether it was feedback from clients, coworkers or teachers back in college....
Read more...Using map, flatMap and compactMap in Combine
Published on: February 3, 2020Oftentimes when you're working with Combine, you'll have publishers that produce a certain output. Sometimes this output is exactly what you need, but often the values that are output by a publisher need to be transformed or manipulated somehow before they are useful to their subscribers. The ability to do this is a huge part of what Combine is, what makes it so powerful, and Functional Reactive Programming (FRP) in general. In this week's post, I will show you several common operators that you can use to transform the output from your publishers and make them more useful. If you've...
Read more...Updating UI with assign(to:on:) in Combine
Published on: January 29, 2020So far in my series of posts about Combine, we have focussed on processing values and publishing them. In all of these posts, I used the sink method to subscribe to publishers and to handle their results. Today I would like to show you a different kind of built-in subscriber; assign(to:on:). This subscriber is perfect for subscribing to publishers and updating your UI in response to new values. In this post, I will show you how to use this subscriber, and I will show you how to avoid memory issues when using assign(to:on:). Using assign(to:on:) in your code If you've...
Read more...Publishing property changes in Combine
Published on: January 27, 2020In Combine, everything is considered a stream of values that are emitted over time. This means that sometimes a publisher can publish many values, and other times it publishes only a single value. And other times it errors and publishes no values at all. When your UI has to respond to changing data, or if you want to update your UI in response to a user's actions, you might consider the data and user input to both be streams of values. When we looked at networking in my previous post, it was possible to use a built-in publisher that is...
Read more...Debugging network traffic with Charles
Published on: January 22, 2020When you perform a URL Request in your app, you typically configure the request in your code and when it's all set up you pass it off to a URLSession data task, and the request should succeed if everything goes as expected. When the request is misconfigured, the server will hopefully return a useful error and you can fix your code accordingly. There are times, however, where the server does not give the information you need. Or your requests succeed but your results are not quite what you expect. It's times like these when I really wish that there was...
Read more...How to sort an Array based on a property of an element in Swift?
Published on: January 20, 2020This post is a short demo of using Swift's sort() and sort(by:) methods. For a more comprehensive overview of sorting, and some background information on how Swift's sorting works I recommend you take a look at this updated post The easiest way to sort an Array in Swift is to use the sort method. This method is available for all Arrays that have Comparable elements and it sorts your array in place: var words = ["hello", "world", "this", "is", "a", "list", "of", "strings"] words.sort() // words is now ["a", "hello", "is", "list", "of", "strings", "this", "world"] This modifies the input...
Read more...Refactoring a networking layer to use Combine
Published on: January 20, 2020In the past two weeks I have introduced you to Combine and I've shown you in detail how Publishers and Subscribers work in Combine. This week I want to take a more practical route and explore Combine in a real-world setting. A while ago, I published a post that explained how you can architect and build a networking layer in Swift without any third-party dependencies. If you haven't seen that post before, and want to be able to properly follow along with this post, I recommend that you skim over it and examine the end result of that post. This...
Read more...How to add an element to the start of an Array in Swift?
Published on: January 19, 2020You can use Array's insert(_:at:) method to insert a new element at the start, or any other arbitrary position of an Array: var array = ["world"] array.insert("hello", at: 0) // array is now ["hello", "world"] Make sure that the position that you pass to the at: argument isn't larger than the array's current last index plus one. For example: // this is fine var array = ["hello"] array.insert("world", at: 1) // this will crash var array = ["hello"] array.insert("world", at: 2) If you have any questions about this tip, or if you have feedback for me, don't hesitate to reach...
Read more...