Are you trying to set up authorization on your OkHttp or Retrofit web requests but aren’t sure of the best way to do it? Have you seen the
Authenticator constructs but aren't sure which to use or how best to use them for authorization? We will explore these concepts within OkHttp, how to sign web requests and also how to retry them if they fail due to failed authorization.
When setting up networking in our apps, authorization is almost always required, as not many remote APIs are complete un-authenticated. OAuth is a common system to use, relying on…
Now that we have Swift Package Manager for including framework dependencies, wouldn’t it be great if we could use it to install and run our command-line tool dependencies as well?
What if I told you that this was already possible, allowing you to add tools like SwiftLint to your project within
Package.swift and run automation tasks easily and with minimal configuration.
When working on software projects there are usually a set of different scripts for running project automation, or maybe a selection of different command-line tools all the developers install on their system.
Do you have properties in your Kotlin types that you want to create later after initialization? You may want to avoid making them nullable, avoid using
lateinit or delay an expensive set up process to a later point. In Kotlin this is where delegated properties and lazy properties in particular can be used, allowing properties to be initialized when they are needed and even keep our main type's initialization simpler and cleaner. 👍
The idea of making a property lazy is not new to Kotlin and many developers having been doing it in other languages or doing it themselves for…
Do you want to upload a file using the clean Retrofit syntax, but aren’t sure how to receive the result as well as the upload progress? We will be using Retrofit to perform the file upload, building an implementation that is able to receive the completion progress at intervals and then complete with the remote API response.
Whilst long-running operations are happening, it is nice for the user to see that activity is occurring, such as a progress view being displayed. …
When developing apps we will often need to use secret values that we don’t want anyone to get access to, such as tokens, IDs and API keys. There are many reasons they may be needed in our source code and in Gradle scripts, the most common being when we are asked to provide one to authenticate with a third-party API.
We will examine a selection of techniques that we can apply, providing protection for our secrets and preventing them from sitting in plaintext, in plain sight! 👀
Before we continue: Please check out the article on my blog, Lord Codes…
For codebases with many different entities, most of us will at some point have hit a bug due to the wrong ID being assigned to a property or passed to a function. Why don’t we use the type system to give all of our IDs their own type and ensure this never happens again.
It is very common for objects to need a form of identifier or ID, frequently the reason being to refer to entities when communicating with a remote API or a database. We can easily implement this by giving our classes an ID property with an appropriate…
Wouldn’t it be great if you could represent a single type that can come in different forms, each able to be constant or carry their own data? If programming in Kotlin, we are in luck as that is exactly what a sealed class is perfect for!
Enums or enumerated types have existed in many different programming languages for years and allows us to represent a type whose value is taken from a limited set of values. Kotlin takes this concept and evolves into something much more powerful, known as sealed classes. They are a really useful addition to the language…
Remastered on 1 Sept 2019
When working in the UI layer of an Android app, it won’t be long before we need to perform an operation upon one of our views. In order to do this, we first need to retrieve it via
findViewById. Although using the API can seem simple, it does introduce a block of boilerplate to our Activities. On top of this the code to bind all the views usually ends up in
onCreate, completely separate from the view properties themselves. 😕
Now that Kotlin has entered the scene with new features we didn’t previously have access…
When working on a software project, particularly in a team, a common workflow involves branching from the main branch, often master or develop. The created branch is where changes for a particular feature or issue are applied. One way of managing this branch would involve committing all work for a large feature to this branch and then merging it back once it has been completed. This means the branch lives for a relatively long time and we will likely find the integration process to be a painful process. 😫
Continuous Integration, commonly referred to as CI, is a popular development…
When it comes to logging in Swift and iOS applications in particular, the APIs that first come to mind might be
NSLog. More recently, however, Apple has introduced a new standard for logging in the form of unified logging, accessed via
OSLog. It is the current recommended way of logging, providing an efficient way to capture information across our applications.
Unified logging provides a number of improvements over previous techniques and also some differences to what we are used to.