Arrays – Quantity of the NIL value in the Arrary of Int Optionals

I just started using Swift and using options. After using generateRandomArrayOfIntsAndNils(), I struggled to calculate the number of nils in the test array

This is what I want to use Method:

let array1: [Int?]
array1 = generateRandomArrayOfIntsAndNils()\

var total = 0

for i in array1 {
if(array1[i] == nil){
total += 1
}
}

print(total)

Any suggestions or guidance would be greatly appreciated.

you You can do this:

let countNils = array1.filter({ $0 == nil }).count

< p>I just started using Swift and using options. After using generateRandomArrayOfIntsAndNils(), I struggled to calculate the number of nils in the test array

This is the method I want to use:

let array1: [Int?]
array1 = generateRandomArrayOfIntsAndNils()\

var total = 0

for i in array1 {
if(array1[i] == nil){
total += 1
}
}

print(total)

< p>Any suggestions or guidance would be greatly appreciated.

You can do this:

 let countNils = array1.filter({ $0 == nil }).cou nt

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 442 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.