在XCode 6中,使用Swift;让我们假设我正在创建某个对象的实例:
let sessionConfiguration = NSURLSessionConfiguration()有没有办法告诉XCode 6代码完成只包括实际定义在NSURLSessionConfiguration类或超类上的方法/属性?
使用上面定义的对象,XCode代码完成建议我使用如下方法:
sessionConfiguration.accessibilityActionDescription(action: String)
sessionConfiguration.animationDidStart(anim: CAAnimation!)但我看不出这些方法与这个类相关。
在专注于代码安全的新Swift编程范式中,这似乎是一种奇怪的行为。
发布于 2015-05-23 08:11:09
extension NSObject {
/* Called when the animation begins its active duration. */
func animationDidStart(anim: CAAnimation!)
/* Called when the animation either completes its active duration or
* is removed from the object it is attached to (i.e. the layer). 'flag'
* is true if the animation reached the end of its active duration
* without being removed. */
func animationDidStop(anim: CAAnimation!, finished flag: Bool)
}
extension NSObject {
/*
Implement accessibilityActivate on an element in order to handle the default action.
For example, if a native control requires a swipe gesture, you may implement this method so that a
VoiceOver user will perform a double-tap to activate the item.
If your implementation successfully handles activate, return YES, otherwise return NO.
default == NO
*/
@availability(iOS, introduced=7.0)
func accessibilityActivate() -> Bool
...}这两种方法分别是在UIAccessibility和CAAnimation中对NSObject声明的扩展。
发布于 2015-05-23 15:37:40
基于博茂园的回答。我原来问题的答案是:
不是的。
XCode自动完成显示类层次结构中的每个方法。有些方法是通过继承添加到类中的,有些是通过扩展添加到类中的。
https://stackoverflow.com/questions/30410272
复制相似问题