# Initialize Struct with Array

**URL:** <https://forums.kodeco.com/t/initialize-struct-with-array/43583>\
**Category:** Swift\
**Created:** [June 13, 2018, 9:49pm UTC](https://forums.kodeco.com/t/initialize-struct-with-array/43583 "2018-06-13T21:49:37Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![sprouse5](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@sprouse5](https://forums.kodeco.com/u/sprouse5)\
**Post date:** [June 14, 2018, 12:16pm UTC](https://forums.kodeco.com/t/initialize-struct-with-array/43583/3 "2018-06-14T12:16:06Z")

</div>

Thanks for that insight! Here is what I ended up with:

```
struct MyStruct {
    let title: String
    let selected: Bool
}

var myStrings: [String]?

...

// simple version of initializing optional string array
myStrings = [String]()
myStrings?.append("Apple")
myStrings?.append("Banana")
myStrings?.append("Carrot")

guard let mStrings = myStrings else { return }
let structArray = mStrings.map { MyStruct(title: $0, selected: false) }

```

The thing I think was I missing was the fact that my original string array is an optional, so I added the guard statement before mapping and now it works! Thanks for the help!

---

_[View the full topic](https://forums.kodeco.com/t/initialize-struct-with-array/43583)._
