• 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
swift - making array of subclass of class also conforming to protocol
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

swift - making array of subclass of class also conforming to protocol


  • Subject: swift - making array of subclass of class also conforming to protocol
  • From: Roland King <email@hidden>
  • Date: Sat, 28 Nov 2015 19:51:57 +0800

I have a protocol I want some of my UIView subclasses to conform to so they can be controlled by a specific master object. So they are UIVIews (class) and they are also MasterControllable (protocol)

easy to make those UIView subclasses

public class MyVIew1 : UIView, MasterControllable {}
public class MyView2 : UIView, MasterControllable {}

etc

what I wanted in the master was an array of them, an array of UIViews which are also MasterControllable, but I can’t think of a way to specify that

private var myViews : Array<UIView,MasterControllable>			// nope
private var myViews : Array<T:UIView where T:MasterControllable>	// nope

I can specify an array of something conforming to a protocol, or more than one protocol, or of a subclass of a given class, but not it seems of a subclass of a given class which also conforms to a given protocol.

Yes I could write a generic UIView subclass which conforms to the MasterControllable protocol and stub out all the protocol methods and then write my UIView subclasses as subclasses of that, then use an array of that generic class, but that seems a very old scruffy way of doing it.

I tried thinking about protocol extensions but didn’t get very far with that either.

Did I miss something or has my quest for type perfection led me down another blind alley?





_______________________________________________

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


  • Follow-Ups:
    • Re: swift - making array of subclass of class also conforming to protocol
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: Non-deprecated way to determine Process Type (LSUIElement etc.) ?
  • Next by Date: Re: FSIsAliasFile deprecated - typeOfFile is slow
  • Previous by thread: Re: FSIsAliasFile deprecated - typeOfFile is slow
  • Next by thread: Re: swift - making array of subclass of class also conforming to protocol
  • Index(es):
    • Date
    • Thread