ios - 关于swift中源码的一点疑问
PHP中文网
PHP中文网 2017-04-17 17:34:44
0
1
446

我在查看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中文网

认证0级讲师

reply all(1)
巴扎黑

I think what you see is like the header file in obj c before. It is just an interface definition, just like a document, not an actual class.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template