PFUser
Objective-C
@interface PFUser : PFObject <PFSubclassing>
Swift
class PFUser : PFObject, PFSubclassing
The PFUser class is a local representation of a user persisted to the Parse Data.
This class is a subclass of a PFObject, and retains the same functionality of a PFObject,
but also extends it with various user specific methods, like authentication, signing up, and validation uniqueness.
-
Gets the currently logged in user from disk and returns an instance of it.
Declaration
Objective-C
+ (nullable instancetype)currentUser;Swift
class func current() -> Self?Return Value
Returns a
PFUserthat is the currently logged in user. If there is none, returnsnil. -
Asynchronously loads the currently logged in user from disk and returns a task that encapsulates it.
Declaration
Objective-C
+ (id)getCurrentUserInBackground;Swift
class func getCurrentUserInBackground() -> Any!Return Value
The task that encapsulates the work being done.
-
The session token for the
PFUser.This is set by the server upon successful authentication.
Declaration
Objective-C
@property (nonatomic, copy, readonly, nullable) NSString *sessionToken;Swift
var sessionToken: String? { get } -
Whether the
PFUserwas just created from a request.Declaration
Objective-C
@property (nonatomic, readonly) BOOL isNew;Swift
var isNew: Bool { get } -
Whether the user is an authenticated object for the device.
An authenticated
PFUseris one that is obtained via a-signUp:or+logInWithUsername:password:method. An authenticated object is required in order to save (with altered values) or delete it.Declaration
Objective-C
@property (nonatomic, assign, unsafe_unretained, readonly, getter=isAuthenticated) BOOL authenticated;Swift
var isAuthenticated: Bool { get }
-
Creates a new
PFUserobject.Declaration
Objective-C
+ (nonnull instancetype)user;Return Value
Returns a new
PFUserobject. -
Enables automatic creation of anonymous users.
After calling this method,
+currentUserwill always have a value. The user will only be created on the server once the user has been saved, or once an object with a relation to that user or an ACL that refers to the user has been saved.Warning
PFObject.will not work on if an item being saved has a relation to an automatic user that has never been saved.Declaration
Objective-C
+ (void)enableAutomaticUser;Swift
class func enableAutomaticUser() -
The username for the
PFUser.Declaration
Objective-C
@property (nonatomic, strong, nullable) NSString *username;Swift
var username: String? { get set } -
! The password for the
PFUser.This will not be filled in from the server with the password. It is only meant to be set.
Declaration
Objective-C
@property (nonatomic, strong, nullable) NSString *password;Swift
var password: String? { get set } -
The email for the
PFUser.Declaration
Objective-C
@property (nonatomic, strong, nullable) NSString *email;Swift
var email: String? { get set } -
Signs up the user asynchronously.
This will also enforce that the username isn’t already taken.
Warning
Make sure that password and username are set before calling this method.
Declaration
Objective-C
- (id)signUpInBackground;Swift
func signUpInBackground() -> Any!Return Value
The task, that encapsulates the work being done.
-
Signs up the user asynchronously.
This will also enforce that the username isn’t already taken.
Warning
Make sure that password and username are set before calling this method.
Declaration
Objective-C
- (void)signUpInBackgroundWithBlock:(nullable PFBooleanResultBlock)block;Swift
func signUpInBackground() async throws -> BoolParameters
blockThe block to execute. It should have the following argument signature:
^(BOOL succeeded, NSError *error).
-
Makes an asynchronous request to login a user with specified credentials.
Returns an instance of the successfully logged in
PFUser. This also caches the user locally so that calls to+currentUserwill use the latest logged in user.Declaration
Objective-C
+ (id)logInWithUsernameInBackground:(nonnull NSString *)username password:(nonnull NSString *)password;Swift
class func logInWithUsername(inBackground username: String, password: String) -> Any!Parameters
usernameThe username of the user.
passwordThe password of the user.
Return Value
The task, that encapsulates the work being done.
-
Makes an asynchronous request to log in a user with specified credentials.
Returns an instance of the successfully logged in
PFUser. This also caches the user locally so that calls to+currentUserwill use the latest logged in user.Declaration
Objective-C
+ (void)logInWithUsernameInBackground:(nonnull NSString *)username password:(nonnull NSString *)password block:(nullable PFUserResultBlock)block;Swift
class func logInWithUsername(inBackground username: String, password: String, block: PFUserResultBlock? = nil)Parameters
usernameThe username of the user.
passwordThe password of the user.
blockThe block to execute. It should have the following argument signature:
^(PFUser *user, NSError *error). -
Logs in a user with username and password and additional authentication data (e.g., MFA).
The authData keys must follow the Parse Server spec, for example: @{ @“mfa”: @{ @“token”: authCode } }
This data is only sent as part of the login request and is not persisted on the PFUser instance.
Declaration
Objective-C
+ (id)logInWithUsernameInBackground:(nonnull NSString *)username password:(nonnull NSString *)password authData:(nullable NSDictionary<NSString *, id> *) authData;Swift
class func logInWithUsername(inBackground username: String, password: String, authData: [String : Any]?) -> Any! -
Block variant of login with additional authData.
Declaration
Objective-C
+ (void)logInWithUsernameInBackground:(nonnull NSString *)username password:(nonnull NSString *)password authData:(nullable NSDictionary<NSString *, id> *) authData block:(nullable PFUserResultBlock)block;Swift
class func logInWithUsername(inBackground username: String, password: String, authData: [String : Any]?, block: PFUserResultBlock? = nil)
-
Makes an asynchronous request to become a user with the given session token.
Returns an instance of the successfully logged in
PFUser. This also caches the user locally so that calls to+currentUserwill use the latest logged in user.Declaration
Objective-C
+ (id)becomeInBackground:(nonnull NSString *)sessionToken;Swift
class func become(inBackground sessionToken: String) -> Any!Parameters
sessionTokenThe session token for the user.
Return Value
The task, that encapsulates the work being done.
-
Makes an asynchronous request to become a user with the given session token.
Returns an instance of the successfully logged in
PFUser. This also caches the user locally so that calls to+currentUserwill use the latest logged in user.Declaration
Objective-C
+ (void)becomeInBackground:(nonnull NSString *)sessionToken block:(nullable PFUserResultBlock)block;Swift
class func become(inBackground sessionToken: String, block: PFUserResultBlock? = nil)Parameters
sessionTokenThe session token for the user.
blockThe block to execute. The block should have the following argument signature:
^(PFUser *user, NSError *error).
-
Enables revocable sessions and migrates the currentUser session token to use revocable session if needed.
This method is required if you want to use
PFSessionAPIs and your application’s ‘Require Revocable Session’ setting is turned off onhttp://parse.comapp settings. After returnedBFTaskcompletes -PFSessionclass and APIs will be available for use.Declaration
Objective-C
+ (id)enableRevocableSessionInBackground;Swift
class func enableRevocableSessionInBackground() -> Any!Return Value
An instance of
BFTaskthat is completed when revocable sessions are enabled and currentUser token is migrated. -
Enables revocable sessions and upgrades the currentUser session token to use revocable session if needed.
This method is required if you want to use
PFSessionAPIs and legacy sessions are enabled in your application settings onhttp://parse.com/. After returnedBFTaskcompletes -PFSessionclass and APIs will be available for use.Declaration
Objective-C
+ (void)enableRevocableSessionInBackgroundWithBlock: (nullable PFUserSessionUpgradeResultBlock)block;Swift
class func enableRevocableSessionInBackground() async throwsParameters
blockBlock that will be called when revocable sessions are enabled and currentUser token is migrated.
-
Asynchronously logs out the currently logged in user.
This will also remove the session from disk, log out of linked services and all future calls to
+currentUserwill returnnil. This is preferrable to using-logOut, unless your code is already running from a background thread.Declaration
Objective-C
+ (id)logOutInBackground;Swift
class func logOutInBackground() -> Any!Return Value
An instance of
BFTask, that is resolved withnilresult when logging out completes. -
Asynchronously logs out the currently logged in user.
This will also remove the session from disk, log out of linked services and all future calls to
+currentUserwill returnnil. This is preferrable to using-logOut, unless your code is already running from a background thread.Declaration
Objective-C
+ (void)logOutInBackgroundWithBlock:(nullable PFUserLogoutResultBlock)block;Swift
class func logOutInBackground() async throwsParameters
blockA block that will be called when logging out completes or fails.
-
Send a password reset request asynchronously for a specified email and sets an error object. If a user account exists with that email, an email will be sent to that address with instructions on how to reset their password.
Declaration
Objective-C
+ (id)requestPasswordResetForEmailInBackground:(nonnull NSString *)email;Swift
class func requestPasswordResetForEmail(inBackground email: String) -> Any!Parameters
emailEmail of the account to send a reset password request.
Return Value
The task, that encapsulates the work being done.
-
Send a password reset request asynchronously for a specified email.
If a user account exists with that email, an email will be sent to that address with instructions on how to reset their password.
Declaration
Objective-C
+ (void)requestPasswordResetForEmailInBackground:(nonnull NSString *)email block:(nullable PFBooleanResultBlock) block;Swift
class func requestPasswordResetForEmail(inBackground email: String, block: PFBooleanResultBlock? = nil)Parameters
emailEmail of the account to send a reset password request.
blockThe block to execute. It should have the following argument signature:
^(BOOL succeeded, NSError *error).
-
Registers a third party authentication delegate. If a delegate is already registered for the authType then it is replaced by the new delegate.
Note
This method shouldn’t be invoked directly unless developing a third party authentication library.See
PFUserAuthenticationDelegate
Declaration
Objective-C
+ (void)registerAuthenticationDelegate: (nonnull id<PFUserAuthenticationDelegate>)delegate forAuthType:(nonnull NSString *)authType;Swift
class func register(_ delegate: any PFUserAuthenticationDelegate, forAuthType authType: String)Parameters
delegateThe third party authenticaiton delegate to be registered.
authTypeThe name of the type of third party authentication source.
-
Unregisters a third party authentication delegate. If no delegate is registered, this fails gracefully.
Note
This method shouldn’t be invoked directly unless developing a third party authentication library.See
PFUserAuthenticationDelegate
Declaration
Objective-C
+ (void)unregisterAuthenticationDelegateForAuthType: (nonnull NSString *)authType;Swift
class func unregisterAuthenticationDelegate(forAuthType authType: String)Parameters
authTypeThe name of the type of third party authentication source.
-
Logs in a user with third party authentication credentials.
Note
This method shouldn’t be invoked directly unless developing a third party authentication library.See
PFUserAuthenticationDelegate
Declaration
Objective-C
+ (id)logInWithAuthTypeInBackground:(nonnull NSString *)authType authData: (nonnull NSDictionary<NSString *, NSString *> *) authData;Swift
class func logInWithAuthType(inBackground authType: String, authData: [String : String]) -> Any!Parameters
authTypeThe name of the type of third party authentication source.
authDataThe user credentials of the third party authentication source.
Return Value
A
BFTaskthat is resolved toPFUserwhen logging in completes. -
Links this user to a third party authentication library.
Note
This method shouldn’t be invoked directly unless developing a third party authentication library.See
PFUserAuthenticationDelegate
Declaration
Objective-C
- (id)linkWithAuthTypeInBackground:(nonnull NSString *)authType authData: (nonnull NSDictionary<NSString *, NSString *> *) authData;Swift
func linkWithAuthType(inBackground authType: String, authData: [String : String]) -> Any!Parameters
authTypeThe name of the type of third party authentication source.
authDataThe user credentials of the third party authentication source.
Return Value
A
BFTaskthat is resolved to@YESif linking succeeds. -
Unlinks this user from a third party authentication library.
Note
This method shouldn’t be invoked directly unless developing a third party authentication library.See
PFUserAuthenticationDelegate
Declaration
Objective-C
- (id)unlinkWithAuthTypeInBackground:(nonnull NSString *)authType;Swift
func unlinkWithAuthType(inBackground authType: String) -> Any!Parameters
authTypeThe name of the type of third party authentication source.
Return Value
A
BFTaskthat is resolved to@YESif unlinking succeeds. -
Indicates whether this user is linked with a third party authentication library of a specific type.
Note
This method shouldn’t be invoked directly unless developing a third party authentication library.See
PFUserAuthenticationDelegate
Declaration
Objective-C
- (BOOL)isLinkedWithAuthType:(nonnull NSString *)authType;Swift
func isLinked(withAuthType authType: String) -> BoolParameters
authTypeThe name of the type of third party authentication source.
Return Value
YESif the user is linked with a provider, otherwiseNO.
-
Deprecated
Please use
PFUser.-signUpInBackgroundWithBlock:instead.Signs up the user asynchronously.
This will also enforce that the username isn’t already taken.
Warning
Make sure that password and username are set before calling this method.
@deprecated Please use
PFUser.-signUpInBackgroundWithBlock:instead.Declaration
Objective-C
- (void)signUpInBackgroundWithTarget:(nullable id)target selector:(nullable SEL)selector;Swift
func signUpInBackground(withTarget target: Any?, selector: Selector?)Parameters
targetTarget object for the selector.
selectorThe selector that will be called when the asynchrounous request is complete. It should have the following signature:
(void)callbackWithResult:(NSNumber *)result error:(NSError *)error.errorwill benilon success and set if there was an error.[result boolValue]will tell you whether the call succeeded or not.
-
Deprecated
Please use
PFUser.+logInWithUsernameInBackground:password:block:instead.Makes an asynchronous request to login a user with specified credentials.
Returns an instance of the successfully logged in
PFUser. This also caches the user locally so that calls to+currentUserwill use the latest logged in user.@deprecated Please use
PFUser.+logInWithUsernameInBackground:password:block:instead.Declaration
Objective-C
+ (void)logInWithUsernameInBackground:(nonnull NSString *)username password:(nonnull NSString *)password target:(nullable id)target selector:(nullable SEL)selector;Swift
class func logInWithUsername(inBackground username: String, password: String, target: Any?, selector: Selector?)Parameters
usernameThe username of the user.
passwordThe password of the user.
targetTarget object for the selector.
selectorThe selector that will be called when the asynchrounous request is complete. It should have the following signature:
(void)callbackWithUser:(PFUser *)user error:(NSError *)error.
-
Deprecated
Please use
PFUser.+becomeInBackground:block:instead.Makes an asynchronous request to become a user with the given session token.
Returns an instance of the successfully logged in
PFUser. This also caches the user locally so that calls to+currentUserwill use the latest logged in user.@deprecated Please use
PFUser.+becomeInBackground:block:instead.Declaration
Objective-C
+ (void)becomeInBackground:(nonnull NSString *)sessionToken target:(nullable id)target selector:(nullable SEL)selector;Swift
class func become(inBackground sessionToken: String, target: Any?, selector: Selector?)Parameters
sessionTokenThe session token for the user.
targetTarget object for the selector.
selectorThe selector that will be called when the asynchrounous request is complete. It should have the following signature:
(void)callbackWithUser:(PFUser *)user error:(NSError *)error.
-
Deprecated
Please use
PFUser.+requestPasswordResetForEmailInBackground:block:instead.Send a password reset request asynchronously for a specified email and sets an error object.
If a user account exists with that email, an email will be sent to that address with instructions on how to reset their password.
@deprecated Please use
PFUser.+requestPasswordResetForEmailInBackground:block:instead.Declaration
Objective-C
+ (void)requestPasswordResetForEmailInBackground:(nonnull NSString *)email target:(nullable id)target selector:(nullable SEL)selector;Swift
class func requestPasswordResetForEmail(inBackground email: String, target: Any?, selector: Selector?)Parameters
emailEmail of the account to send a reset password request.
targetTarget object for the selector.
selectorThe selector that will be called when the asynchronous request is complete. It should have the following signature:
(void)callbackWithResult:(NSNumber *)result error:(NSError *)error.errorwill benilon success and set if there was an error.[result boolValue]will tell you whether the call succeeded or not.
-
Signs up the user synchronously.
This will also enforce that the username isn’t already taken.
Warning
Make sure that password and username are set before calling this method.
Declaration
Objective-C
- (BOOL)signUp;Return Value
Returns
YESif the sign up was successful, otherwiseNO. -
Signs up the user synchronously.
This will also enforce that the username isn’t already taken.
Warning
Make sure that password and username are set before calling this method.
Declaration
Objective-C
- (BOOL)signUp:(NSError *_Nullable *_Nullable)error;Swift
func signUp() throwsParameters
errorError object to set on error.
Return Value
Returns whether the sign up was successful.
-
Makes a synchronous request to login a user with specified credentials.
Returns an instance of the successfully logged in
PFUser. This also caches the user locally so that calls to+currentUserwill use the latest logged in user.Declaration
Objective-C
+ (nullable instancetype)logInWithUsername:(nonnull NSString *)username password:(nonnull NSString *)password;Parameters
usernameThe username of the user.
passwordThe password of the user.
Return Value
Returns an instance of the
PFUseron success. If login failed for either wrong password or wrong username, returnsnil. -
Makes a synchronous request to login a user with specified credentials.
Returns an instance of the successfully logged in
PFUser. This also caches the user locally so that calls to+currentUserwill use the latest logged in user.Declaration
Objective-C
+ (nullable instancetype)logInWithUsername:(nonnull NSString *)username password:(nonnull NSString *)password error:(NSError *_Nullable *_Nullable)error;Swift
class func logIn(withUsername username: String, password: String) throws -> SelfParameters
usernameThe username of the user.
passwordThe password of the user.
errorThe error object to set on error.
Return Value
Returns an instance of the
PFUseron success. If login failed for either wrong password or wrong username, returnsnil.
-
Makes a synchronous request to become a user with the given session token.
Returns an instance of the successfully logged in
PFUser. This also caches the user locally so that calls to+currentUserwill use the latest logged in user.Declaration
Objective-C
+ (nullable instancetype)become:(nonnull NSString *)sessionToken;Parameters
sessionTokenThe session token for the user.
Return Value
Returns an instance of the
PFUseron success. If becoming a user fails due to incorrect token, it returnsnil. -
Makes a synchronous request to become a user with the given session token.
Returns an instance of the successfully logged in
PFUser. This will also cache the user locally so that calls to+currentUserwill use the latest logged in user.Declaration
Objective-C
+ (nullable instancetype)become:(nonnull NSString *)sessionToken error:(NSError *_Nullable *_Nullable)error;Swift
class func become(_ sessionToken: String) throws -> SelfParameters
sessionTokenThe session token for the user.
errorThe error object to set on error.
Return Value
Returns an instance of the
PFUseron success. If becoming a user fails due to incorrect token, it returnsnil.
-
Synchronously* logs out the currently logged in user on disk.
Declaration
Objective-C
+ (void)logOut;Swift
class func logOut()
-
Synchronously Send a password reset request for a specified email.
If a user account exists with that email, an email will be sent to that address with instructions on how to reset their password.
Declaration
Objective-C
+ (BOOL)requestPasswordResetForEmail:(nonnull NSString *)email;Parameters
emailEmail of the account to send a reset password request.
Return Value
Returns
YESif the reset email request is successful.NO- if no account was found for the email address. -
Synchronously send a password reset request for a specified email and sets an error object.
If a user account exists with that email, an email will be sent to that address with instructions on how to reset their password.
Declaration
Objective-C
+ (BOOL)requestPasswordResetForEmail:(nonnull NSString *)email error:(NSError *_Nullable *_Nullable)error;Swift
class func requestPasswordReset(forEmail email: String) throwsParameters
emailEmail of the account to send a reset password request.
errorError object to set on error.
Return Value
Returns
YESif the reset email request is successful.NO- if no account was found for the email address.
View on GitHub
Install in Dash