0

Output of array looks like [[3, 1], [2, 1], [3, 1], [4, 1], [6, 1]] I want particular values 3 and 1 for indexpath.row 1 and so on.

var weekdays = [Int]()
weekdays.append(daysArr)  

 Attempt 1
 for i in weekdays  {
      for j in i
      } 
}

On this line - for j in i I get error like "Type any" does not confirm to protocol 'Sequence'

I tried changing type from any to other but nothing seems to be working

0

1 Answer 1

2

If the array is nested declare it as

var weekdays = [[Int]]() 

In cellForRow get the inner array with indexPath.row and iterate it the usual way

let weekdayArray = weekdays[indexPath.row]
for aWeekday in weekdayArray {
    print(aWeekday)
}
Sign up to request clarification or add additional context in comments.

6 Comments

Can you please confirm why question is downvote ?| Also there is one issue with your answer i.e aWeekday[3, 1] But how to get value 3 and 1 .. I mean how can I iterate over aWeekday
I didn't downvote. But I can imagine that people are downvoting because the question is a bit ambiguous, for example it's missing in which line the error occurs and is weekdays the data source array of something else? And in my example weekdayArray will contain [3, 1]. The loop is iterating over weekdayArray
Thanks for the info on downvote. And thanks for your solution. I am gonna accept your answer
I made changes on question, please do let me know if its correct now ?
It's much better. By the way: The error (message) occurs because you are trying to access a second level of a one-level array.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.