mercredi 24 juin 2015

swift IOS 8 NSInvalidArgumentException, why?

Here is my problem, I'm trying to make a clon of snapchat very simple one, using parse with the default project given in the page, everything was going ok, until I have to take pictures and save them to send them to an user. With this code:

//
//  UsersTableViewController.swift
//  SnapClomSwift
//
//  Created by Pedro Alonso on 24/06/15.
//  Copyright (c) 2015 Parse. All rights reserved.
//

import UIKit
import Parse

class UsersTableViewController: UITableViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {


    var usersArray: [String] = []

    var activeRecipient: Int = 0

    override func viewDidLoad() {
        super.viewDidLoad()

        var query = PFUser.query()
        query?.whereKey("username", notEqualTo: PFUser.currentUser()!.username!)

        var users = query?.findObjects()

        if let user = users {
            for username in user {
                println(username.username!!)

                usersArray.append(username.username!!)


            }
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Potentially incomplete method implementation.
        // Return the number of sections.
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete method implementation.
        // Return the number of rows in the section.
        return usersArray.count
    }


    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("snapCell", forIndexPath: indexPath) as! UITableViewCell

        // Configure the cell...
        cell.textLabel?.text = usersArray[indexPath.row]

        return cell
    }

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        activeRecipient = indexPath.row

        pickImage()


    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using [segue destinationViewController].
        // Pass the selected object to the new view controller.
    }
    */

    func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {

        //Upload image to parse //error come somewhere from here I think


        println("Image Selected")
        self.dismissViewControllerAnimated(true, completion: nil)


        var imageToSend = PFObject(className:"Image")
        imageToSend["image"] = UIImageJPEGRepresentation(image, 0.5)
        imageToSend["senderUsername"] = PFUser.currentUser()!.username
        imageToSend["recipientUsername"] = usersArray[activeRecipient]

        imageToSend.save()

    }

    func pickImage() {

        var image = UIImagePickerController()
        image.delegate = self
        image.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
        image.allowsEditing = false

        self.presentViewController(image, animated: true, completion: nil)

    }


}

The error:

2015-06-24 15:03:13.414 SnapClomSwift[2043:124661] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMutableData PF_base64EncodedString]: unrecognized selector sent to instance 0x7a648960'

Is not very helpful to debug, any help??

See more ..

Aucun commentaire:

Enregistrer un commentaire