Chapter 19: UI Improvements Section: Add Icons Error (‘image’ is unavailable: APIs as of iOS 7 and earlier are unavailable in Swift

Hello guys,

I am currently stuck in the adding icons section of chapter 19. I added the following code:

override func viewDidLoad() {
    super.viewDidLoad()

    if let checklist = checklistToEdit {
       title = “Edit Checklist”
       textField.text = checklist.name
       doneBarButton.isEnabled = true
       iconName = checklist.iconName
   }
 iconImage.image = UIImage(named: iconName) // I added this
}

When I added the iconImage.image = UIImage(named: iconName) code, it throws up this error:

‘image’ is unavailable: APIs deprecated as of iOS 7 and earlier are unavailable in Swift

Are there any solutions or workarounds for this? Thanks in advance.
My macOS version is: macOS Mojave 10.14.2
Xcode version: 10.1 (10B61)

Since the code works with Xcode 10 and Swift 4.2, there should not be any properties that are deprecated and not available to Swift. So my suspicion is that you had defined iconImage as a different type than what the book specifies. Can you check the type of the iconImage property against the code provided in the book?

If it doesn’t match, that’s your issue …

If it matches then, one thing you can do is check your project against the provided final project in the book if you want to troubleshoot the issue yourself.

Alternatively, please upload your project as a ZIP file somewhere and provide a link to the ZIP file so that I (or someone else) can download the file and see what might be going on.

1 Like

Hello again,

I checked my ListDetailViewController.swift against the ListDetailViewController.swift provided in the final project in the book. It turns out I made a mistake of defining iconImage as UITableViewCell instead of UIImageView!

47

After making the necessary changes, I built the app with no errors. I have made a callous mistake.

I’m glad that you were able to sort it out :slight_smile: And don’t worry about the mistakes - they happen to even the most experienced programmer. The thing is to learn from each mistake as to how to spot what might be going wrong …

2 Likes

Thank you so much for your help!

Had the same issue as @ndx_54.
I think this is because the instruction in the book is a little off:

Use the Assistant Editor to add an outlet property for the cell to ListDetailViewController.swift and name it iconImage

Here it is saying to add the outlet for the cell - not the UIImageView within the cell.

Thank you for posting your findings though!

2 Likes

This topic was automatically closed after 166 days. New replies are no longer allowed.