2019ios筆記

weixin_33797791發表於2019-03-06

合併unity工程遇到的問題:

1.ios cannot use "@throw" with objective-c exceptions disabled 問題解決方案
解決辦法:修改target -> build settings -> All | Combined -> Apple LLVM Compiler 7.0 - Language 中 Enable Objective-C Exceptions 為YES

2.錯誤為:a parameter list without types is only allowed in a function definition。
解決辦法:Apple LLVM 6.1 - Language設定C Language Dialect為Compiler Default或者GNU99[-std=gnu99]

3.使用 LLVM 混淆器新增引數進行編譯提示如下錯誤:
clang (LLVM option parsing): for the -bcf option: may only occur zero or one times!

將編譯引數全部複製下來,仔細對比發現,有重複的
-DINIT_SCRIPTING_BACKEND=1
-mllvm
-bcf
-fno-strict-overflow
-DINIT_SCRIPTING_BACKEND=1
-mllvm
-bcf
於是再檢視 Xcode 的 CFlag 配置,發現有一個 $(inherited) 引數,刪除這個引數就可以了。

ios開發進階筆記

1.修改block之外的變數

預設下,在block中訪問的外部變數是複製過去的,即無法改變原變數的值。需要能改變原變數的值,需要在變數宣告時加上__block。示例程式碼如下:

__block int a = 0;
void (^func)(void) = ^{
    a++;
}
func();
//到這裡a的值已被修改為1;

如果變數是引用型別的物件,預設情況下雖然是複製,但引用計數也會加1,我是這麼理解的。

2.關於UIWindow
  • UIWindow 繼承自UIView,所以可以透過addSubView方法新增子UIView。
  • 通常程式裡只有一個UIWindow,當UIAlertView彈出時,系統會臨時建立一個UIWindows,並讓其UIWindowLevel設定的更高,以保證它出現在所以應用介面之上。
  • UIWindow還適用於實現:手勢解鎖介面,啟動介紹頁,通知和提示的顯示,彈框廣告。