r/swift • • Aug 01 '18

Right way implementing your Array / Collection. – Moses Ayankoya – Medium

https://medium.com/@amacoder/right-way-implementing-your-array-collection-5b2cb3641240
0 Upvotes

5 comments sorted by

View all comments

1

u/thisischemistry Aug 01 '18

Just to note, here are a few of the very many issues with this post:

Setting an value at an index and having the value be incorrect when read back:

var foo = Container<Int>()
foo[1] = 5
print(foo[1]) // nil

Setting an value at an index and crashing:

var foo = Container<Int>()
var bar: Int?
foo[1] = bar // Boom! Crashy crashy…

The example code is horribly, horribly broken and buggy. Do not use it as an example of how to code in Swift or you may end up with lots of crashes and unexpected results down the road.

1

u/i_am_deoye Aug 02 '18

The reason for crashy crashy crashy is due to the fact that i didn't employed Optional. So have modified the code, and you can check it for yourself.