jonpeter
jonpeter

Reputation: 599

Contextual type String, float, f float cannot be used with array literal

let MSULandMarks: [(String, Float, Float)] = [["ALUMNI MEMORIAL CHAPEL", 42.728419, -84.474001], ["BEAUMONT TOWER & CARILLON", 42.731948, -84.482194], ["BRESLIN CENTER", 42.728305, -84.492395], ["DAIRY STORE - SHAW", 42.724292, -84.478380], ["DAIRY STORE - UNION", 42.734195, -84.482827], ["MUNN ICE ARENA", 42.728305, -84.492395], ["THE ROCK", 42.728109, -84.477584], ["SPARTY", 42.731103, -84.487491], ["SPARTAN STADIUM", 42.728132, -84.484831]]

How am I setting this up incorrectly?

Upvotes: 0

Views: 66

Answers (2)

Mo Abdul-Hameed
Mo Abdul-Hameed

Reputation: 6110

You are using square brackets [] to create tuples, you should be using ().

This is how you should do it:

var MSULandMarks: [(string: String, f1: Float, f2: Float)] = [
    ("ALUMNI MEMORIAL CHAPEL", 42.728419, -84.474001),
    ("BEAUMONT TOWER & CARILLON", 42.731948, -84.482194),
    ("BRESLIN CENTER", 42.728305, -84.492395)
]

As you noticed, I gave names for the tuple elements to make accessing them easier.

print(MSULandMarks[1].string) // Prints: BEAUMONT TOWER & CARILLON

Upvotes: 1

Fogmeister
Fogmeister

Reputation: 77651

Your internal objects should use (). You are using [].

The type of the array you creating is [[Any]] not [(String, Float, Float)] like you want.

Change he square brackets to parens and it will fix your problem.

Upvotes: 1

Related Questions