A
A
Aleksandr Govorukhin2017-06-25 20:21:41
iOS
Aleksandr Govorukhin, 2017-06-25 20:21:41

How to fix '__NSArrayI' (0x1084ecdd8) to 'NSMutableArray' (0x1084ecea0) error in swift 3?

Hello!
I download an archive of images from the Internet and archive:

recipe.imageRecipe = NSKeyedArchiver.archivedData(withRootObject: CDataArray) as NSData

, where CDataArray is of type NSMutableArray.
Then I display it all on the main screen:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! MainTableViewCell
        
        let myRecipe = recipe[indexPath.row]
        
        let img = NSKeyedUnarchiver.unarchiveObject(with: myRecipe.imageRecipe! as Data) as! NSMutableArray
        
        cell.nameRecipe.text = myRecipe.nameRecipe
        cell.imageRecipe.image = UIImage(data: img[0] as! Data)
        

        return cell
    }

, but then I have a photo delete window:
var newImages: [NSData] = []

    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let images = NSKeyedUnarchiver.unarchiveObject(with: self.recipe.imageRecipe! as Data)
        
        newImages = images as! [NSData]

and the rewrite itself
@IBAction func saveEditRecipe() {
        
        let CDataArray = newImages as! NSMutableArray
        
        if let recipe = recipe {
            
            if recipe.value(forKey: "nameRecipe") != nil {
                recipe.setValue(textEditName.text, forKey: "nameRecipe")
            }
            
            if recipe.value(forKey: "descriptionRecipe") != nil {
                recipe.setValue(textEditDescription.text, forKey: "descriptionRecipe")
            }
            
            if recipe.value(forKey: "imageRecipe") != nil {
                recipe.setValue(NSKeyedArchiver.archivedData(withRootObject: CDataArray), forKey: "imageRecipe")
            }
            
        } else {
            print("unable to fetch or create recipe")
        }
        
        
        (UIApplication.shared.delegate as! AppDelegate).saveContext()
        
        self.goToListOfRecepies()
}

, after which I get an error, the one in the header, at this moment:
let img = NSKeyedUnarchiver.unarchiveObject(with: myRecipe.imageRecipe! as Data) as! NSMutableArray

What does he not like if I do identical operations?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aleksandr Govorukhin, 2017-06-26
@SnapSh0t

let img = NSKeyedUnarchiver.unarchiveObject(with: myRecipe.imageRecipe! as Data) as! NSArray

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question