nsrange:
nsrange的定義
typedef struct _nsrange nsrange;
typedef nsrange *nsrangepointer;
ns_inline nsrange nsmakerange(nsuinteger loc, nsuinteger len)
nsstring *str = @"liumingchuan";
nsrange range1 = nsmakerange(0, 3);
nslog(@"%@",[str substringwithrange:range1]);
nsrange range2 = [str rangeofstring:@"ming"];
nslog(@"range of ming location is %lu length is %lu",range2.location,range2.length);
nsrange range3 = [str rangeofstring:@"o"];
nslog(@"range of ming location is %lu length is %lu",range3.location,range3.length);
// 當沒有匹配時返回nsnotfound
// nsnotfound的定義
// static const nsinteger nsnotfound = nsintegermax;
// #define nsintegermax long_max
// 當上面location找不到時,其實返回的數值是-1 因為是無符號整數 我們列印的是最大值(使用最高位作為符號位)
// 所以nsnotfound的值是-1
nslog(@"nsnotfound is %ld",(long)nsnotfound);
nslog(@"nsnotfound:%d \nnsintegermax:%ld \nlong_max:%ld \n",nsnotfound,nsintegermax,long_max);
輸出:
2015-10-04 17:06:51.660 ocstudy[3372:2659715] liu
2015-10-04 17:06:51.661 ocstudy[3372:2659715] range of ming location is 3 length is 4
2015-10-04 17:06:51.661 ocstudy[3372:2659715] range of ming location is 9223372036854775807 length is 0
2015-10-04 17:06:51.662 ocstudy[3372:2659715] nsnotfound is 9223372036854775807
2015-10-04 17:06:51.662 ocstudy[3372:2659715] nsnotfound:-1
nsintegermax:9223372036854775807
long_max:9223372036854775807
常用的還有
cgpoint/nspoint
cgsize/nssize
cgrect/nsrect
// struct cgpoint ;
// typedef struct cgpoint cgpoint;
cgpoint origin = cgpointmake(0, 0);
// cgpoint origin = cgpointzero;
// cgpoint origin = ;
// cgpointequaltopoint(point1, point2);
// struct cgsize ;
// typedef struct cgsize cgsize;
cgsize size = cgsizemake(100, 100);
// cgsize size = cgsizezero;
// cgsize size = ;
// cgsizeequaltosize(size1, size2);
// struct cgrect ;
// typedef struct cgrect cgrect;
cgrect rect = cgrectmake(0, 0, 100, 100);
// cgrect rect = cgrectzero;
// cgrect rect = ,};
// cgrect rect = ;
// cgrectequaltorect(rect1, rect2);
// cgrectcontainspoint(rect, point);
// cgrectcontainsrect(rect1, rect2);
//結構體轉為字串
nsstring *str1 = nsstringfrompoint(origin);
nslog(@"%@",str1);
nsstring *str2 = nsstringfromsize(size);
nslog(@"%@",str2);
nsstring *str3 = nsstringfromrect(rect);
nslog(@"%@",str3);
輸出:
2015-10-04 23:05:33.243 ocstudy[3780:3398073]
2015-10-04 23:05:33.243 ocstudy[3780:3398073]
2015-10-04 23:05:33.243 ocstudy[3780:3398073] , }
Objective C常用的幾個結構體
nsrange 表示範圍 location length 初始化 nsrange range nsrange nsmakerange 4,5 nsstring str nsstringfromrange range 轉成nsstring nssize等同於 cgsize 有兩個值組成 weight表...
libevent幾個結構體的理解
struct event base struct event base 這裡要注意struct event list activequeues 為什麼用雙指標,這是因為很多事件的優先順序一致,所以用佇列陣列來存放,這樣導致有些事件不能第一時間處理 struct event 這裡主要理解幾個 tail...
OC之常用結構體
一 基本知識 foundation 基礎框架。框架中包含了很多開發中常用的資料型別,如結構體,列舉,類等,是其他ios框架的基礎。如果要想使用foundation框架中的資料型別,那麼包含它的主標頭檔案就可以了。即 import 補充 core foundation框架相對底層,裡面的 幾乎都是c語...