xcode - How can I concisely define model objects when using structs in Swift? -


I read somewhere that using strontacts was the best practice when using Swift to pass around model data.

I am doing this, but I am thinking that there is something that I can do regarding the creation of large (and growing) user data items:

  struct UserAccount {var id: string? AuthId: Give String Email Email Address: String Let Mobile Phone Number: String Let's First Name: String Let's Last Name: String Let Country Code: String Homepage Download Download URL: String Tagline: String Let's Picture: String Account Status: AccountState =. NoAccount // ...}  

When I create a user account, it is more or less, but later it is cumbersome and incorrect code in the wrong code. It has to be done. I am parsing using JSON responses, but then to separate the model separately, like:

  let id = jsondata ["id"]. String! Let's do authId = jsonData ["authId"] String! Enter email address = json.data ["emailAddress"]. String! Enter mobile phone number = jsonData ["mobilephoneNumber"]. String! Give First Name = jsonData ["First Name"] String! Let's lastName = jsonData ["lastname"]. String! Country Code = jsonData ["countrycode"]. Give String. Homepage url = jsnsdata ["homepage user"]. Give String! Give tagline = json.data ["tagline"]. String! Picture url = jesundidata ["picture url"]. Give String! Let's go to account = convertActTestat stringTontem (jsonData ["accountState"]. String!) User Account = User Account (id: id, authId: authId, email address: email address, mobile phone number: mobile phone number, first name: first name , Last name: last name, country code: country code, homepage url: HomepageUrl, tagline: tagline, image url: photo url, accountstate: accountstate)  

This may look absurd Before that I It has also been done by introducing the variable before extending the gram, but the reason for this is that when IDE writes for forced errors from within the structure, it is very difficult to understand what is wrong, and so when I change the model I am doing this, so it gives me permission to troubleshoot it quickly. Any ideas about this?

My question:

That user object may later contain too much data on the server side and 50+ lines look like a bad idea, so :

  1. Are there solutions to create strokes in a few simple ways? What is the name of the pattern?
  2. Should I create user models that are related to specific tasks? For example, to achieve a profile, the UserAccount is used to authenticate the model, the user may be able to get the settings or be different in the list of the most popular accounts of my service.
  3. Do people leave it only in the form and define the mappers so that there is no redundancy? If so - what is a good example of this?

Thanks.

When faced with this, I will create another launcher for the model which takes JSON data Is:

  struct UserAccount {// ... init (jsValue: JSValue) {id = jsonData ["id"]. String! AuthId = jsonData ["authId"] String! Email address = json data ["email address"]. String! Mobile phone number = json data ["mobile phone number"]. String! FirstName = jsonData ["First name"]. String! LastName = jsonData ["lastname"]. String! Countrycode = Json Data ["Country Code"]. String! HomepageUrl = jsonData ["homepageUrl"] String! Tagline = json.data ["tagline"]. String! PictureUrl = jsonData ["pictureUrl"]. String! You can create just the new  UserAccount  example from your JSON data: 

> user account = User account (jsv: jsnadata)

Comments