makeObjectsPerformSelector

makeObjectsPerformSelector

在Objective-C中,我使用以下代码删除所有 subview :

[self.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

但是如何 swift 使用它呢?我看到apple documentation swift 使用了该方法
func makeObjectsPerformSelector(_ aSelector: Selector)

但是当我尝试它时,出现错误:'AnyObject[]' does not have a member named 'makeObjectsPerformSelector'
有什么方法可以快速删除 subview ?

最佳答案

已针对Swift 2.0(Xcode 7)更新

使用forEach:

self.view.subviews.forEach { subview in
    subview.removeFromSuperview()
}

或像这样:
view.subviews.forEach { $0.removeFromSuperview() }

关于ios - makeObjectsPerformSelector的快速等效项是什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24446372/

10-10 07:12