nsarray *array = [nsarray
arraywithobjects:@"one", @"two", @"three", nil];
nslog(@"%d", array.count);
// 訪問陣列的第乙個元素
nslog(
@"%@"
, [arrayobjectatindex:
0]);
// 最後乙個元素位置為array.count - 1
// nslog(@"%@", [array objectatindex:array.count]);
//動態陣列
nsmutablearray*marray = [nsmutablearray
arraywitharray
:array];
[marray addobject:@"four"];
[marray removeobjectatindex:2];
nslog(@"%@", marray);
// 合併陣列
nslog(
@"%@"
, [arrayarraybyaddingobjectsfromarray:marray]);
// 檢查陣列
if ([marraycontainsobject:@"four"])
nslog
(@"the index is %d", [marray
indexofobject
:@"four"]);
// 組成陣列
nslog(
@"%@"
, [arraycomponentsjoinedbystring:
@" "
]);
// 可變字典
nsmutabledictionary*dict = [nsmutabledictionary
dictionary
];[dict setobject:
@"1"
forkey:
@"a"
];[dict setobject:
@"2"
forkey:
@"b"
];[dict setobject:
@"3"
forkey:
@"c"
];nslog(
@"%@"
, [dictdescription]);
// 字典查詢
nslog(
@"%@"
, [dictobjectforkey:
@"a"
]);nslog(
@"%@"
, [dictobjectforkey:
@"f"
]);
// 替代字典元素
[dict setobject:
@"foo"
forkey:
@"c"
];nslog(
@"%@"
, [dictobjectforkey:
@"c"
]);
// 刪除字典元素
[dict removeobjectforkey:
@"b"];
//字典元素數量及keys
nslog
(@"the dictionary has %d objects", [dict
count
]);nslog(@"%@", [dictallkeys]);
// 把字典元素寫入檔案後讀出
nsstring
@"documents/arraysample.txt"
];if
([arraywritetofile:path atomically:
yes])
nslog
(@"file was written successfully");
nsarray *newarray = [nsarray
arraywithcontentsoffile:path];
nslog(@"%@", newarray);
IOS Foundation基礎知識
1.如果某個物件obj為nil,在執行obj的方法時 int i obj methodwhichreturnint 這時的 i 0 程式執行正常 如果執行函式返回值為結構體,如 cgpoint p obj getlocation 則p為undifined 2.object 的自省機制 iskindo...
iOS Foundation 框架基類
ios foundation 框架基類 太陽火神的漂亮人生 本文遵循 署名 非商業用途 保持一致 創作公用協議 太陽火神的漂亮人生 本部落格專注於 敏捷開發及移動和物聯裝置研究 ios android html5 arduino pcduino,基類 title topic date data ty...
IOS Foundation 字串例項分析
1,基本字串操作 void basicstringmanipulation 2,字串字串操作 void showcasesubstrings 字串替代 nsstring replaced mystringstringbyreplacingoccurrencesofstring withstring ...