Mike Chen
Mike Chen

Reputation: 397

Unresolved identifier 'join' and 'array' is unavailable

While I use Xcode 8.1.2 to edit the lines of code, the two problems occurred. Please help me solve the problems.

  1. Use of unresolved identifier ‘join’

Xcode 8.1.2 indicates Use of unresolved identifier ‘join’ Line of Code: 6

    func countryFromFilename(_ filename: String) -> String {
        var name = filename.components(separatedBy: "-")[1]
        let length: Int = name.characters.count
        name = (name as NSString).substring(to: length - 4)
        let components = name.components(separatedBy: "_")
        return join(" ", components)
    }

2.'array' is unavailable: Please use Array initializer instead. Line of code: 1

        if model.regions.values.array.filter({$0 == true}).count == 0 {
            model.toggleRegion(regionNames[defaultRegionIndex])
            switches[defaultRegionIndex].isOn = true
            displayErrorDialog()

Thanks in advance,

Mike

Upvotes: 1

Views: 609

Answers (1)

Martin R
Martin R

Reputation: 539685

(Summarizing above comments:) There is no global join function in Swift 3. To concatenate an array of strings, use

components.joined(separator: " ")

Secondly, "'array' is unavailable: Please use Array initializer instead" means that

model.regions.values.array

should be

Array(model.regions.values)

However, there is no need to create an array, you can filter the values sequence directly:

if model.regions.values.filter({$0 == true}).count == 0

which in turn can be simplified to

if !model.regions.values.contains(true)

Upvotes: 1

Related Questions