我正在为我的应用程序制作一个简单的登录屏幕。最初,当我设置 PFObject 和 PFUser 在后台保存时它正在工作,突然我添加了几行代码,然后它停止工作并出现以下错误:
2015-10-24 04:49:09.101 ParseStarterProject-Swift[936:44671] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The class PFUser must be registered with registerSubclass before using Parse.' * First throw call stack:
我的代码非常简单:
import UIKit
import Parse
class ViewController: UIViewController, UIApplicationDelegate {
//registration screen VARIABLES
var user = PFUser()
//Password
@IBOutlet weak var password: UITextField!
//UserName
@IBOutlet weak var userName: UITextField!
//Email
@IBOutlet weak var userEmailAddress: UITextField!
//registration Screen METHODS
//Facbook
@IBAction func facebookRegistration(sender: AnyObject) {
}
//Twitter
@IBAction func twitterRegistration(sender: AnyObject) {
}
//Email
@IBAction func emailRegistartion(sender: AnyObject)
{
//Check if any fields are nil
if userEmailAddress.text == "" || userName.text == "" || password.text == ""
{
//provide and alert
self.alert("oops", yourMessage: "looks like you are missing some fields", yourPrefferredStyle: UIAlertControllerStyle.Alert, actionTitle: "ok", alertStyle: UIAlertActionStyle.Default)
self.activityIndicator(frame: 0, frame: 0, frame: 50, frame: 50, indicatorViewStyle: .White)
}
//implement email confirmation alert
else{
self.createUser(userName.text, password: password.text, email: userEmailAddress.text)
}
}
//Sign In
@IBAction func signInButton(sender: AnyObject) {
}
//THIS IS A GENERIC FUNCTION TO CREATE A PFUSER
func createUser (username: String!, password: String!, email: String!)
{
let user = PFUser()
user.username = username
user.password = password
user.email = email
user.signUpInBackgroundWithBlock { (saved: Bool, error:NSError?) -> Void in
if let error = error {
_ = error.userInfo["error"] as? NSString
}
else
{
self.alert("Registered!", yourMessage: "You have successfully registered, please check your email for verification.", yourPrefferredStyle: UIAlertControllerStyle.Alert, actionTitle: "Sweet", alertStyle: UIAlertActionStyle.Default)
}
}
}
//THIS IS THE GENRIC ALERT FUNCTION
func alert (alertTitle: String?, yourMessage: String?, yourPrefferredStyle:UIAlertControllerStyle, actionTitle: String?, alertStyle: UIAlertActionStyle)
{
let alert = UIAlertController(title: (alertTitle), message:(yourMessage), preferredStyle:(yourPrefferredStyle))
alert.addAction((action: UIAlertAction(title: (actionTitle), style: (alertStyle), handler: { (action) -> Void in
self.dismissViewControllerAnimated(true, completion: nil)})))
self.presentViewController(alert, animated: true, completion: nil)
}
//THIS IS A GENEREIC LOADING INDICATION ANIMATION
func activityIndicator (frame x: CGFloat?, frame y: CGFloat?, frame Width: CGFloat?, frame height: CGFloat?, indicatorViewStyle: UIActivityIndicatorViewStyle)
{
var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
activityIndicator.center = self.view.center
activityIndicator.hidesWhenStopped = true
activityIndicator.activityIndicatorViewStyle = indicatorViewStyle
view.addSubview(activityIndicator)
activityIndicator.startAnimating()
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
}
如您所见,我创建了自己的函数来创建 PFuser,以便每次用户输入新凭据并点击寄存器时都可以调用函数...但它不起作用。希望有人可以帮忙!
最佳答案
您需要在应用程序委托(delegate)中调用设置方法。
[Parse setApplicationId:@"xxx" clientKey:@"xxx"];
https://parse.com/apps/quickstart#parse_data/mobile/ios/native/new
关于ios - PARSE - STARTER SWIFT : 'NSInternalInconsistencyException' , 原因:'在使用 Parse 之前,必须使用 registerSubclass 注册 PFUser 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33319848/