November 30, 2016

在Obj-C專案中使用Swift CocoaPod Library

在時代從Obj-C到Swift的過渡期,某些時候我們就是可能需要在專案中引用到Swift的Library。Apple也非常好心的準備了一切,只不過有時候就是沒那麼完美。

官方文件:
Swift and Objective-C in the Same Project

在使用一個SideMenu pod的時候遭遇兩個問題:

1. 出現錯誤:“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

解法是在PodFile中加入以下
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end


參考網址:http://stackoverflow.com/questions/38446097/xcode-8-beta-3-use-legacy-swift-issue/38466703#38466703


在整合時遇到第二個問題:
找不到 menuAddScreenEdgePanGesturesToPresent 將無法正確設定螢幕邊緣的PanGesture。
所幸最後在issue中找到解法: https://github.com/jonkykong/SideMenu/pull/82

原來某些swift語法無法正確被轉換為objC的語法,以至於產生的 xxx-swift.h 內容不完全。根據該pull request可以修正ScreenEdgePanGesture的問題,不過另一個menuBlurEffectStyle則得自行修改了。

0 Comments: