mardi 4 août 2015

Extracting elements of a tuple from an array of tuples in swift

I have managed quite easily to extract tuple from an array of tuples however I am stumped as to how to extract the elements of the tuple.

//: Playground - noun: a place where people can play

import UIKit

import Foundation

class ActivityDetailsModel {


    var activityCategory: String! // The choice of major activity


    init(activityCategory: String){
        self.activityCategory = activityCategory
    }

    class func activityForm(activityCategory: String) -> [(Question: String, Answer: String)] {
        var activityProfile: [(Question: String, Answer: String)] = [] //An array of tuples containing the users activity details

        switch activityCategory {
        case "Sport":
            activityProfile = [(Question:  "Home Club", Answer: "a"),(Question: "Other venues", Answer: "b")]// [, ["Activity days – Mon – Sunday": "c"], ["Player strength": "d"], ["Age group to play with": "e"]]
            return activityProfile
        case "Recreation":
            activityProfile = [(Question:  "Home Club2", Answer: "ab"),(Question: "Other venues3", Answer: "bc")]
            return activityProfile

        default:
            var activityProfile = [(Question:  "nixs", Answer: "nie")]
            return activityProfile
        }

    }


}
var actProf:[(Question: String, Answer: String)]
actProf = ActivityDetailsModel.activityForm("Recreation")
println(actProf[1])

This returns the second tuple from the array - all I need now is to extract the elements of the tuple



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire