-3

私は Apple のドキュメントを調査しており、UIApplication などのクラスが内部でどのように動作するかを理解したいと考えていますが、コマンドで「UIApplication」をクリックすると、Xcode は UIApplication のプロパティとメソッド シグネチャのみを表示し、メソッド内の実際のコードは表示しません。Apple が提供するクラスの内部で何が起こっているかを知ることができれば、これは貴重な情報になると思いましたが、なぜそれを知ることも見ることもできないのでしょうか?

たとえば、UIApplication をクリックした場合に表示される内容は次のとおりです。

public class UIApplication : UIResponder {

    public class func sharedApplication() -> UIApplication

    unowned(unsafe) public var delegate: UIApplicationDelegate?

    public func beginIgnoringInteractionEvents() // nested. set should be set during animations & transitions to ignore touch and other events
    public func endIgnoringInteractionEvents()
    public func isIgnoringInteractionEvents() -> Bool // returns YES if we are at least one deep in ignoring events

    public var idleTimerDisabled: Bool // default is NO

    public func openURL(url: NSURL) -> Bool
    @available(iOS 3.0, *)
    public func canOpenURL(url: NSURL) -> Bool

    public func sendEvent(event: UIEvent)

    public var keyWindow: UIWindow? { get }
    public var windows: [UIWindow] { get }

    public func sendAction(action: Selector, to target: AnyObject?, from sender: AnyObject?, forEvent event: UIEvent?) -> Bool

    public var networkActivityIndicatorVisible: Bool // showing network spinning gear in status bar. default is NO

    // default is UIStatusBarStyleDefault

    // The system only calls this method if the application delegate has not
    // implemented the delegate equivalent. It returns the orientations specified by
    // the application's info.plist. If no supported interface orientations were
    // specified it will return UIInterfaceOrientationMaskAll on an iPad and
    // UIInterfaceOrientationMaskAllButUpsideDown on a phone.  The return value
    // should be one of the UIInterfaceOrientationMask values which indicates the
    // orientations supported by this application.
    @available(iOS 6.0, *)
    public func supportedInterfaceOrientationsForWindow(window: UIWindow?) -> UIInterfaceOrientationMask

    public var statusBarOrientationAnimationDuration: NSTimeInterval { get } // Returns the animation duration for the status bar during a 90 degree orientation change.  It should be doubled for a 180 degree orientation change.
    public var statusBarFrame: CGRect { get } // returns CGRectZero if the status bar is hidden

    public var applicationIconBadgeNumber: Int // set to 0 to hide. default is 0. In iOS 8.0 and later, your application must register for user notifications using -[UIApplication registerUserNotificationSettings:] before being able to set the icon badge.

    @available(iOS 3.0, *)
    public var applicationSupportsShakeToEdit: Bool

    @available(iOS 4.0, *)
    public var applicationState: UIApplicationState { get }
    @available(iOS 4.0, *)
    public var backgroundTimeRemaining: NSTimeInterval { get }

    @available(iOS 4.0, *)
    public func beginBackgroundTaskWithExpirationHandler(handler: (() -> Void)?) -> UIBackgroundTaskIdentifier
    @available(iOS 7.0, *)
    public func beginBackgroundTaskWithName(taskName: String?, expirationHandler handler: (() -> Void)?) -> UIBackgroundTaskIdentifier
    @available(iOS 4.0, *)
    public func endBackgroundTask(identifier: UIBackgroundTaskIdentifier)

    /*! The system guarantees that it will not wake up your application for a background fetch more
        frequently than the interval provided. Set to UIApplicationBackgroundFetchIntervalMinimum to be
        woken as frequently as the system desires, or to UIApplicationBackgroundFetchIntervalNever (the
        default) to never be woken for a background fetch.

        This setter will have no effect unless your application has the "fetch" 
        UIBackgroundMode. See the UIApplicationDelegate method
        `application:performFetchWithCompletionHandler:` for more. */
    @available(iOS 7.0, *)
    public func setMinimumBackgroundFetchInterval(minimumBackgroundFetchInterval: NSTimeInterval)

    /*! When background refresh is available for an application, it may launched or resumed in the background to handle significant
        location changes, remote notifications, background fetches, etc. Observe UIApplicationBackgroundRefreshStatusDidChangeNotification to
        be notified of changes. */
    @available(iOS 7.0, *)
    public var backgroundRefreshStatus: UIBackgroundRefreshStatus { get }

    @available(iOS 4.0, *)
    public var protectedDataAvailable: Bool { get }

    @available(iOS 5.0, *)
    public var userInterfaceLayoutDirection: UIUserInterfaceLayoutDirection { get }

    // Return the size category
    @available(iOS 7.0, *)
    public var preferredContentSizeCategory: String { get }
}
4

1 に答える 1

3

これは、製品 (この場合は Apple の SDK) に API を提供する場合の一般的な方法です。実装の詳細は作成者次第であり、内部でどのように機能するかを知る必要はありません。あなたが知る必要があるのは、彼らの製品を操作できるようにするツールであり、それらのツールは API と呼ばれます。

ウィキの API

実装自体は変更される可能性があり、頻繁に変更されます。API は、これらの変更によってアプリケーションが混乱したり破損したりしないように設計されています。コードビハインドを見ると、誤った仮定や悪い習慣につながる可能性があります。言うまでもなく、それは多くの場合独占的であり、公の目を意図したものではありません.

編集

あなたはそれを書いている人ではないので、実装には関心がありません。Apple が実装を作成します。あなたは彼らが舞台裏で作成したものを使用するだけです。

たとえば、beginIgnoringInteractionEvents メソッドを見てみましょう。呼び出したときに正確に何が起こるかはわかりません。知っているのは、一度呼び出すと、相互作用イベントの取得が停止することだけです。一部の内部 checkForEvents プロパティを false に設定するだけでそれを行うか、ハンドラーのリストからハンドラーを削除するか、ビュー階層全体を再作成するかは、完全に透過的です。内部について心配する必要はありません。メソッド/プロパティが何をするかを知る必要があるだけであり、それが約束を守ることを保証するのは Apple 次第です動作のバグ)

于 2016-08-31T17:19:19.023 に答える