2nd December solution - Advent of Code 2020 - swift

As part of Advent of Code (adventofcode.com) each day there are two programming tasks to be solved. All solutions are listed here.

I am writing the solutions in Swift with the Playground environment in xCode.

Tasks - 2nd December 2020

  1. Check validity of passwords for the pattern [minOccurencesOfChar]-[minOccurencesOfChar] [char]: [password]

  2. Check validity of passwords for the pattern [firstPositionOfChar]-[secondPositionOfChar] [char]: [password] and where either the firstPositionOfChar or secondPositionOfChar contains the character.

For a more detailed description of the tasks check this out.

The password variable is an array of strings containing the lines given by Advent of Code, which is individual for each user. I only show a small excert of this variable below. I use String Extensions for a more convenient solution.

Here is the solution:

Overview of all solutions of 2020:

Advent of Code 2020 Solutions Overview

1st December solution - Advent of Code 2020 - swift

As part of Advent of Code (adventofcode.com) each day there are two programming tasks to be solved. All solutions are listed here.

I am writing the solutions in Swift with the Playground environment in xCode.

Tasks - 1st December 2020

  1. In a list of numbers find two numbers, which add up to exactly 2020 and take their product.

  2. In a list of numbers find three numbers, which add up to exactly 2020 and take their product.

The data variable is an array of the list of numbers given by Advent of Code, which is individual for each user.

Here is the solution:

Overview of all solutions of 2020:

Advent of Code 2020 Solutions Overview

Get photo metadata with PHPicker in SwiftUI

With iOS 14.0 a new photo picker PHPicker was introduced. In this post I will show you how to get and show photo metadata, the PHAsset, containing information like creation date and the location of where the photo was taken, in SwiftUI.

When using the PHPickerViewControllerDelegate the metadata can be obtained the following way:

Screenshot 2020-10-18 at 11.05.07.png

Make sure to add the Privacy - Photo Library Usage Description key to the Info.plist file

Simple CustomPhotoPickerView example

I created a full example app of how to get and display photo metadata with the new PHPicker in iOS 14.

It can be cloned here:

Link to GitHub repo at simple branch which only contains the basics.

Link to GitHub repo at main branch which has the UI shown here.

Simulator Screen Shot - iPhone SE (2nd generation) - 2020-10-18 at 07.23.41.png

As the PHPickerView is a UIView the UIViewControllerRepresentable protocol must be used for using it with SwiftUI.