Wednesday, September 28, 2022
HomeiOS DevelopmentWhy I am unable to use a append() in for loop in...

Why I am unable to use a append() in for loop in Swift? [closed]


I wished to append a [Int] array within the checklist array.

I might used the insert() however append() was not working with error message that " No actual matches in name to occasion technique ‘append’ ".

I researched a motive for this example, however I could not discover it…

    var checklist = [[Int]]()
    // It is working
    for _ in 0..<N {
        checklist.insert(readLine()!.cut up(separator: " ").map{ Int(String($0))! }, at: checklist.endIndex)
    }

    // It isn't working
    for _ in 0..<N {
        checklist.append(contentsOf: readLine()!.cut up(separator: " ").map{ Int(String($0))! })
    }

Please let me know why. Thanks

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments