• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: What type category should I use for my model in Swift?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What type category should I use for my model in Swift?


  • Subject: Re: What type category should I use for my model in Swift?
  • From: David Duncan <email@hidden>
  • Date: Thu, 02 Jun 2016 09:40:59 -0700

> On Jun 2, 2016, at 8:55 AM, Daryle Walker <email@hidden> wrote:
>
> [Warning: rambling]
>
> In Objective-C, you pretty much have to use a class for you model (in your MVC Cocoa app). But in Swift, you have the option to use a struct/enum or a non-NSObject class too.
>
> My model in mind is dumb data, so a struct seems appropriate.  But your various Cocoa subclass would need to reference the model, and using a struct means it’s by value instead of reference, so coordinating changes would get harder.
>
> I’m guessing that I could use something like view-models, and only those VMs access the model, and always through referencing the containing object (like a NSDocument subclass).  But a reference type, even a non-NSObject one, still seems easier.  And I may want to use KVO or Core Data, which require NSObject subclasses.


In practical terms, a model typically both has value and reference types. If you take a game example, the data that describes the capabilities of a unit is value data, but the unit itself has identity and is thus a reference type. Also “Dumb” vs “Smart” data doesn’t really translate well to value vs reference – you can have “smart” structs and “dumb” classes (a Box class is a typical example of a “dumb" class – its entire purpose is to grant identity to a value type) – its really a matter of if you need identity or not.

I would highly recommend you experiment and do what feels for your case.
--
David Duncan


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >What type category should I use for my model in Swift? (From: Daryle Walker <email@hidden>)

  • Prev by Date: What type category should I use for my model in Swift?
  • Next by Date: Re: What type category should I use for my model in Swift?
  • Previous by thread: What type category should I use for my model in Swift?
  • Next by thread: Re: What type category should I use for my model in Swift?
  • Index(es):
    • Date
    • Thread