Follow along at https://www.hackingwithswift.com/100/23.
This day resolves around recapping the content covered while going through Projects 1-3 in Hacking with Swift. I won't try to rehash what I wrote up already, but a few additional key points are worth mentioning:
- When we instantiate a view controller in code, and the view controller is based on what we've set up in our storyboard, we need to communicate this to iOS by using the
storyboard.instantiateViewController
method:
if let vc = storyboard?.instantiateViewController(withIdentifier: "Detail") as? DetailViewController {
}
-
UIActivityViewController
can do a lot. And so, not surprisingly, some of its capabilities overlap with permissions. For example, if we want our app to be able to save an image to the photo library, we need to configure the target'sinfo.plist
file it to ask for thePrivacy - Photo Library Additions Usage Description
permission. -
Each
UIView
element has alayer
property, which is an instance of theCALayer
class. While UIView elements also have their own higher-level styling properties, this can unlock access to styling at a lower-level for things related toCoreAnimation
such as gradients and particle effects.
A good way to end a recap is to extend on things. Day 23 ends with a challenge project:
Create an app that lists various world flags in a table view. When one of them is tapped, slide in a detail view controller that contains an image view, showing the same flag full size. On the detail view controller, add an action button that lets the user share the flag picture and country name using UIActivityViewController.
Feel free to peruse the finished project here. In the meantime... a few screenshots:
- One thing I couldn't figure was how to ensure each image in the table view was the same size just by using the default cell. The flag of Albania asset is actually rather large, but for some reason its being resized to a smaller version. Perhaps I need to experiment more with the image scaling settings — or use a custom cell class for more fine-grained control.