swift - User Class Design -
i new design patterns, in need of determining way of designing specific part of ios app working on.
i have user object, represents user logged in. simple, , looks this:
class user { var firstname: string var lastname: string var photo: string //must stored string filename. var listofjoinedopportunities = [opportunity]() var listofjoinedopportunitieskeys = [string]() var listoffriendsontheapp: nsarray var bio: string var email: string var userid: string //a unique id used persist data user 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 in need of instance represents logged in user, foresee needing class if add features interact other users of app.
a total of 5 views include interactions need read , write user object represents logged in user.
currently, passing around object controller controller creating new references. or, creating new object represents same logged-in user data saved database (firebase).
please help!
passing object destination view preferred way handle (prepareforsegue). being said, can store user object instance in appdelegate , reference view if fits model.
the drawback storing references in app delegate clutter , may unnecessary in more complex cases since they'll allocated (lookup lazy loading well). want pass objects along previous views can dealloc in turn lowers memory footprint. way if receive memory warning can handle appropriately recover properly.
// set var in appdelegate var user:user? // accessing view let appdelegate = uiapplication.sharedapplication().delegate as! appdelegate let loggedinuser = appdelegate.user
Comments
Post a Comment