0

I have team, teamScore, userScore information on parse. I download it and now want to store it locally and update it. I will create Team() Class, have the scores as properties and then creating instances of the class with team names downloaded from parse. Problem is how to create instance of this class with names from the parse downloaded team names?

OR is there a simpler way to solve this problem without classes?

5
  • You could use a dictionary, an array of your Team class, or your Team class with CoreData. Commented Dec 16, 2014 at 14:28
  • i really wanted to have an array of teams with teamScore and userScore as dictionary items but could not figure out how to do it. Commented Dec 16, 2014 at 14:36
  • Ah yes, sorry, an array of dictionary items is probably what you want. Each dictionary would have two keys. Commented Dec 16, 2014 at 14:40
  • I tried var teamsData = [["teamName":["teamScore":0, "userScore":0]]] to declare which works but then teamsData.append("USA":("teamScore":0,"userScore":0)) does not work. Commented Dec 16, 2014 at 15:04
  • Would have to be a mutable array to add to it, or you could use arrayByAddingObjectsFromArray(). Commented Dec 16, 2014 at 15:07

1 Answer 1

1

You can try something like that:

var className = "TeamClassName"
var c = NSClassFromString(className) as? TeamScoreSuperclas.Type
if let cl = c {
    println("ok")
}
else {
    println("false")
}

You should have a superclass for your team, score, etc classes. In the example above you pass team class name as a parameter but if you change it to score it will be fine until the superclass is the same.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.