"Empty collection literal requires an explicit type" error on Swift3

Update swift 4 :

var array = [] as [String]

This error occurs since implicit conversions are abolished so you have to tell the compiler the explicit type (of the ArrayLiteral []):

var list: NSArray = []
// or
var list = [] as NSArray

The Swift 5 guided tour is pretty explicit about creating empty arrays or dictionaries: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html#ID461 towards the end of the first section.

To create an empty array or dictionary, use the initializer syntax.

let emptyArray = [String]()
let emptyDictionary = [String: Float]()

Tags:

Ios

Swift3