mercredi 22 avril 2015

User Class Design

I am very new to design patterns, so I am in need of help determining a good way of designing a specific part of an iOS app I am working on.

I have a User object, that represents the user that is logged in. It is very simple, and looks like this:

class User {
    var firstName: String
    var lastName: String
    var photo: String //must be stored as a string for the filename.
    var listOfJoinedOpportunities = [Opportunity]()
    var listOfJoinedOpportunitiesKeys = [String]()
    var listOfFriendsOnTheApp: NSArray
    var bio: String
    var email: String
    var userID: String   //A unique ID that is used to persist data about the user to the database (Firebase). 


  init(firstName: String, lastName: String, photo: String, email:String, userID: String, joinedEvents: [Opportunity],joinedStrings: [String]){
    self.firstName = firstName
    self.lastName = lastName
    self.photo = photo
    self.listOfJoinedOpportunities = joinedEvents
    self.listOfFriendsOnTheApp = []
    self.listOfJoinedOpportunitiesKeys = []
    self.bio = ""
    self.email = email
    self.userID = userID
  }   
}

Currently I am only in need of an instance that represents the logged in user, but I could foresee needing this class if I add features to interact with other users of the app.

A total of 5 views include interactions that need to read and write to the user object that represents the logged in user.

Currently, I am passing around the object from controller to controller by creating new references. OR, I am creating a new object that represents the same logged-in user from data that was saved to the database (Firebase).

Please help!

Aucun commentaire:

Enregistrer un commentaire