How to use SwiftUI in framework

大兔子大兔子 提交于 2019-12-11 14:29:18

问题


I'm using SwiftUI inside my binary framework, I added SwiftUI.framework as Optional in Embedded Binaries and use @available so it compiles just fine with deployment target iOS 9. However I cannot use it with xcodebuild, my commands :

xcodebuild clean archive \
    -project "${PROJECT_NAME}.xcodeproj" \
    -scheme ${1} \
    -configuration ${CONFIGURATION} \
    -destination "${2}" \
    -archivePath "${3}" \
    SKIP_INSTALL=NO \
    OBJROOT="${OBJROOT}/DependentBuilds" \
    BUILD_LIBRARY_FOR_DISTRIBUTION=YES | xcpretty

error message:

use of undeclared type 'View'

use of unresolved identifier 'UIHostingController'

P/s: -weak_framework SwiftUI in Other Linker Flags also didn't work


回答1:


SwiftUI doesn't have 32 bit header, so adding architecture flag where the error is fix the issue

#if (arch(x86_64) || arch(arm64))
//...
#endif



回答2:


You can wrap SwiftUI related code in #if canImport(SwiftUI) && canImport(Combine) statements. See example.



来源:https://stackoverflow.com/questions/58233454/how-to-use-swiftui-in-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!