Last updated 3 years ago
Was this helpful?
โ break : not allowed.
โ continue : not allowed.
โ return : exit only from the current call to body.
// `seq.forEach(_:)` declaration: func forEach( _ body: (Self.Element) throws -> Void ) rethrows
// sequence.forEach() (1...10).forEach { n in print(n) // โญ๏ธ return from this closure, not from the `forEach` method if n > 2 { return } } // 1, 2, ..., 10
class ArticleGroupViewController: UIViewController { private let articles: [Article] override func viewDidLoad() { super.viewDidLoad() // โญ๏ธ ็ดๆฅๅฐ method ๆพๅ ฅ forEach()๏ผๅฏๅขๅ ็จๅผ็ๅฏ่ฎๆงใ articles.forEach(addArticleView) } private func addArticleView(for article: Article) { let articleView = ArticleView() view.addSubview(articleView) } }
Advanced Swift, p.
โฉ for...in โญ๏ธ
Collections โฉ โฉ
Flow Control โฉ - iterate over a sequence (array, range, string, dictionary)
Sundell โฉ