Hi Roland,

I think you’re right.  The trick is - what do I put in the Storyboard such that 
it sticks (and IB doesn’t just change it back) and resolves at runtime?

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

> On Dec 3, 2015, at 11:17 PM, Roland King <r...@rols.org> wrote:
> 
> 
>> On 4 Dec 2015, at 14:45, Stevo Brock <devli...@sunsetmagicwerks.com> wrote:
>> 
>> 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).
> 
> I don’t see how that would work. IB needs a fully specified class in order to 
> instantiate it, you just have the name of the generic. At the least you need 
> MediaItemViewController<VideoMediaItemView> but I’m not even sure that would 
> work. The error message is indeed telling you that no such class as 
> MediaItemViewController exists, because it doesn’t, only specialised versions 
> of it actually exist (you can probably dump your binary to see what they are 
> called, I don’t know the mangled naming convention for generics)
> 
> 
> 
> 


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to