• 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: Init in Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Init in Swift


  • Subject: Re: Init in Swift
  • From: Greg Parker <email@hidden>
  • Date: Tue, 06 Sep 2016 17:23:59 -0700

> On Sep 6, 2016, at 5:17 PM, Gerriet M. Denkmann <email@hidden> wrote:
>
>> On 5 Sep 2016, at 13:29, Quincey Morris <email@hidden> wrote:
>>
>> More globally, this sort of thing is not terribly idiomatic for Swift, because you’re trying to hide things that could get exposed other ways, for example, by “hostile” subclassing. The Swift-ier way would be to use a protocol instead of (or in addition to, but preferably instead of) the superclass. The protocol would “force” the subclass to define its own “onlyKnownBySubclass” locally.
>
> I do not think this would work for me. There are several subclasses and the superclass contains lots of functions (some of which are overwritten by subclasses).
> If the superclass becomes a protocol then all this code had to be duplicated in each subclass.

Swift protocol extensions can solve some of those problems. The protocol extension provides a default implementation to every class that conforms to the protocol. Each class may provide its own implementation that overrides the protocol extension's default implementation.


--
Greg Parker     email@hidden <mailto:email@hidden>     Runtime Wrangler


_______________________________________________

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: 
 >Init in Swift (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Init in Swift (From: Quincey Morris <email@hidden>)
 >Re: Init in Swift (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: Init in Swift
  • Next by Date: slicing in Swift
  • Previous by thread: Re: Init in Swift
  • Next by thread: Re: Init in Swift
  • Index(es):
    • Date
    • Thread