ios - Use UIKit conditionally in file used by Watch app -
i have created model class use in ios app , watch app - included in both targets. have use uipasteboard
in class available in uikit
, not available watchos. while can import uikit file without issue, when go use uipasteboard
not compile because watch extension not know it.
how can use uipasteboard
in class available watch app?
i wondered if run code when device isn't apple watch using #available
, didn't resolve issue.
if #available(ios 7.0, *) { uipasteboard.generalpasteboard()... //error: use of unresolved identifier 'uipasteboard' } else { //don't use uipasteboard }
use existing preprocessor directive defined in swift:
#if os(ios) //uikit code here #elseif os(watchos) //watch code here #endif
see documentation preprocessor directives here.
Comments
Post a Comment