#[repr(C)]pub struct GKScore { /* private fields */ }
GKScore
only.Expand description
GKScore represents a score in the leaderboards.
See also Apple’s documentation
Implementations§
Source§impl GKScore
GKChallenge.
Use the following category methods to issue GKScoreChallenges and GKAchievementChallenges to an array of playerIDs. Players may not issue challenges to themselves nor to non-friends. Please see the GameKit reference documentation for further details on these methods.
impl GKScore
GKChallenge. Use the following category methods to issue GKScoreChallenges and GKAchievementChallenges to an array of playerIDs. Players may not issue challenges to themselves nor to non-friends. Please see the GameKit reference documentation for further details on these methods.
Sourcepub unsafe fn reportScores_withEligibleChallenges_withCompletionHandler(
scores: &NSArray<GKScore>,
challenges: &NSArray<GKChallenge>,
completion_handler: Option<&DynBlock<dyn Fn(*mut NSError)>>,
)
👎DeprecatedAvailable on crate features GKChallenge
and block2
only.
pub unsafe fn reportScores_withEligibleChallenges_withCompletionHandler( scores: &NSArray<GKScore>, challenges: &NSArray<GKChallenge>, completion_handler: Option<&DynBlock<dyn Fn(*mut NSError)>>, )
GKChallenge
and block2
only.Use this alternative to reportScores:withCompletionHandler: to allow only certain specific challenges to be completed. Pass nil to avoid completing any challenges.
pub unsafe fn reportLeaderboardScores_withEligibleChallenges_withCompletionHandler( scores: &NSArray<GKLeaderboardScore>, challenges: &NSArray<GKChallenge>, completion_handler: Option<&DynBlock<dyn Fn(*mut NSError)>>, )
GKChallenge
and GKLeaderboardScore
and block2
only.Source§impl GKScore
GKChallengeUI.
impl GKScore
GKChallengeUI.
pub unsafe fn challengeComposeControllerWithMessage_players_completionHandler( &self, message: Option<&NSString>, players: Option<&NSArray<GKPlayer>>, completion_handler: GKChallengeComposeCompletionBlock, mtm: MainThreadMarker, ) -> Retained<NSViewController>
GKChallenge
and crate feature GKBasePlayer
and crate feature GKPlayer
and crate feature block2
and crate feature objc2-app-kit
and macOS only.pub unsafe fn challengeComposeControllerWithMessage_players_completion( &self, message: Option<&NSString>, players: Option<&NSArray<GKPlayer>>, completion_handler: GKChallengeComposeHandler, mtm: MainThreadMarker, ) -> Retained<NSViewController>
GKChallenge
and crate feature GKBasePlayer
and crate feature GKPlayer
and crate feature block2
and crate feature objc2-app-kit
and macOS only.Source§impl GKScore
GKChallengeObsoletedUI.
impl GKScore
GKChallengeObsoletedUI.
Sourcepub unsafe fn challengeComposeControllerWithPlayers_message_completionHandler(
&self,
player_i_ds: Option<&NSArray<NSString>>,
message: Option<&NSString>,
completion_handler: GKChallengeComposeCompletionBlock,
mtm: MainThreadMarker,
) -> Option<Retained<NSViewController>>
Available on crate feature GKChallenge
and crate feature block2
and crate feature objc2-app-kit
and macOS only.
pub unsafe fn challengeComposeControllerWithPlayers_message_completionHandler( &self, player_i_ds: Option<&NSArray<NSString>>, message: Option<&NSString>, completion_handler: GKChallengeComposeCompletionBlock, mtm: MainThreadMarker, ) -> Option<Retained<NSViewController>>
GKChallenge
and crate feature block2
and crate feature objc2-app-kit
and macOS only.- This method is obsolete. Calling this method does nothing and will return nil **
Source§impl GKScore
impl GKScore
Sourcepub unsafe fn initWithLeaderboardIdentifier(
this: Allocated<Self>,
identifier: &NSString,
) -> Retained<Self>
👎Deprecated
pub unsafe fn initWithLeaderboardIdentifier( this: Allocated<Self>, identifier: &NSString, ) -> Retained<Self>
Initialize the score with the local player and current date.
Sourcepub unsafe fn initWithLeaderboardIdentifier_player(
this: Allocated<Self>,
identifier: &NSString,
player: &GKPlayer,
) -> Retained<Self>
👎DeprecatedAvailable on crate features GKBasePlayer
and GKPlayer
only.
pub unsafe fn initWithLeaderboardIdentifier_player( this: Allocated<Self>, identifier: &NSString, player: &GKPlayer, ) -> Retained<Self>
GKBasePlayer
and GKPlayer
only.Initialize the achievement for a specific player. Use to submit participant scores when ending a turn-based match.
Sourcepub unsafe fn formattedValue(&self) -> Option<Retained<NSString>>
👎Deprecated
pub unsafe fn formattedValue(&self) -> Option<Retained<NSString>>
The score formatted as a string, localized with a label
Sourcepub unsafe fn leaderboardIdentifier(&self) -> Retained<NSString>
👎Deprecated
pub unsafe fn leaderboardIdentifier(&self) -> Retained<NSString>
leaderboard identifier (required)
Sourcepub unsafe fn setLeaderboardIdentifier(&self, leaderboard_identifier: &NSString)
👎Deprecated
pub unsafe fn setLeaderboardIdentifier(&self, leaderboard_identifier: &NSString)
Setter for leaderboardIdentifier
.
Sourcepub unsafe fn context(&self) -> u64
👎Deprecated
pub unsafe fn context(&self) -> u64
optional additional context that allows a game to store and retrieve additional data associated with the store. Default value of zero is returned if no value is set.
Sourcepub unsafe fn setContext(&self, context: u64)
👎Deprecated
pub unsafe fn setContext(&self, context: u64)
Setter for context
.
Sourcepub unsafe fn date(&self) -> Retained<NSDate>
👎Deprecated
pub unsafe fn date(&self) -> Retained<NSDate>
The date this score was recorded. A newly initialized, unsubmitted GKScore records the current date at init time.
Sourcepub unsafe fn player(&self) -> Retained<GKPlayer>
👎DeprecatedAvailable on crate features GKBasePlayer
and GKPlayer
only.
pub unsafe fn player(&self) -> Retained<GKPlayer>
GKBasePlayer
and GKPlayer
only.The player that recorded the score.
Sourcepub unsafe fn rank(&self) -> NSInteger
👎Deprecated
pub unsafe fn rank(&self) -> NSInteger
The rank of the player within the leaderboard, only valid when returned from GKLeaderboard
Sourcepub unsafe fn shouldSetDefaultLeaderboard(&self) -> bool
👎Deprecated
pub unsafe fn shouldSetDefaultLeaderboard(&self) -> bool
Convenience property to make the leaderboard associated with this GKScore, the default leaderboard for this player. Default value is false. If true, reporting that score will make the category this score belongs to, the default leaderboard for this user
Sourcepub unsafe fn setShouldSetDefaultLeaderboard(
&self,
should_set_default_leaderboard: bool,
)
👎Deprecated
pub unsafe fn setShouldSetDefaultLeaderboard( &self, should_set_default_leaderboard: bool, )
Setter for shouldSetDefaultLeaderboard
.
Sourcepub unsafe fn reportScores_withCompletionHandler(
scores: &NSArray<GKScore>,
completion_handler: Option<&DynBlock<dyn Fn(*mut NSError)>>,
)
👎DeprecatedAvailable on crate feature block2
only.
pub unsafe fn reportScores_withCompletionHandler( scores: &NSArray<GKScore>, completion_handler: Option<&DynBlock<dyn Fn(*mut NSError)>>, )
block2
only.Report scores to the server. The value must be set, and date may be changed. Possible reasons for error:
- Value not set
- Local player not authenticated
- Communications problem
Source§impl GKScore
Deprecated.
impl GKScore
Deprecated.
pub unsafe fn reportScoreWithCompletionHandler( &self, completion_handler: Option<&DynBlock<dyn Fn(*mut NSError)>>, )
block2
only.pub unsafe fn initWithCategory( this: Allocated<Self>, category: Option<&NSString>, ) -> Retained<Self>
pub unsafe fn category(&self) -> Option<Retained<NSString>>
Sourcepub unsafe fn setCategory(&self, category: Option<&NSString>)
👎Deprecated
pub unsafe fn setCategory(&self, category: Option<&NSString>)
Setter for category
.
Methods from Deref<Target = NSObject>§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
Sourcepub fn class(&self) -> &'static AnyClass
pub fn class(&self) -> &'static AnyClass
Dynamically find the class of this object.
§Panics
May panic if the object is invalid (which may be the case for objects
returned from unavailable init
/new
methods).
§Example
Check that an instance of NSObject
has the precise class NSObject
.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());
Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load
instead.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load
instead.Use Ivar::load
instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T
.
See Ivar::load_ptr
for details surrounding this.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
Attempt to downcast the object to a class of type T
.
This is the reference-variant. Use Retained::downcast
if you want
to convert a retained object to another type.
§Mutable classes
Some classes have immutable and mutable variants, such as NSString
and NSMutableString
.
When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.
So using this method to convert a NSString
to a NSMutableString
,
while not unsound, is generally frowned upon unless you created the
string yourself, or the API explicitly documents the string to be
mutable.
See Apple’s documentation on mutability and on
isKindOfClass:
for more details.
§Generic classes
Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.
You can, however, safely downcast to generic collections where all the
type-parameters are AnyObject
.
§Panics
This works internally by calling isKindOfClass:
. That means that the
object must have the instance method of that name, and an exception
will be thrown (if CoreFoundation is linked) or the process will abort
if that is not the case. In the vast majority of cases, you don’t need
to worry about this, since both root objects NSObject
and
NSProxy
implement this method.
§Examples
Cast an NSString
back and forth from NSObject
.
use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};
let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();
Try (and fail) to cast an NSObject
to an NSString
.
use objc2_foundation::{NSObject, NSString};
let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());
Try to cast to an array of strings.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();
This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.
Downcast when processing each element instead.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
for elem in arr {
if let Some(data) = elem.downcast_ref::<NSString>() {
// handle `data`
}
}
Trait Implementations§
Source§impl ClassType for GKScore
impl ClassType for GKScore
Source§const NAME: &'static str = "GKScore"
const NAME: &'static str = "GKScore"
Source§type ThreadKind = <<GKScore as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<GKScore as ClassType>::Super as ClassType>::ThreadKind
Source§impl NSObjectProtocol for GKScore
impl NSObjectProtocol for GKScore
Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
Source§fn hash(&self) -> usize
fn hash(&self) -> usize
Source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
isKindOfClass
directly, or cast your objects with AnyObject::downcast_ref