Creating an iOS/OS X cross-platform class

后端 未结 3 473
生来不讨喜
生来不讨喜 2020-12-14 19:53

I read a lot of questions about creating a cross-platform library for these 2 systems. Every answer points to static library as the solution.

I don\'t want to end up

3条回答
  •  臣服心动
    2020-12-14 20:46

    When it comes to UIColor/NSColor, I handle it like this:

    #if TARGET_OS_IPHONE
    #define ImageClassName UIImage
    #else
    #define ImageClassName NSImage
    #endif
    

    Then, in header files, and if you're just passing instances around, you can just use e.g. ImageClassName *.

    Repeat the #if block in your code when you need to use the UIColor/NSColor APIs.

提交回复
热议问题