07-19-2023, 01:19 AM
According to Apple engineer Elizabeth Reid "shimming" is when you use conditional compilation to reuse code between iOS and OS X. For example:
#if TARGET_OS_IPHONE
@import UIKit;
#define BaseView UIView
#else
@import AppKit;
#define BaseView NSView
#endif
@interface MyView : BaseView
@end
In the WWDC 2014 session [Sharing code between iOS and OS X][1] she also states:
> If you literally translate how you would shim with Objective-C, this
> will not compile in Swift.
>
> There are ways to shim your code in Swift.
>
> But it gets more complicated than your basic conditional compilation
> that we can use in Objective-C.
So, which are the ways to "shim your code" in Swift?
[1]:
#if TARGET_OS_IPHONE
@import UIKit;
#define BaseView UIView
#else
@import AppKit;
#define BaseView NSView
#endif
@interface MyView : BaseView
@end
In the WWDC 2014 session [Sharing code between iOS and OS X][1] she also states:
> If you literally translate how you would shim with Objective-C, this
> will not compile in Swift.
>
> There are ways to shim your code in Swift.
>
> But it gets more complicated than your basic conditional compilation
> that we can use in Objective-C.
So, which are the ways to "shim your code" in Swift?
[1]:
[To see links please register here]