1

I am new to Objective-C, and this compatibility issue of MTKView really confuses me.

I have a view class, and it's used to be like this,

@interface MyView : NSView
@end

@implementation MyView

// A lot of implementations

@end

I am now trying to use Metal to refresh the content in MyView. To use MTKView, which is defined on macOS as

@interface MTKView : NSView

I changed my code to

@interface MyView : MTKView
@end

I compiled my code with the latest SDK so it won't have any issue at compile time.

My questions are,

  1. Since MTKView is only supported on macOS 10.11+, what would happen if I run this code on devices with OS version lower than 10.11? I think it will probably not work since these devices don't know anything about MTKView at runtime. But could Apple had magically considered this issue and let it work on old devices just as NSView at the time my code is compiled?

  2. If it won't work on older OS version devices, what can I do to achieve this without any compatibility issue? What is the common method to solve this kind of compatibility issue? It should work like this but I think runtime inheritance is not a thing.

// Just to show how it should work
if (Is_10_11_Or_Above())
    @interface MyView : MTKView
else
    @interface MTKView : NSView
CookCookie
  • 35
  • 7
  • As far as I know **MTKView** should work on any type of devices that support **Metal** framework. – Hamid Yusifli Nov 19 '19 at 18:46
  • @0xBFE1A8 Thanks for your comment! I wish all devices could support Metal. I have to implement a traditional drawing method for devices that don't support Metal. My concern is that I can't just inherit `MTKView`, it would cause trouble when running on those devices that don't support Metal. – CookCookie Nov 20 '19 at 01:15

0 Answers0