SnapSh0t
@SnapSh0t
iOS-Developer

Как исправить ошибку '__NSArrayI' (0x1084ecdd8) to 'NSMutableArray' (0x1084ecea0) в swift 3?

Здравствуйте!

Я скачиваю архив изображений с интернета и архивирую:
recipe.imageRecipe = NSKeyedArchiver.archivedData(withRootObject: CDataArray) as NSData

, где CDataArray имеет тип NSMutableArray.
После чего отображаю это все на главном экране:
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
    }

, но потом у меня есть окно удаления фото:
var newImages: [NSData] = []

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


и сама перезапись,
@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()
}

, после чего у меня вылезает ошибка, та что в шапке, в этом моменте:
let img = NSKeyedUnarchiver.unarchiveObject(with: myRecipe.imageRecipe! as Data) as! NSMutableArray

Что ему не нравится, если я делаю идентичные операции?
  • Вопрос задан
  • 216 просмотров
Решения вопроса 1
SnapSh0t
@SnapSh0t Автор вопроса
iOS-Developer
let img = NSKeyedUnarchiver.unarchiveObject(with: myRecipe.imageRecipe! as Data) as! NSArray
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы