iOS開發常見細節歸納

2021-07-09 03:44:36 字數 1796 閱讀 3183

1、判斷檔案是否存在,再匯入使用,避免檔案不存在的情況;

#if __has_include()

# include #elif __has_include()

# include #else

# error "insane system"

#endif

#if __has_include()

foundation_export double yymodelversionnumber;

foundation_export const unsigned char yymodelversionstring;

#import #import #else

#import "nsobject+yymodel.h"

#import "yyclassinfo.h"

#endif

2、foundation_export與#define 哪個來定義常量更好?

首先看看 蘋果的定義 

#if defined(__cplusplus)

#define foundation_extern extern "c"

#else

#define foundation_extern extern

#endif

#if target_os_win32

#if defined(nsbuildingfoundation)

#define foundation_export foundation_extern __declspec(dllexport)

#else

#define foundation_export foundation_extern __declspec(dllimport)

#endif

#define foundation_import foundation_extern __declspec(dllimport)

#else

#define foundation_export foundation_extern

#define foundation_import foundation_extern

#endif

接下來繼續,一般ios我們定義常量的方法有兩種,來看下面例子

我的.h檔案

foundation_export nsstring * const kmyconstantstring1;

foundation_extern nsstring * const kmyconstantstring2;

.m檔案是這樣定義的

nsstring * const kmyconstantstring1 = @"123";

nsstring * const kmyconstantstring2 = @"456";

nsstring *strtmp = @"456";

if(strtmp

== kmyconstantstring1)

nslog(@"strtmp:%p, kmyconstantstring2:%p", strtmp, kmyconstantstring2);

列印結果:

strtmp:0x103717248,  kmyconstantstring2:0x103717248
可見strtmp與 

kmyconstantstring2  指向同一記憶體位址。

iOS開發注意細節

1.在初始化方法的時候,只做初始化操作,不要新增動畫等類似操作 2.在使用 delegate 呼叫方法的時候要判斷一下,if delegate respondstoselector selector accordingcityrefreshlist 增加程式的健壯行 3.id initwithnib...

ui 細節歸納

訊息佇列中有多少個訊息可以放,這個訊息佇列定義的是多大?有幾個執行緒 ui開了幾個執行緒 自己寫一遍榮哥的鍊錶,提高一下自己的 水平,按下按鍵後的流程是什麼樣子的 按下按鍵根據的是鍵值還是btn的字元?和btn的字元有關係嗎 陣列和指標的區別,陣列本質上是什麼,是普通變數,陣列名本質上是什麼?是常指...

UI細節歸納

172.16.30.124 ls libbluetooth.la libbluetooth.so.3 libdbus 1.la libdbus 1.so.3 libglib 2.0.la libglib 2.0.so.0 libgmodule 2.0.la libgmodule 2.0.so.0 以...