Swift Plist Reading and Initializing Arrays as Objects for Key

You can solve this by moving your code into a function that is called after your objects initialization.

Properties are initialized as part of the initialization of your object. You have created path and dict as properties and are trying to initialize them with code that does not meet the requirements for initialization.

An initializer cannot call any instance methods, read the values of any instance properties, or refer to self as a value until after the first phase of initialization is complete.

--The Swift Programming Language - Initialization - Safety check 4

Also, it seems you only want and need sceneName and sceneDetail to be properties, so you can move them completely within the scope of the method you use to populate sceneDetail and sceneName after initialization.

It's hard for me to say what the subscript error is exactly because I don't see what type of data detailVC.detailModal is supposed to contain; even so, it seems the wrong type of object is being passed into the detailModal array. A good little description of this issue is Swift and arrays


To resolve your initial problem, put the code inside a func, like:

var memoryName = []
var memoryDetail = []

override func awakeFromNib() {
    super.awakeFromNib()

    let path = NSBundle.mainBundle().pathForResource("Memories", ofType:"plist")
    let dict = NSDictionary(contentsOfFile:path)

    memoryName = dict["MemoryName"] as Array<String>
    memoryDetail = dict["MemoryDetail"] as Array<String>
}