TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Challenge

Have you ever been to a conference or a meetup, chatted to someone new, then realized seconds after you walk away that you’ve already forgotten their name? You’re not alone, and the app you’re building today will help solve that problem and others like it.

Your goal is to build an app that asks users to import a picture from their photo library, then attach a name to whatever they imported. The full collection of pictures they name should be shown in a List, and tapping an item in the list should show a detail screen with a larger version of the picture.

Breaking it down, you should:

  • Use PhotosPicker to let users import a photo from their photo library.
  • Detect when a new photo is imported, and immediately ask the user to name the photo.
  • Save that name and photo somewhere safe.
  • Show all names and photos in a list, sorted by name.
  • Create a detail screen that shows a picture full size.
  • Decide on a way to save all this data.

Remember to import the user's photo as Data, so you can write it out easily.

You can use SwiftData for this project if you want to, but it isn’t required – a simple JSON file written out to the documents directory is fine, although you will need to add a custom conformance to Comparable to get array sorting to work.

If you do choose to use SwiftData, here's an important tip: when storing large data like images or movies in your models, define them using a special @Attribute macro like this:

@Attribute(.externalStorage) var photo: Data

That tells SwiftData not to save the image data directly inside its database, but to put it alongside instead – it's much more efficient.

Remember, you already know everything you need to make this work – good luck!

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

BUY OUR BOOKS
Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

Average rating: 4.4/5

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.