GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

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 try! Swift Tokyo.

SPONSORED Ready to dive into the world of Swift? try! Swift Tokyo is the premier iOS developer conference will be happened in April 9th-11th, where you can learn from industry experts, connect with fellow developers, and explore the latest in Swift and iOS development. Don’t miss out on this opportunity to level up your skills and be part of the Swift community!

Get your ticket here

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.