Using the same file with different flags in WatchKit and host App

微笑、不失礼 提交于 2019-12-06 16:20:18

SWIFT version

Use other swift flags in build settings of your WatchKit Extension target. For example, add a flag WATCH (must be prefixed with -D):

Then in your shared file add this code:

        #if WATCH
            NSLog("watch")
        #else
            NSLog("app")
        #endif

Objective-C version

Use preprocessor macros in build settings of your WatchKit Extension target. For example, add a macro WATCH = 1:

Then in your shared file add this code:

#ifdef WATCH
    NSLog(@"watch");
#else
    NSLog(@"app");
#endif
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!