Skip to main content

CDN error on pod update

Today while in Terminal, I ran a regular script pod update.  However, this time I received the following error

[!] CDN: trunk URL couldn't be downloaded: https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/d/a/2/Alamofire/5.1.0/Alamofire.podspec.json Response: Timeout was reached

I read on GitHub that it could be a cache issue, so I ran:

Creating a new SwiftUI project

Creating a new SwiftUI project is a quick process.  There are already thousands of sites outlining how to do these steps.  Rather than repeat this steps at the top of each article, we will refer to this article to get you across the line if you don't know or need a refresher.

Step 1

Open Xcode and either click Create a new Xcode project in Xcode’s startup window, or choose File > New > Project.

SwiftUI adding a background image with a gradient tint

I'm going to take you on a journey about adding a gradient tint to a background image.  The journey will go through text modifiers with regular and semibold font weights, and font colour.  Using an image from Unsplash.  Adding a black tint, then transform it to a gradient using a colour array.  If you get lost along the journey, the final result is available on GitHub.

Gradient tint over a background image

How to apply a gradient tint over a background image?

Set the background image

The first step is to set the background image.  I wanted the image to cover the entire device, so scale aspect fill will be required.

self.backgroundImage = UIImageView(image: UIImage(named: "bgkMain"))
self.backgroundImage.contentMode = .scaleAspectFill
self.view.insertSubview(self.backgroundImage, at: 0)

 

date formatter

Working on formatting the date in Xcode, and you come across the situation where you need to check or test the date format.  NSDateFormatter is a great site to check your date format string.  I wanted to transform the 2019-08-15 10:34:49+1000 to Aug 15, 12:34 AM.

Number decimal places

Adding a floating decimal point for n number of places is quite easy to achieve.  The key to understand is the receive an outcome of a fraction the numbers need to be Double.  So Int numbers will result in a whole number product.  By way of example:

  • 80 / 3 = 26

We know that this result is incorrect.  To get the correct outcome the equation needs to be as follows:

Code conventions

Whatever you are coding - code clarity is your goal.

Subscribe to iOS