搜尋

首頁  >  問答  >  主體

ios - 关于swift中源码的一点疑问

我在查看Xcode中查看swift的源码,遇到几个问题:
如下:UITableViewController继承了UIViewController

@available(iOS 2.0, *)
public class UITableViewController : UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    public init(style: UITableViewStyle)
    public init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?)
    public init?(coder aDecoder: NSCoder)
    
    public var tableView: UITableView!
    @available(iOS 3.2, *)
    public var clearsSelectionOnViewWillAppear: Bool // defaults to YES. If YES, any selection is cleared in viewWillAppear:
    
    @available(iOS 6.0, *)
    public var refreshControl: UIRefreshControl?
}

然后我点击到UIViewController中看了下,它也是个class类:

@available(iOS 2.0, *)
public class UIViewController : UIResponder, NSCoding, UIAppearanceContainer, UITraitEnvironment, UIContentContainer, UIFocusEnvironment {
...省略一些代码

@available(iOS 6.0, *)
    public func canPerformUnwindSegueAction(action: Selector, fromViewController: UIViewController, withSender sender: AnyObject) -> Bool

@available(iOS 9.0, *)
    public func allowedChildViewControllersForUnwindingFromSource(source: UIStoryboardUnwindSegueSource) -> [UIViewController]
...省略一些代码

里面有上面那样子没有方法体的方法声明,我理解的swift不是只有在协议中才可以定义方法,而没有方法体吗?而UIViewController是个class类,为什么里面的方法也可以没有方法体呢?

PHP中文网PHP中文网2888 天前461

全部回覆(1)我來回復

  • 巴扎黑

    巴扎黑2017-04-17 17:36:44

    我覺得你看到的就像是以前 obj c 裡的頭檔吧,只是介面定義,就像一個文件一樣,並不是實際的 class。

    回覆
    0
  • 取消回覆