objc2-game-kit 0.3.2

Bindings to the GameKit framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

extern_class!(
    /// Class representing a saved game for the local player, or a version of a saved game when in conflict
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamekit/gksavedgame?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct GKSavedGame;
);

extern_conformance!(
    unsafe impl NSCopying for GKSavedGame {}
);

unsafe impl CopyingHelper for GKSavedGame {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for GKSavedGame {}
);

impl GKSavedGame {
    extern_methods!(
        #[unsafe(method(name))]
        #[unsafe(method_family = none)]
        pub unsafe fn name(&self) -> Option<Retained<NSString>>;

        #[unsafe(method(deviceName))]
        #[unsafe(method_family = none)]
        pub unsafe fn deviceName(&self) -> Option<Retained<NSString>>;

        #[unsafe(method(modificationDate))]
        #[unsafe(method_family = none)]
        pub unsafe fn modificationDate(&self) -> Option<Retained<NSDate>>;

        #[cfg(feature = "block2")]
        /// Asynchronously load the data for this saved game. The completion handler is called with loaded data or an error.
        #[unsafe(method(loadDataWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn loadDataWithCompletionHandler(
            &self,
            handler: Option<&block2::DynBlock<dyn Fn(*mut NSData, *mut NSError)>>,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl GKSavedGame {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

/// GKSavedGame.
#[cfg(all(
    feature = "GKBasePlayer",
    feature = "GKLocalPlayer",
    feature = "GKPlayer"
))]
impl GKLocalPlayer {
    extern_methods!(
        #[cfg(feature = "block2")]
        /// Asynchronously fetch saved games. The handler is called with an array of GKSavedGame objects or an error.
        /// If there is more than one saved game with the same name then a conflict exists. The application should determine the correct data to use and call resolveConflictingSavedGames:withData:completionHandler:. This may require data merging or asking the user.
        #[unsafe(method(fetchSavedGamesWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn fetchSavedGamesWithCompletionHandler(
            &self,
            handler: Option<&block2::DynBlock<dyn Fn(*mut NSArray<GKSavedGame>, *mut NSError)>>,
        );

        #[cfg(feature = "block2")]
        /// Asynchronously save game data. If a saved game with that name already exists it is overwritten, otherwise a new one is created. The completion handler is called with the new / modified GKSavedGame or an error.
        /// If the saved game was in conflict then the overwritten version will be the one with the same deviceName if present, otherwise the most recent overall.
        #[unsafe(method(saveGameData:withName:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn saveGameData_withName_completionHandler(
            &self,
            data: &NSData,
            name: &NSString,
            handler: Option<&block2::DynBlock<dyn Fn(*mut GKSavedGame, *mut NSError)>>,
        );

        #[cfg(feature = "block2")]
        /// Asynchronously delete saved games with the given name. The completion handler will indicate whether or not the deletion was successful.
        #[unsafe(method(deleteSavedGamesWithName:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn deleteSavedGamesWithName_completionHandler(
            &self,
            name: &NSString,
            handler: Option<&block2::DynBlock<dyn Fn(*mut NSError)>>,
        );

        #[cfg(feature = "block2")]
        /// Asynchronously resolve a saved game conflict. This deletes all versions included in conflictingSavedGames and creates a new version with the given data. The completion handler is called with the newly created save and all other remaining versions or an error.
        #[unsafe(method(resolveConflictingSavedGames:withData:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn resolveConflictingSavedGames_withData_completionHandler(
            &self,
            conflicting_saved_games: &NSArray<GKSavedGame>,
            data: &NSData,
            handler: Option<&block2::DynBlock<dyn Fn(*mut NSArray<GKSavedGame>, *mut NSError)>>,
        );
    );
}

#[cfg(all(
    feature = "GKBasePlayer",
    feature = "GKLocalPlayer",
    feature = "GKPlayer",
    feature = "GKSavedGameListener"
))]
extern_conformance!(
    unsafe impl GKSavedGameListener for GKLocalPlayer {}
);