错误:'NSInvalidArgumentException'...发送到实例

时间:2015-06-24 12:10:04

标签: ios swift uitableview parse-platform

这是我的问题,我正在尝试克隆Snapchat,一个非常简单的,使用Parse.com和页面中给出的默认项目,一切都很好,直到我必须拍照并保存他们将它们发送给用户。使用此代码:

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 numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return usersArray.count
    }


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

        cell.textLabel?.text = usersArray[indexPath.row]

        return cell
    }

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

        activeRecipient = indexPath.row

        pickImage()


    }

    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)

    }


}

错误:

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'

调试不是很有帮助,任何帮助??

EDIT1:我认为解析函数是最后一次调用并打破了所有内容,但我不确定。

screenshot of the exception

EDIT2:我想我已经修好但是我不确定最初的是什么,仍然。新代码是这样的:

var imageToSend = PFObject(className:"Image")
        //var imageData = UIImagePNGRepresentation(image)
        imageToSend["senderUsername"] = PFUser.currentUser()!.username!
        imageToSend["recipientUsername"] = usersArray[activeUser]
        imageToSend.saveInBackgroundWithBlock({
            (success: Bool, error: NSError?) -> Void in
            if (success == false) {
                // Error.
                println("Error horray! \(error?.description)")
            } else {
                // There was a problem, check error.description

                let imageData = UIImagePNGRepresentation(image)

                let imageFile = PFFile(name: "image-png", data: imageData)

                imageToSend["image"] = imageFile

                imageToSend.saveInBackgroundWithBlock({
                    (success: Bool, error: NSError?) -> Void in

                    if success == false {

                        println("something is fucked up \(error?.description)")
                    } else {

                        println("Cool")
                    }
                })

                println("Done")
            }
        })

我想这不是解决方案,而是一种解决方法,所以我将接受Zaph的回答。

1 个答案:

答案 0 :(得分:3)

要查看导致错误的实际语句,请添加异常断点:

从Mian菜单调试:断点:创建异常断点 右键单击断点并将异常设置为Objective-C 添加动作:“po $ arg1”。
运行应用程序以获取断点,您将位于导致异常的行,并且错误消息将位于调试器控制台中。

enter image description here