Swift SDK Version

UserProfile

publicstructUserProfile
Represents an immutable Facebook profile.
This class provides a global current instance to more easily add social context to your application. When the profile changes, a notification is posted so that you can update relevant parts of your UI and is persisted to NSUserDefaults.
Typically, you will want to call Profile.updatesOnAccessTokenChange = true, so that it automatically observes changes to the AccessToken.current.
You can use this class to build your own ProfilePictureView or in place of typical requests to /me.
  • Convenience alias for type of closure that is used as a completion for fetching UserProfile.

    Declaration

    Swift
    publictypealiasCompletion=(FetchResult)->Void
  • Fetches a user profile by userId.
    If the current profile is set, and it has the same userId, calling method will reset the current profile with the newly fetched one.

    Declaration

    Swift
    publicstaticfuncfetch(userId:String,completion:@escapingCompletion)

    Parameters

    userId
    Facebook user id of the profile to fetch.
    completion
    The closure to be executed once the profile is refreshed.
  • Refreshes the existing user profile.
    If the current profile is set, and receiver has the same userId, calling method will reset the current profile with the newly fetched one.

    Declaration

    Swift
    publicfuncrefresh(_completion:Completion?)

    Parameters

    completion
    Optional closure to be executed once the profile is refreshed. Default: nil.
  • Current instance of Profile that represents the currently logged in user’s profile.

    Declaration

    Swift
    publicstaticvarcurrent:UserProfile?{getset}
  • Loads the current profile and passes it to the completion closure.
    If the current profile is already loaded, this method will call the completion block synchronously, otherwise it will begin a graph request to update current profile and the call the completion closure when finished.

    Declaration

    Swift
    publicstaticfuncloadCurrent(_completion:Completion?)

    Parameters

    completion
    The closure to be executed once the profile is loaded.
  • Allows controlling whether current profile should automatically update when AccessToken.current changes.
    Note
    If AccessToken.current is unset (changes to nil), the current profile instance remains. It’s also possible for the current to return nil until the data is fetched.

    Declaration

    Swift
    publicstaticvarupdatesOnAccessTokenChange:Bool{getset}
  • Defines the aspect ratio for the source image of the profile picture.
    See more

    Declaration

    Swift
    publicenumPictureAspectRatio
  • Returns a complete NSURL for retrieving the user’s profile image.

    Declaration

    Swift
    publicfuncimageURLWith(_aspectRatio:PictureAspectRatio,size:CGSize)->URL

    Parameters

    aspectRatio
    Apsect ratio of the source image to use.
    size
    Requested height and width of the image. Will be rounded to integer precision.