objc2_game_kit/generated/
GKLeaderboard.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-app-kit")]
7#[cfg(target_os = "macos")]
8use objc2_app_kit::*;
9use objc2_foundation::*;
10
11use crate::*;
12
13/// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkleaderboardtimescope?language=objc)
14// NS_ENUM
15#[repr(transparent)]
16#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
17pub struct GKLeaderboardTimeScope(pub NSInteger);
18impl GKLeaderboardTimeScope {
19    #[doc(alias = "GKLeaderboardTimeScopeToday")]
20    pub const Today: Self = Self(0);
21    #[doc(alias = "GKLeaderboardTimeScopeWeek")]
22    pub const Week: Self = Self(1);
23    #[doc(alias = "GKLeaderboardTimeScopeAllTime")]
24    pub const AllTime: Self = Self(2);
25}
26
27unsafe impl Encode for GKLeaderboardTimeScope {
28    const ENCODING: Encoding = NSInteger::ENCODING;
29}
30
31unsafe impl RefEncode for GKLeaderboardTimeScope {
32    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
33}
34
35/// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkleaderboardplayerscope?language=objc)
36// NS_ENUM
37#[repr(transparent)]
38#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
39pub struct GKLeaderboardPlayerScope(pub NSInteger);
40impl GKLeaderboardPlayerScope {
41    #[doc(alias = "GKLeaderboardPlayerScopeGlobal")]
42    pub const Global: Self = Self(0);
43    #[doc(alias = "GKLeaderboardPlayerScopeFriendsOnly")]
44    pub const FriendsOnly: Self = Self(1);
45}
46
47unsafe impl Encode for GKLeaderboardPlayerScope {
48    const ENCODING: Encoding = NSInteger::ENCODING;
49}
50
51unsafe impl RefEncode for GKLeaderboardPlayerScope {
52    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
53}
54
55/// [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkleaderboardtype?language=objc)
56// NS_ENUM
57#[repr(transparent)]
58#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
59pub struct GKLeaderboardType(pub NSInteger);
60impl GKLeaderboardType {
61    #[doc(alias = "GKLeaderboardTypeClassic")]
62    pub const Classic: Self = Self(0);
63    #[doc(alias = "GKLeaderboardTypeRecurring")]
64    pub const Recurring: Self = Self(1);
65}
66
67unsafe impl Encode for GKLeaderboardType {
68    const ENCODING: Encoding = NSInteger::ENCODING;
69}
70
71unsafe impl RefEncode for GKLeaderboardType {
72    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
73}
74
75extern_class!(
76    /// GKLeaderboard represents a single instance of a leaderboard for the current game.
77    /// Leaderboards can be of the following types:
78    /// 1. Classic - Traditional, non-expiring leaderboards
79    /// 2. Recurring - Periodic timed leaderboards that follow a recurrence rule defined in App Store Connect.
80    ///
81    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamekit/gkleaderboard?language=objc)
82    #[unsafe(super(NSObject))]
83    #[derive(Debug, PartialEq, Eq, Hash)]
84    pub struct GKLeaderboard;
85);
86
87extern_conformance!(
88    unsafe impl NSObjectProtocol for GKLeaderboard {}
89);
90
91impl GKLeaderboard {
92    extern_methods!(
93        /// Localized title
94        #[unsafe(method(title))]
95        #[unsafe(method_family = none)]
96        pub unsafe fn title(&self) -> Option<Retained<NSString>>;
97
98        /// set when leaderboards have been designated a game group; set when loadLeaderboardsWithCompletionHandler has been called for leaderboards that support game groups
99        #[unsafe(method(groupIdentifier))]
100        #[unsafe(method_family = none)]
101        pub unsafe fn groupIdentifier(&self) -> Option<Retained<NSString>>;
102
103        /// Leaderboard ID defined in App Store Connect that this instance is associated with
104        #[unsafe(method(baseLeaderboardID))]
105        #[unsafe(method_family = none)]
106        pub unsafe fn baseLeaderboardID(&self) -> Retained<NSString>;
107
108        /// Type of leaderboard
109        #[unsafe(method(type))]
110        #[unsafe(method_family = none)]
111        pub unsafe fn r#type(&self) -> GKLeaderboardType;
112
113        /// Date and time this instance started accepting score submissions (only applicable to recurring leaderboards)
114        #[unsafe(method(startDate))]
115        #[unsafe(method_family = none)]
116        pub unsafe fn startDate(&self) -> Option<Retained<NSDate>>;
117
118        /// Date and time the next instance will start accepting score submissions (only applicable to recurring leaderboards)
119        #[unsafe(method(nextStartDate))]
120        #[unsafe(method_family = none)]
121        pub unsafe fn nextStartDate(&self) -> Option<Retained<NSDate>>;
122
123        /// Duration from startDate during which this leaderboard instance accepts score submissions (only applicable to recurring leaderboards)
124        #[unsafe(method(duration))]
125        #[unsafe(method_family = none)]
126        pub unsafe fn duration(&self) -> NSTimeInterval;
127
128        /// The description of this Leaderboard as configured by the developer in App Store Connect.
129        #[unsafe(method(leaderboardDescription))]
130        #[unsafe(method_family = none)]
131        pub unsafe fn leaderboardDescription(&self) -> Retained<NSString>;
132
133        #[cfg(feature = "GKReleaseState")]
134        /// The release state of the leaderboard in App Store Connect.
135        #[unsafe(method(releaseState))]
136        #[unsafe(method_family = none)]
137        pub unsafe fn releaseState(&self) -> GKReleaseState;
138
139        /// The identifier of the game activity associated with this leaderboard, as configured by the developer in App Store Connect.
140        #[unsafe(method(activityIdentifier))]
141        #[unsafe(method_family = none)]
142        pub unsafe fn activityIdentifier(&self) -> Retained<NSString>;
143
144        /// The properties when associating this leaderboard with a game activity, as configured by the developer in App Store Connect.
145        #[unsafe(method(activityProperties))]
146        #[unsafe(method_family = none)]
147        pub unsafe fn activityProperties(&self) -> Retained<NSDictionary<NSString, NSString>>;
148
149        /// A Boolean value that indicates whether the current leaderboard isn't visible in Game Center views.
150        ///
151        /// You can still submit scores to a hidden leaderboard.
152        #[unsafe(method(isHidden))]
153        #[unsafe(method_family = none)]
154        pub unsafe fn isHidden(&self) -> bool;
155
156        #[cfg(feature = "block2")]
157        /// Loads classic and recurring leaderboards associated with the supplied App Store Connect leaderboard IDs.
158        /// If leaderboardIDs is nil, this loads all classic and recurring leaderboards for this game.
159        #[unsafe(method(loadLeaderboardsWithIDs:completionHandler:))]
160        #[unsafe(method_family = none)]
161        pub unsafe fn loadLeaderboardsWithIDs_completionHandler(
162            leaderboard_i_ds: Option<&NSArray<NSString>>,
163            completion_handler: &block2::DynBlock<
164                dyn Fn(*mut NSArray<GKLeaderboard>, *mut NSError),
165            >,
166        );
167
168        #[cfg(feature = "block2")]
169        /// Loads the occurrence preceding this occurrence for a recurring leaderboard in which the local player submitted a score. If no previous occurrence is found that the player submitted a score to, then the most recent previous occurrence is returned.
170        #[unsafe(method(loadPreviousOccurrenceWithCompletionHandler:))]
171        #[unsafe(method_family = none)]
172        pub unsafe fn loadPreviousOccurrenceWithCompletionHandler(
173            &self,
174            completion_handler: &block2::DynBlock<dyn Fn(*mut GKLeaderboard, *mut NSError)>,
175        );
176
177        #[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer", feature = "block2"))]
178        /// Class method to submit a single score to multiple leaderboards
179        /// score - earned by the player
180        /// context - developer supplied metadata associated with the player's score
181        /// player - the player for whom this score is being submitted
182        /// leaderboardIDs - one or more leaderboard IDs defined in App Store Connect
183        #[unsafe(method(submitScore:context:player:leaderboardIDs:completionHandler:))]
184        #[unsafe(method_family = none)]
185        pub unsafe fn submitScore_context_player_leaderboardIDs_completionHandler(
186            score: NSInteger,
187            context: NSUInteger,
188            player: &GKPlayer,
189            leaderboard_i_ds: &NSArray<NSString>,
190            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
191        );
192
193        #[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer", feature = "block2"))]
194        /// Instance method to submit a single score to the leaderboard associated with this instance
195        /// score - earned by the player
196        /// context - developer supplied metadata associated with the player's score
197        /// player - the player for whom this score is being submitted
198        #[unsafe(method(submitScore:context:player:completionHandler:))]
199        #[unsafe(method_family = none)]
200        pub unsafe fn submitScore_context_player_completionHandler(
201            &self,
202            score: NSInteger,
203            context: NSUInteger,
204            player: &GKPlayer,
205            completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
206        );
207
208        #[cfg(all(feature = "GKLeaderboardEntry", feature = "block2"))]
209        /// Loads leaderboard entries based on the supplied parameters.
210        /// playerScope - Friends or Global
211        /// timeScope - Today, Week, All Time (Only applicable to classic leaderboards)
212        /// range - Range of ranked entries to return (minimum start index 1, maximum length 100)
213        /// Upon completion, will return:
214        /// localPlayerEntry - entry for the local player
215        /// entries - requested entries matching supplied parameters
216        /// totalPlayerCount - total player count matching specified scope
217        #[unsafe(method(loadEntriesForPlayerScope:timeScope:range:completionHandler:))]
218        #[unsafe(method_family = none)]
219        pub unsafe fn loadEntriesForPlayerScope_timeScope_range_completionHandler(
220            &self,
221            player_scope: GKLeaderboardPlayerScope,
222            time_scope: GKLeaderboardTimeScope,
223            range: NSRange,
224            completion_handler: &block2::DynBlock<
225                dyn Fn(
226                    *mut GKLeaderboardEntry,
227                    *mut NSArray<GKLeaderboardEntry>,
228                    NSInteger,
229                    *mut NSError,
230                ),
231            >,
232        );
233
234        #[cfg(all(
235            feature = "GKBasePlayer",
236            feature = "GKLeaderboardEntry",
237            feature = "GKPlayer",
238            feature = "block2"
239        ))]
240        /// Loads leaderboard entries for specific players based on the supplied parameters.
241        /// players - Array of players to load entries for
242        /// timeScope - Today, Week, All Time (Only applicable to classic leaderboards)
243        /// Upon completion, will return:
244        /// localPlayerEntry - entry for the local player
245        /// entries - requested entries matching supplied parameters
246        #[unsafe(method(loadEntriesForPlayers:timeScope:completionHandler:))]
247        #[unsafe(method_family = none)]
248        pub unsafe fn loadEntriesForPlayers_timeScope_completionHandler(
249            &self,
250            players: &NSArray<GKPlayer>,
251            time_scope: GKLeaderboardTimeScope,
252            completion_handler: &block2::DynBlock<
253                dyn Fn(*mut GKLeaderboardEntry, *mut NSArray<GKLeaderboardEntry>, *mut NSError),
254            >,
255        );
256    );
257}
258
259/// Deprecated.
260impl GKLeaderboard {
261    extern_methods!(
262        #[deprecated]
263        #[unsafe(method(category))]
264        #[unsafe(method_family = none)]
265        pub unsafe fn category(&self) -> Option<Retained<NSString>>;
266
267        /// Setter for [`category`][Self::category].
268        ///
269        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
270        #[deprecated]
271        #[unsafe(method(setCategory:))]
272        #[unsafe(method_family = none)]
273        pub unsafe fn setCategory(&self, category: Option<&NSString>);
274
275        #[deprecated]
276        #[unsafe(method(initWithPlayerIDs:))]
277        #[unsafe(method_family = init)]
278        pub unsafe fn initWithPlayerIDs(
279            this: Allocated<Self>,
280            player_i_ds: Option<&NSArray<NSString>>,
281        ) -> Option<Retained<Self>>;
282
283        #[cfg(feature = "block2")]
284        #[deprecated]
285        #[unsafe(method(loadCategoriesWithCompletionHandler:))]
286        #[unsafe(method_family = none)]
287        pub unsafe fn loadCategoriesWithCompletionHandler(
288            completion_handler: Option<
289                &block2::DynBlock<
290                    dyn Fn(*mut NSArray<NSString>, *mut NSArray<NSString>, *mut NSError),
291                >,
292            >,
293        );
294
295        #[cfg(feature = "block2")]
296        #[deprecated]
297        #[unsafe(method(setDefaultLeaderboard:withCompletionHandler:))]
298        #[unsafe(method_family = none)]
299        pub unsafe fn setDefaultLeaderboard_withCompletionHandler(
300            leaderboard_identifier: Option<&NSString>,
301            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
302        );
303
304        #[deprecated]
305        #[unsafe(method(timeScope))]
306        #[unsafe(method_family = none)]
307        pub unsafe fn timeScope(&self) -> GKLeaderboardTimeScope;
308
309        /// Setter for [`timeScope`][Self::timeScope].
310        #[deprecated]
311        #[unsafe(method(setTimeScope:))]
312        #[unsafe(method_family = none)]
313        pub unsafe fn setTimeScope(&self, time_scope: GKLeaderboardTimeScope);
314
315        /// Filter on friends. Does not apply to leaderboard initialized with players.
316        #[deprecated]
317        #[unsafe(method(playerScope))]
318        #[unsafe(method_family = none)]
319        pub unsafe fn playerScope(&self) -> GKLeaderboardPlayerScope;
320
321        /// Setter for [`playerScope`][Self::playerScope].
322        #[deprecated]
323        #[unsafe(method(setPlayerScope:))]
324        #[unsafe(method_family = none)]
325        pub unsafe fn setPlayerScope(&self, player_scope: GKLeaderboardPlayerScope);
326
327        /// leaderboardID. If nil, fetch the aggregate leaderboard.
328        #[deprecated]
329        #[unsafe(method(identifier))]
330        #[unsafe(method_family = none)]
331        pub unsafe fn identifier(&self) -> Option<Retained<NSString>>;
332
333        /// Setter for [`identifier`][Self::identifier].
334        ///
335        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
336        #[deprecated]
337        #[unsafe(method(setIdentifier:))]
338        #[unsafe(method_family = none)]
339        pub unsafe fn setIdentifier(&self, identifier: Option<&NSString>);
340
341        /// Leaderboards start at index 1 and the length should be less than 100. Does not apply to leaderboards initialized with players.  Exception will be thrown if developer tries to set an invalid range.
342        #[deprecated]
343        #[unsafe(method(range))]
344        #[unsafe(method_family = none)]
345        pub unsafe fn range(&self) -> NSRange;
346
347        /// Setter for [`range`][Self::range].
348        #[deprecated]
349        #[unsafe(method(setRange:))]
350        #[unsafe(method_family = none)]
351        pub unsafe fn setRange(&self, range: NSRange);
352
353        #[cfg(feature = "GKScore")]
354        /// Scores are not valid until loadScores: has completed.
355        #[deprecated]
356        #[unsafe(method(scores))]
357        #[unsafe(method_family = none)]
358        pub unsafe fn scores(&self) -> Option<Retained<NSArray<GKScore>>>;
359
360        /// The maxRange which represents the size of the leaderboard is not valid until loadScores: has completed.
361        #[deprecated]
362        #[unsafe(method(maxRange))]
363        #[unsafe(method_family = none)]
364        pub unsafe fn maxRange(&self) -> NSUInteger;
365
366        #[cfg(feature = "GKScore")]
367        /// The local player's score
368        #[deprecated]
369        #[unsafe(method(localPlayerScore))]
370        #[unsafe(method_family = none)]
371        pub unsafe fn localPlayerScore(&self) -> Option<Retained<GKScore>>;
372
373        /// This property is true if the leaderboard is currently loading
374        #[deprecated]
375        #[unsafe(method(isLoading))]
376        #[unsafe(method_family = none)]
377        pub unsafe fn isLoading(&self) -> bool;
378
379        #[cfg(all(feature = "GKBasePlayer", feature = "GKPlayer"))]
380        /// Specify an array of GKPlayers. For example, the players who are in a match together
381        /// Defaults to AllTime score, if you want to change the timeScope, set the property before loading the scores. Range and playerScope are not applicable. players may not be nil.
382        #[deprecated]
383        #[unsafe(method(initWithPlayers:))]
384        #[unsafe(method_family = init)]
385        pub unsafe fn initWithPlayers(
386            this: Allocated<Self>,
387            players: &NSArray<GKPlayer>,
388        ) -> Retained<Self>;
389
390        #[cfg(all(feature = "GKScore", feature = "block2"))]
391        /// Load the scores for this leader board asynchronously. Error will be nil on success.
392        /// Possible reasons for error:
393        /// 1. Communications problem
394        /// 2. Unauthenticated player
395        #[deprecated]
396        #[unsafe(method(loadScoresWithCompletionHandler:))]
397        #[unsafe(method_family = none)]
398        pub unsafe fn loadScoresWithCompletionHandler(
399            &self,
400            completion_handler: Option<
401                &block2::DynBlock<dyn Fn(*mut NSArray<GKScore>, *mut NSError)>,
402            >,
403        );
404
405        #[cfg(feature = "block2")]
406        /// Loads the array of GKLeaderboard for your app
407        /// Possible reasons for error:
408        /// 1. Communications problem
409        /// 2. Unauthenticated player
410        /// 3. Leaderboard not present
411        #[deprecated]
412        #[unsafe(method(loadLeaderboardsWithCompletionHandler:))]
413        #[unsafe(method_family = none)]
414        pub unsafe fn loadLeaderboardsWithCompletionHandler(
415            completion_handler: Option<
416                &block2::DynBlock<dyn Fn(*mut NSArray<GKLeaderboard>, *mut NSError)>,
417            >,
418        );
419    );
420}
421
422/// UI.
423impl GKLeaderboard {
424    extern_methods!(
425        #[cfg(all(feature = "block2", feature = "objc2-app-kit"))]
426        #[cfg(target_os = "macos")]
427        /// Asynchronously load the image. Error will be nil on success.
428        #[unsafe(method(loadImageWithCompletionHandler:))]
429        #[unsafe(method_family = none)]
430        pub unsafe fn loadImageWithCompletionHandler(
431            &self,
432            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut NSImage, *mut NSError)>>,
433        );
434    );
435}