• 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
Need Help with Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Need Help with Swift


  • Subject: Need Help with Swift
  • From: Stevo Brock <email@hidden>
  • Date: Thu, 03 Dec 2015 22:45:38 -0800

I’m trying to set up a UIViewController than can host a number of different UIViews as long as they adhere to a given protocol.  I’ve worked through getting things set up to make the compiler happy, but I’m getting a runtime error loading the view controller from the storyboard.  Below is the relevant code.

How do I specify the class in the storyboard so it will load correctly?  Or perhaps there’s a different way to construct this all so it will work?

protocol MediaItemView {
}

class PhotoMediaItemView : UIImageView, MediaItemView {
}

class VideoMediaItemView : VideoPlayerView, MediaItemView {
}

class MediaItemViewController<T where T: UIView, T: MediaItemView> : UIViewController {
	private	var	currentMediaItemView :T?
}


let	mediaItemViewController =
		self.storyboard?.instantiateViewControllerWithIdentifier("MediaItemViewController") as!
			MediaItemViewController<VideoMediaItemView>

Storyboard has a view controller with the Class set to "MediaItemViewController"

2015-12-03 22:07:23.966 Media Tools[14143:276368] Unknown class _TtC11Media_Tools23MediaItemViewController in Interface Builder file.
Could not cast value of type 'UIViewController' (0x10d1dfd60) to 'Media_Tools.MediaItemViewController<Media_Tools.PhotoMediaItemView>' (0x1193fc038).

-Stevo Brock
 Owner
 Sunset Magicwerks, LLC
 www.sunsetmagicwerks.com
@SunsetMagicwrks
 818-478-9758

_______________________________________________

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: Need Help with Swift
      • From: Roland King <email@hidden>
    • Re: Need Help with Swift
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: Overriding property attributes
  • Next by Date: Re: Need Help with Swift
  • Previous by thread: Re: Overriding property attributes
  • Next by thread: Re: Need Help with Swift
  • Index(es):
    • Date
    • Thread