0

I have a struct that contains array of arrays:

public struct myStruct: Codable {
    var timetables:[[MyObject]] = [[]];
}

How to initialise the first external array so to limit by e.g. 7 and be able to insert at any index "internal" array?

1 Answer 1

2

Use Array's repeating:count: initializer:

var timetable = Array(repeating: [MyObject](), count: 7)
Sign up to request clarification or add additional context in comments.

3 Comments

Nope, when JSONdecoding if I have only one element it gives count 1
In that case you can't rely on the compiler-generated initializer anymore, but have to implement init(from decoder: Decoder) yourself. I'll update my answer.
Nevermind, it's me who made an error changing not in all places. Your solution perfectly works

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.