背景描述:項(xiàng)目升級(jí)到xcode 8 后,遇到了一些問(wèn)題,做下記錄,以供大家參考;
問(wèn)題一:Swift 2.3 升級(jí)到 swift 3.0 的問(wèn)題
PS:我是在OC項(xiàng)目中遇到的,靜態(tài)庫(kù)沖突
解決方案:
1,舊項(xiàng)目,使用xcode8打開時(shí),會(huì)自動(dòng)詢問(wèn),是否自動(dòng)將 swift2.3語(yǔ)法,升級(jí)到swift3.0;可以選擇轉(zhuǎn)換,轉(zhuǎn)換之后,如果還有報(bào)錯(cuò)的地方,需要自己手動(dòng)處理swift語(yǔ)法錯(cuò)誤;
2,如果不升級(jí)swift語(yǔ)法,可以在build setting 中,設(shè)置Use Legacy Swift Language Version 為YES;即:允許使用低版本swift;
問(wèn)題二:項(xiàng)目編譯期間,報(bào)符號(hào)重定義的錯(cuò)誤:duplicate symbols
解決方案:
1,Build Setting 中,設(shè)置NO Common Blocks 為NO; 【該選項(xiàng)的意思,官方解釋如下】
In C, allocate even uninitialized global variables in the data section of the object file, rather than generating them as common blocks. This has the effect that if the same variable is declared (without extern ) in two different compilations, you will get an error when you link them. The only reason this might be useful is if you wish to verify that the program will work on other systems which always work this way.
2,如果1不起作用,繼續(xù)Build Setting 中,設(shè)置Enable Testability 為NO;【該選項(xiàng)的意思,解釋如下】(或者查看重定義的符號(hào),是否聲明為了static 類型)
From The Xcode 8 Release Notes:
When the Enable Testability build setting is enabled, Xcode 8 will pass -export_dynamic to the linker to preserve all global symbols for testing. This effectively overrides dead code stripping, which can expose link failures from unused functions that reference undefined symbols. If necessary, disabling testability will allow the link to proceed without source changes. (27684883)
Of course, the best thing to do is to either: a) remove the unused code that is causing the linker issues, or b) actually fix the linker issues.
在用oc語(yǔ)言寫的項(xiàng)目中親測(cè)可用,在這附上原文地址http://blog.csdn.net/jiajiayouba/article/details/52766600
十分感謝原創(chuàng)作者