Fabio Cenni Fabio Cenni - 1 year ago 84
iOS Question

Type [TeamModel] has no subscript members

I'm trying to perform a segue from a UICollectionView cell to an other viewController, but Xcode send me this error "Type [TeamModel] has no subscript members" when I try to pass data.
here the the entire class

import UIKit

class AllTeamController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate
// MARK: properties

let navigationBar = UINavigationBar()
let segmentedControl = ADVSegmentedControl()
@IBOutlet weak var collectionView: UICollectionView!
@IBOutlet weak var menuButton: UIBarButtonItem!

// MARK: view method

override func viewDidLoad()


collectionView!.backgroundColor = UIColor.returnBasicColor("clearGreen")
collectionView!.decelerationRate = UIScrollViewDecelerationRateFast

let nib = UINib(nibName: "TeamCell", bundle: nil)
collectionView.registerNib(nib, forCellWithReuseIdentifier: "teamCell")

override func didReceiveMemoryWarning()

// MARK: collection view data source and delegate

func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int
return 1

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
return DataManager.sharedInstance.teamsArray.count

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("teamCell", forIndexPath: indexPath) as! TeamCell

let team = DataManager.sharedInstance.teamsArray[indexPath.row]
cell.teamImage.image = UIImage(named: team.teamImage)
cell.teamName.text = team.teamName
cell.teamAdress.text = team.teamAdress
cell.teamNumberOfChants.text = "\(team.teamNumeberOfChants)"

return cell

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
performSegueWithIdentifier("toChantController", sender: self)

// MARK: navigation (segue)

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
if (segue.identifier == "toChantController")
if let indexPath = collectionView.indexPathsForSelectedItems()
let controller = segue.destinationViewController as! TeamChantViewController
controller.chant = DataManager.sharedInstance.teamsArray[??????????????????]


import UIKit

class DataManager: NSObject
class var sharedInstance:DataManager
get {
struct Static
static var instance : DataManager? = nil
static var token : dispatch_once_t = 0
dispatch_once(&Static.token) { Static.instance = DataManager() }

return Static.instance!

// MARK: properties

var teamsArray: [TeamModel]!
var settingsArray: [[(name: String, description: String, image: String)]]!

// MARK: methods

func loadTeams()
let juveChant1 = ChantModel(name: "1")
let juveChant2 = ChantModel(name: "2")
let juveChant3 = ChantModel(name: "3")
let juventus = TeamModel(name: "Juventus", adress: "Cori della Juventus", number: 34, colors: ("juvColor","juvColor"), image: "juve_ritaglio", chants: [juveChant1,juveChant2,juveChant3])
let milan = TeamModel(name: "Milan", adress: "Cori del Milan", number: 12, colors: ("milColor","mlnColor"), image: "milan_ritaglio", chants: [juveChant1,juveChant2,juveChant3])
let inter = TeamModel(name: "Inter", adress: "Cori dell'Inter", number: 19, colors: ("intColor","intColor"), image: "inter_ritaglio", chants: [juveChant1,juveChant2,juveChant3])
let roma = TeamModel(name: "Roma", adress: "Cori della Roma", number: 10, colors: ("romColor","romColor"), image: "roma_ritaglio", chants: [juveChant1,juveChant2,juveChant3])
let napoli = TeamModel(name: "Napoli", adress: "Cori del Napoli", number: 21, colors: ("napColor","napColor"), image: "napoli_ritaglio", chants: [juveChant1,juveChant2,juveChant3])
let lazio = TeamModel(name: "Lazio", adress: "Cori della lazio", number: 5, colors: ("lazColor","lazColor"), image: "lazio_ritaglio", chants: [juveChant1,juveChant2,juveChant3])
let fiorentina = TeamModel(name: "Fiorentina", adress: "Cori della Fiorentina", number: 9, colors: ("fioColor","fioColor"), image: "fiorentina_ritaglio", chants: [juveChant1,juveChant2,juveChant3])
let torino = TeamModel(name: "Torino", adress: "Cori del Torino", number: 11, colors: ("torColor","torColor"), image: "torino_ritaglio", chants: [juveChant1,juveChant2,juveChant3])
teamsArray = [juventus,milan,inter,roma,napoli,lazio,fiorentina,torino]

func loadSettings()
let media = [(name: "Preferiti", description: "I tuoi cori prefriti", image: "heartIcon"),(name: "Stadi d'Italia", description: "Galleria degli stadi italiani", image: "stadiumIcon"),(name: "Mappa", description: "Luoghi di interesse", image: "mapIcon")]
let social = [(name: "Facebook", description: "Visita la pagina Facebook di iSupporters", image: "facebbokIcon"),(name: "Google+", description: "Visita la pagina Google+ di iSupporters", image: "google+Icon"),(name: "Twitter", description: "Visita la pagina Twitter di iSupporters", image: "twitterIcon"),(name: "Diffondi", description: "Suggerisci iSupporters a un amico", image: "megaphoneIcon")]
let settings = [(name: "Impostazioni", description: "Impostazioni e restrizioni", image: "settingImage"),(name: "Supporto", description: "Segnala un problea su iSupporters", image: "supportIcon"),(name: "Vota", description: "Dai un voto ad iSupporters su App Store", image: "rateIcon")]
settingsArray = [media,social,settings]

hope someone can explain me where I am doing wrong!

Lu_ Lu_
Answer Source

As in comment question

indexpath[0].row insted indexpath.row: could you explain me?

you are using method


it returns an array, it is that simple so you need to use

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download