在Swift中对Parse的PFUser进行子类化 [英] Subclassing Parse's PFUser in Swift

查看:147
本文介绍了在Swift中对Parse的PFUser进行子类化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我知道之前已经提出了类似的问题,并且我已经尝试遵循这个建议 stackoverflow在这里回答无济于事。我也尝试添加这个的基本要点作为评论,但我还没有足够的代表:(基本上我试图使用PFSubclassing来扩展Parse的PFUser模型。因此,这是我的相应代码:

First off, I know similar questions have been asked before and I've tried following the advice of this stackoverflow answer here to no avail. I also tried adding the basic gist of this as a comment, but I don't have enough rep yet :( Basically I am trying to use PFSubclassing to extend Parse's PFUser model. As such, here's my corresponding code:

User.swift:

User.swift:

import Foundation
import CoreLocation

class User : PFUser, PFSubclassing {

    override init() {
        super.init()
    }

    convenience init(email: String!) {
        self.init()

        self.email = email
        self.username = email

    }

    // don't need to call User.registerSubclass() in AppDelegate because this
    // is handling that here
    override class func load() {
        self.registerSubclass()
    }

    // Commented out because this is extending PFUser
    //    override class func parseClassName() -> String! {
    //        return "PFUser"
    //    }
}

测试结果:

-[PFObject _loadSensitiveUserDataFromKeychainItemWithName:]: unrecognized selector sent to instance 0x7f98ebc1c250

我是还在我的Bridging-Header中执行以下操作:

I'm also doing the following in my Bridging-Header:

#import <Parse/Parse.h>
#import <Parse/PFObject+Subclass.h>

如果我在User.swift中取消注释parseClassname()我得到:

If I un-comment "parseClassname() in User.swift" I get:

failed: caught "NSInvalidArgumentException", "Cannot initialize a PFUser with a custom class name."

这让我相信设置界面至少部分有效。

Which leads me to believe that setting up the interfaces is at least partially working.

根据我所见过的所有建议,我似乎无法弄清楚我做错了什么。还有一个 open bug ,它会产生相同的错误消息,但它是由使用引起的Parse的本地数据存储,我还没有配置任何一个。

Based on all of the advice I've seen, I can't seem to figure out what I'm doing wrong. There is also an open bug that produces the same error message, but it is caused by using Parse's local data store and I haven't configured any of that.

此时我觉得我错过了一些显而易见的东西,或者我受到同样的影响如上所述的错误。有什么建议吗?

At this point I feel like I am missing something dead obvious, or I am being affected by the same bug as mentioned above. Any suggestions?

推荐答案

好的,通过反复试验解决了我自己的问题。基本上它看起来像缓存登录PFUser导致问题。当Parse最初加载时,它正在从模拟器加载登录状态,该状态与新注册的User子类冲突。

Okay, solved my own problem here through trial and error. Essentially it looks like a cached logged in PFUser was causing problems. When Parse would initially load it was loading the logged in state from the emulator which was conflicting with the newly registered User subclass.

要修复此问题,您可以:

To fix this you can either:


  1. 重新启动模拟器。

  2. 致电 PFUser.logOut()在AppDelegate中的Parse.setApplicationId()之后立即刷新缓存的用户。

  1. Restart the emulator.
  2. Call PFUser.logOut() right after Parse.setApplicationId() in AppDelegate to flush the cached user.

希望将来帮助其他人!

这篇关于在Swift中对Parse的PFUser进行子类化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆