Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么苹果的文档只显示属性和方法签名,而不显示实际代码?_Ios_Swift_Xcode_Apple Documentation - Fatal编程技术网

Ios 为什么苹果的文档只显示属性和方法签名,而不显示实际代码?

Ios 为什么苹果的文档只显示属性和方法签名,而不显示实际代码?,ios,swift,xcode,apple-documentation,Ios,Swift,Xcode,Apple Documentation,我正在浏览苹果的文档,希望了解UIApplication之类的类是如何完成它们在引擎盖下的工作的。但是,如果您命令单击UIApplication,Xcode只显示UIApplication的属性和方法签名,而不显示方法中的实际代码。我想如果我们能看到苹果提供的类中发生了什么,这将是一个有价值的信息,但为什么我们不能知道或看到呢 例如,如果您命令单击UIApplication,将显示以下内容: public class UIApplication : UIResponder { publ

我正在浏览苹果的文档,希望了解UIApplication之类的类是如何完成它们在引擎盖下的工作的。但是,如果您命令单击UIApplication,Xcode只显示UIApplication的属性和方法签名,而不显示方法中的实际代码。我想如果我们能看到苹果提供的类中发生了什么,这将是一个有价值的信息,但为什么我们不能知道或看到呢

例如,如果您命令单击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 }
}

在本例中,为您的产品向某人提供API时,这是一种常见的做法。实现细节取决于创建者,您不需要知道内部的工作方式。您所需要知道的是允许使用其产品的工具,这些工具称为API

实现本身可以而且经常会发生变化,API的设计方式确保这些变化不会中断或破坏您的应用程序。 看到背后的代码可能会导致错误的假设和/或不良做法。更不用说它通常是专有的,并不真正为公众所用

编辑:

您不关心实现,因为您不是编写它的人。苹果创造了实现,你只需使用他们在幕后制造的任何东西


例如,以beginIgnoringInteractionEvents方法为例。你不知道当你打电话时会发生什么。你所知道的是,一旦你调用它,你将停止获得交互事件。如果只需将某些内部checkForEvents属性设置为false,或者从处理程序列表中删除处理程序,或者重新创建整个视图层次结构就可以了,那么它对您来说是完全透明的。你不必担心内部问题,你只需要知道方法/属性的作用,苹果公司有责任确保它遵守承诺,当你在行为中遇到错误时,你会偶尔感到失望,因为唯一可能回答这个问题的来源是软件制造商,即苹果,即使他们的答案是主观的。@dasblinkenlight那么人们如何知道他们是否正确使用了方法或属性呢?我的问题对你有意义吗?我只是想确保我掌握了如何正确使用Apple提供的类。当你说主观的时候,这是不是说编程更像是一门有无限答案的艺术?@dasblinkenlight任何人都可以回答这个问题,它没有任何苹果特有的或主观的东西。这是一个生成的界面,类似于Objective-C中的@interface块。苹果故意隐藏它们的实现。我不知道你在问什么。您永远不会实现自己的UIApplication类。对于UIViewController之类的类,您可以在实现中重写超类的指定方法以对类进行修改,但决不应尝试访问私有属性或通过方法swizzling等更改默认方法实现。因此,在外行术语中,我们是否可以安全地同意,只要我们在调用我们希望使用的类的方法或属性时遵守其参数和返回类型,苹果的API就可以像切饼干的类一样使用?因此,只要我们遵守参数和返回类型,我们就可以自由地创建实现?不完全是这样,请参见我的编辑以获得澄清