开发者

NSTableView available for osx 10.0 but NsTableViewDataSource available for only 10.6?

开发者 https://www.devze.com 2022-12-18 02:27 出处:网络
I was looking at the docs for NSTableViewDataSource and they say that this protocol is only availab开发者_如何学运维le on osx 10.6.How can this be?Isn\'t NSTableViewDataSource the object that contains

I was looking at the docs for NSTableViewDataSource and they say that this protocol is only availab开发者_如何学运维le on osx 10.6. How can this be? Isn't NSTableViewDataSource the object that contains all the data for your NsTableView?


To add what @Zydeco wrote, @protocols in Objective-C didn't have @optional attributes before 10.5. So, Apple couldn't use @protocol to define what are the delegate methods, because the delegate objects choose to implement only a part of delegate methods. Apple used something called an informal protocol in those olden days, which were just NSObject categories.

Now that they introduced the way to mark some methods as @optional in a @protocol, they decided to make every delegate a formal protocol in 10.6. This way there can be more compile-time checking. But the functionality has not changed.

See the official documentation on the protocols for more info.


NSTableViewDataSource exists in 10.6 as a formal protocol, in older versions, the methods in NSTableViewDataSource are just delegate methods, but it works the same way: you implement the methods in your data source object.


In 10.6, Apple formalized many delegate and data source informal protocols. Thus an informal protocol like

@interface NSObject (MyViewDataSource)

// data source methods

@end

became

@protocol MyViewDataSource
//data source methods
@end

The advantage is that the compiler can do some compile-time checking to warn you if you pass a non-conformant instance (i.e. doesn't implement NSTableViewDataSource as the data source to, e.g. an NSTableView and can warn you if you don't implement all the required methods of the protocol after declaring that a class implements the protocol in its @interface.

The @protocol(NSTableViewDataSource) doesn't exist prior to 10.6, so you'll have to declare it if you want to compile with the SDK for previous versions. You can do so and pass your data source object (which now implements a dummy protocol) as the data source in previous SDKs since it necessarily also conforms to the informal protocol defined in those previous versions.

0

精彩评论

暂无评论...
验证码 换一张
取 消