【object-c 學習筆記】第8章 foundation Kit介紹

來源:互聯網
上載者:User

標籤:

1、資料類型

1)範圍

第一個是結構體,表示相關事物的範圍,通常是字串裡的字元範圍或者數組裡的元素範圍。

1     typedef struct _NSRange2     {3         unsigned int location;//存放該範圍的起始位置4         unsigned int length;//該範圍所含元素個數5     }NSRange;

  例如:"Object-c is a cool language"中,單詞cool可以用location為17,length為4的範圍表示;location還可以用NSNotFound這個值來表示沒有範圍,說明變數沒有初始化。

建立NSRange有三種方法:

(1)直接給欄位賦值;

1     NSRange range;2     range.location = 17;3     range.length = 4;

(2)應用C語言的彙總結構賦值機制

1     NSRange range = {17,4};

(3)cocoa提供的快捷函數 NSMakeRange(): 可以在任何能夠使用函數的地方使用它,例如在方法中調用將其作為參數傳遞;

1 NSRange range = NSMakeRange(17,4); [anObject flabulateWithRange:NSMakeRange(13,15)];

 

  

【object-c 學習筆記】第8章 foundation Kit介紹

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.