copy:複製乙份新的
assign:指標指向同一位址
2.weak+strong
本地變數前面要加兩個下劃線,成員變數不用加
nsmutablestring
*str=[
nsmutablestring
stringwithformat
:@"%@"
,@"test"
];//「=」後的部分建立乙個臨時變數,引用計數加1;再賦值,引用計數又加1
nslog(
@"str %ld"
,cfgetretaincount((
__bridge
cftyperef
) str));
__weak
nsmutablestring *weakstr=str;
nslog
(@"str %ld"
,cfgetretaincount
((__bridge
cftyperef
) str));//檢視str的retaincount,為2;如果是weakstr的retaincount則不一定
__weak
nsmutablestring *weakstr2=str;
nslog(@"weakstr2 %ld",cfgetretaincount((__bridge
cftyperef) weakstr2));
__weak
nsmutablestring *weakstr3=weakstr;
//指向weak reference的weak reference,會對引用計數加1
nslog(
@"str %ld"
,cfgetretaincount((
__bridge
cftyperef
) str));
__strong
nsmutablestring
*strongstr=str;//每用一次strong則相當於對str retain一次
1.構造多個nsmutablestring
2.構造乙個nsarray
3.把nsmutablestring物件新增到nsarray
4.檢視nsmutablestring的retaincount
nsmutablestring*s1=[nsmutablestring
stringwithformat
:@"%@"
,@"one"];
nsmutablestring*s2=[nsmutablestring
stringwithformat
:@"%@"
,@"two"];
nsmutablestring*s3=[nsmutablestring
stringwithformat
:@"%@"
,@"three"];
nsarray
*array=[[
nsarray
alloc
]initwithobjects
:s1,s2,s3,
nil];//字串的所有權歸array,s1,s2,s3的retaincount加1
nslog(
@"%d"
,[s1retaincount]);
[s1release
];[s2
release
];[s3
release
];//這個時候字串release,則在array銷毀後字串的retaincount也變為0
nslog(
@"%d"
,[s1retaincount]);
output:2 1
把nsarray改為nsmutablearray:
5.nsarray移除相應的nsmutablestring
6.檢視相應的nsmutablestring的retaincount
nsmutablearray *array=[[nsmutablearray
alloc] initwithobjects:s1,s2,s3, nil];
nslog(
@"%d"
,[s1retaincount]);
[array removeobject:s1];
nslog(
@"%d"
,[s1retaincount]);
output:2 1
可以用索引輸出:
nslog(@"%@",array[0]);
4.nsnumber
用nsnumber類來用物件導向的方法處理數字。如果你只需要簡單的數字(而不是物件),用nsinterger類來操作有符號數(正數或者負數),用nsuinterger類來操作無符號數(正數或0),用cgfloat類和double來操作浮點數。
numberwithint:將乙個整數值封裝成乙個
nsnumber例項;
numberwithunsignedint:將乙個無符號整數值(正數或0)封裝成乙個
nsnumber例項;
numberwithfloat:將乙個浮點數封裝成乙個
nsnumber例項;
numberwithdouble:將乙個double型別的數封裝成乙個nsnumber例項;
intvalue:從呼叫該函式的nsnumber例項中返回乙個整型nsiteger型別值。
unsignedintvalue:從呼叫該函式的nsnumber例項中返回乙個無符號整型nsiteger型別值。
floatvalue:從呼叫該函式的nsnumber例項中返回乙個浮點數cgfloat型別值。
doublevalue:從呼叫該函式的nsnumber例項中返回乙個雙精度double型別值。
5.nsdictionary
nsarray *a1=[[nsarray
alloc]initwithobjects:@"1",@"2",@"3",nil];//objectforkey
nsarray *a2=[[nsarray
alloc] initwithobjects:@"a",@"b",@"c",nil];//keys
nsdictionary
*dic=[
nsdictionary
dictionarywithobjects:a1forkeys:a2];
for(id
keyindictionary
in[dic
allkeys
])//[dic allkeys]把所有的key取出來,利用in keyindictionary裡存從[dic allkeys]乙個個取出的key,id可換為任意型別,此處可換為nsstring
//其它還有多種方法
學習IOS的第三天
今天主要學習 設定器 setter 和 訪問器 getter 1.設定器 void set首字母大寫的例項變數 例項變數的返回值型別 去掉下劃線的例項變數名 2.訪問器 例項變數的返回值型別 去掉下劃線的例項變數名 在.h檔案中 void setname nsstring name 設定器 nsst...
學習第三天
額,又是美好的一天!祝賀比利時奪得季軍!下面,還是先看資訊學 今天繼續看倍增。這道題是和倍增沾邊的題,額,其實就是兩邊floyd。但是思路還是可以借鑑的。這道的思路是,使用兩個陣列,乙個是f k u v 這個陣列表示節點u到節點v之間是否距離為2 k,如果是,則為1,否則為0.代表u和v之間是否1s...
學習第三天
等價類是建立在這種思想之上 即我們不可能進行窮舉測試,那麼我們就 必須對輸入進行分類,而這種分類是建立在我們知道計算機程式設計原理和 計算機處理單元的工作原理基礎之上的,程式是通過資料結構和演算法來實現 的,計算機是按照演算法來執行程式的,這種執行是穩定的,不會因為我們的 輸入而導致計算機處理不穩定...