UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Project 10: Name Label in Person NOT WORKING ON ACTUAL DEVICE

Forums > 100 Days of Swift

@manan  

The App works fine on the simulator.

When I run it on my iPhone, the image is picked out fine and it even displays the image.

But the Label which should say 'Unknown' initially is not visible. When I use Rename from the UIAlertController, I present another alert controller with a text field for name.

As soon as I type the first letter in the text field, an error shows up in my Xcode console: 2020-07-21 13:19:24.679451+0530 Project10[33091:14325443] [general] Connection to daemon was invalidated

Here is my didSelectItemAt:

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    let person = people[indexPath.item]

    let ac = UIAlertController(title: nil, message: nil, preferredStyle: .alert)
    ac.addAction(UIAlertAction(title: "Rename", style: .default){
        [weak self] _ in

        let ac1 = UIAlertController(title: "Rename Person", message: nil, preferredStyle: .alert)
        ac1.addTextField()

        ac1.addAction(UIAlertAction(title: "Save", style: .default){
            [weak self,weak ac1] _ in
            guard let newName = ac1?.textFields?[0].text else {return}
            person.name = newName
            self?.collectionView.reloadData()
        })

        ac1.addAction(UIAlertAction(title: "Cancel", style: .cancel))

        self?.present(ac1,animated: true)
    })

    ac.addAction(UIAlertAction(title: "Delete Person", style: .destructive){
        [weak self] _ in
        self?.people.remove(at: indexPath.item)
        self?.collectionView.reloadData()
    })

    ac.addAction(UIAlertAction(title: "Cancel", style: .cancel))
    present(ac,animated: true)

}

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.