0
class subash{



var proper:String

init(name:String) {
    self.proper=name
  }
}


 var obj=[subash]()

 obj[0]=subash(name: "skills")


 print(obj[0].proper)

error is Fatal error: Index out of range

i have created a new array with the type of Subash, I failed to create elements of type subash in the array, Am I misunderstanding

0

1 Answer 1

1

Element in obj array at index 0 doesn't exist. Instead append new element to an array

obj.append(subash(name: "skills"))
Sign up to request clarification or add additional context in comments.

2 Comments

but we are not retriving any data right . we are just inserting so why i giving me error?
@subashchandru exactly. You're just inserting data and when you're trying to insert data at index where aren't any data. You first have to append some element at this index then you're able to rewrite it if you need to array.append(""); array[0] = ""

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.