IOS NSArray,NSDictionary

小結:

NSArray有序的集合;

NSDictionary無序的集合,可排序; 增刪改查

?

------NSArray-----------

?create :

1)NSArray *array = [NSArray arrayWithObjects:@"Henry",@"Jones", @"Susan", @"Smith", @"Patty", @"Johnson", nil];?

2)NSArray *myArray = [NSArray arrayWithArray:array];

NSLog(@"%@", myArray);?

3)?NSMutableArray *array = [[NSMutableArray alloc]?initWithObjects: @"Foo", @"Bar", @"FooBar", nil];?

4)?NSMutableArray *array2 = [NSMutableArray arrayWithCapacity: 3];

//Add an object

[array2 addObject: @"Foo"];

//Add another object

[array2 addObject: @"Bar"];

//Insert an object at a particular index

[array2 insertObject: @"FooBar" atIndex: 1];?

5)?int n = 15;

NSMutableArray *numberArray = [[NSMutableArray alloc] initWithCapacity:n];

//srand(time(0));

srandom(time(NULL));

for(int i = 0; i < n; i++)

[numberArray addObject:[NSNumber numberWithInt:arc4random()%n]];

NSLog( @"%@", numberArray);

?

sort:

NSArray *sortedArray =?

? [array sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];?

?

?

---------dictionary--------------

NSArray? *keys = [NSArray arrayWithObjects:@"key1", @"key2", @"key3", nil];

? ? NSArray *objects = [NSArray arrayWithObjects:@"How", @"are", @"you", nil];

? ? NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];

//Case 1, loop through?

for (id key in dictionary) {

? ? ? ? NSLog(@"key: %@, value: %@", key, [dictionary objectForKey:key]);

? ? }

//Case 2, loop through?

NSEnumerator *enumerator;

? ? id key;

enumerator = [dictionary keyEnumerator]; ? ?

? ? while ((key = [enumerator nextObject])){ ?

? ? ? ? NSLog(@"%@====>%@", key, [dictionary objectForKey:key]);

? ? }

?

轉載于:https://www.cnblogs.com/csj007523/archive/2012/07/20/2600889.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379477.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379477.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379477.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Java PropertyPermission equals()方法與示例

PropertyPermission類equals()方法 (PropertyPermission Class equals() method) equals() method is available in java.util package. equals()方法在java.util包中可用。 equals() method is used to check whether this object and the given object (ob) are equal or not…

c#配合oracle快速導入excel方法--原創(6萬條記錄5分鐘左右)

原理&#xff1a;用c#采用讀取Excel數據源方式將數據讀入c#的datatable,循環datatable,將datatable中的數據用stringbuilder拼成insert into (字段名) valus (值);每5條插入一個符號&#xff08;作用是將sql字符串限制在4000字符以內&#xff09;&#xff0c;然后將拼成的字符串…

English最俗語法大全

一、先分析兩個長難句 1,It is a truth universally acknowledged that a single man in possession of a good fortune must be in want of a wife. 人們公認這樣一個事實&#xff0c;一個有錢的單身男人一定想要娶一個妻子。 in want of want 想要 university widely 廣泛的…

tfs 內網和外網切換的方法。

C:\Windows\System32\drivers\etc的hosts文件配置一個123.67.128.109 geo-dept-3轉載于:https://www.cnblogs.com/lwflt/archive/2012/07/23/2604731.html

observable_Java Observable countObservers()方法與示例

observable可觀察的類countObservers()方法 (Observable Class countObservers() method) countObservers() method is available in java.util package. countObservers()方法在java.util包中可用。 countObservers() method is used to count the number of observers exists…

設計模式--Strategy 策略模式

所謂策略模式(Strategy Pattern)&#xff0c;就是將策略 (算法) 封裝為一個對象&#xff0c;易于相互替換&#xff0c;如同 USB 設備一樣可即插即用&#xff1b;如果將策略、具體的算法和行為&#xff0c;編碼在某個類或客戶程序內部&#xff0c;將導至事后的修改和擴展不易。 …

HDU-1518 Square dfs+剪枝

該題問給定的棍子能否組成一個正方形。首先我們要判定是否總長度是4的倍數&#xff0c;然后再決定是否存在某條邊大于組合邊長。 搜索的過程中也是可以進行剪枝了。 首先將邊排序&#xff0c;我們可以假定所有的組合邊由大小遞減的邊組成&#xff0c;那么我們在搜索的時候就不用…

英語思維黃金法則

一、謂語單一原則 英文的句子當中&#xff0c;有且只有一套謂語結構。 要想使用多個謂語&#xff0c;有以下三種方法&#xff1a; 1&#xff0c;利用連詞將不同謂語并列起來 2&#xff0c;把其中的一些動詞給降級&#xff08;v-ing v-ed 非謂語動詞&#xff09; 3&#xff0c;…

java getname_Java文件類字符串getName()方法(帶示例)

java getname文件類字符串getName() (File Class String getName()) This method is available in package java.io.File.getName(). 軟件包java.io.File.getName()中提供了此方法。 This method is used to retrieve or return the filename or directory name and represente…

WF中DependencyObject和DependencyProperty的實現

WF中DependencyObject和DependencyProperty的實現 DependencyProperty的Register和RegisterAttached方法&#xff0c;將DependencyProperty存在IDictionary中完成注冊&#xff0c;確保相同name的DependencyProperty在一個ownerType類型中只能有一個。 DependencyObject的GetVal…

hdu2115: I Love This Game

hdu2115: http://acm.hdu.edu.cn/showproblem.php?pid2115題意&#xff1a;輸入n組名字和對應的時間&#xff08;分&#xff1a;秒&#xff09;&#xff0c;要求按時間長度由短到長排序&#xff0c;并輸出對應排名&#xff0c;若時間一樣&#xff0c;則按名字字典序排序&#…

打開eclipse出現Failed to load the JNI shared library “D:\java\jdk\bin\...\jre\bin\server\jvm.dll”如何解決?

eclipse打開的時候出現Failed to load the JNI shared library “D:\java\jdk\bin…\jre\bin\server\jvm.dll”如何解決&#xff1f;&#xff1f; 如圖所示&#xff1a; 即代表你的jdk與eclipse的位數不一樣&#xff01;&#xff01;&#xff01; 你可以查看一下eclipse和jd…

Java DataOutputStream writeUTF()方法及示例

DataOutputStream類的writeUTF()方法 (DataOutputStream Class writeUTF() method) writeUTF() method is available in java.io package. writeUTF()方法在java.io包中可用。 writeUTF() method is used to write the given string value to the basic data output stream wit…

2010年世界杯分組

A 南非 墨西哥 烏拉圭 法國 B 阿根廷 南非 韓國 希臘 C 英格蘭 美國 阿爾及利亞 斯洛文尼亞 D 德國 澳大利亞 塞爾維亞 加納 E 荷蘭 丹麥 日本 喀麥隆 F 意大利 巴拉圭 新西蘭 斯洛伐克 G 巴西 朝鮮 科特迪瓦 葡萄牙 H 西班牙 瑞士 洪都拉斯 智利 轉載于:https://www.cnblogs.c…

圓形墜落模擬算法設計

目標&#xff1a;實現一個算法&#xff0c;模擬在一個封閉二維區域&#xff0c;圓形小球朝給定方向墜落的過程&#xff0c;實現二維區域的緊密填充。 像下面這樣&#xff1a; 難點&#xff0c;及其簡單解決&#xff1a; 1.如何把粒子移動盡可能遠&#xff1f; 圖中的粒子i&…

Maven詳細教學

一、Maven簡介 maven&#xff1a;是apache下的一個開源項目&#xff0c;是純java開發&#xff0c;并且只是用來管理java項目的 依賴管理&#xff1a;就是對jar包的統一管理 可以節省空間 項目一鍵構建&#xff1a;mvn tomcat:run該代碼可以將一個完整的項目運行起來&#xff0…

Java Character.UnicodeBlock of()方法與示例

Character.UnicodeBlock類的()方法 (Character.UnicodeBlock Class of() method) of() method is available in java.lang package. of()方法在java.lang包中可用。 of() method is used to return the Unicode block containing the given parameter value or it returns null…

simpleDBM的B-link樹實現

參考的是VLDB2005的這篇論文&#xff0c;做個標記把。/Files/YFYkuner/Concurrency_control_and_recovery_for_balanced_B-link_trees.pdf 轉載于:https://www.cnblogs.com/YFYkuner/archive/2009/12/21/1629268.html

網站后臺中對html標簽的處理

最近做一個CMS&#xff0c;后臺中需要使用在線編輯器對新聞進行編輯&#xff0c;然后發表。我用的在線編輯器是CKEditorCKFinder。也許是我為了讓CKEditor更本地化吧&#xff0c;改了很多。后來發現在CKEditor中對文字設置字體、顏色、字號大小時文字的<span>標簽會出現N…

Java Calendar getActualMaximum()方法與示例

日歷類的getActualMaximum()方法 (Calendar Class getActualMaximum() method) getActualMaximum() method is available in java.util package. getActualMaximum()方法在java.util包中可用。 getActualMaximum() method is used to return the maximum value that the given …