面試:解釋weak 和 assign 什么時(shí)候使用 Weak 和 assign
@property (nonatomic, weak )UIView *view;
ARC 中才有weak MRC 沒(méi)有
weak :弱指針,不會(huì)讓引用計(jì)數(shù)器+1 羹膳, 如果指向?qū)ο蟊讳N(xiāo)毀贤斜,指針會(huì)自動(dòng)清空睁宰。
assign: 很容易造成壞內(nèi)存訪問(wèn)。 用的是 __unsafe_unretained(三年之前的經(jīng)驗(yàn)) 修飾,不會(huì)讓引用計(jì)數(shù)器+1 如果指向內(nèi)存被銷(xiāo)毀爹土。指針不會(huì)清空。
/** VIP */
@property (nonatomic,assign,getter = isVip) BOOL vip;
if(status.isVip)
{
self.vipImageView.hidden =NO;
}else{
self.vipImageView.hidden =YES;
}
特定構(gòu)造方法: 后面帶有 NS_DESIGNATED_INITIALIZER
1. 子類(lèi)如果重寫(xiě)了父類(lèi)的 【特定構(gòu)造方法】 那么必須調(diào)用 super 調(diào)用 父類(lèi)的指定構(gòu)造方法踩身。 不然會(huì)出現(xiàn)警告胀茵。
@property ( nonatomic , weak ) UILabel *label;
@property ( nonatomic , strong ) NSDate * created_Time;
@property ( nonatomic , strong ) NSArray * array;
/** 名字 */
@property (nonatomic, copy) NSString * name ;
NSLog(“%@”, p.name)
/** 年齡 */
@property (nonatomic, assign ) NSInteger age ;
NSLog(“%zd”, p.age)
@property (nonatomic, assign ) double price ; 20.5 %f
@property (nonatomic, assign ) CGRect iconFrame
@property (nonatomic, assign ) float money ; %.2f 后面保留兩位
// 把字符串轉(zhuǎn)成數(shù)值
NSInteger sum = [strString integerValue];
[floatValue doubleValue intValue longlongValue]
知識(shí)點(diǎn):
if(username.length == 0)
{
[self showInfo:@"賬號(hào)不能為空" message:@"提示" cancelMess:@"我知道了"];
return;
//return 就不會(huì)提醒后面的信息了。
}
%.2f 后面保留兩位 32.21
%02zd 05
%zd NSInteger result
%lu [str.length count]
{
int _age
double _height
double _weight
NSString *name
NSString *_tel
NSString *_email
}
age = %i height =%f
%i %p 輸出地址
NSString *str =[[Person alloc] init]
NSUInteger length = [str length];
NSLog(@“%lu”,length)
double sum = [[ p valueForKeyPath:@“books.@sum.price”] doubleValue] ; //返回的是數(shù)組挟阻, 把數(shù)組轉(zhuǎn)成字符串
NSLog(@“%f”琼娘,sum);
1. OC 提供基本數(shù)據(jù)類(lèi)型
int 整型 四個(gè)字節(jié) (32位) 符號(hào)%d
float = 59.5f 浮點(diǎn)數(shù) 符號(hào)%f
double 雙精度浮點(diǎn)數(shù) %f
char = ^a^ 字符類(lèi)型:一個(gè)字節(jié)(8位) 范圍:-128 + 127 符號(hào):%c
其他類(lèi)型 : id 類(lèi)型:可以轉(zhuǎn)化為任何數(shù)據(jù)類(lèi)型峭弟。可以存放任何數(shù)據(jù)類(lèi)型的對(duì)象脱拼。
(一個(gè)指向這種對(duì)象的實(shí)例變量的指針) id 是一個(gè)指針 使用時(shí)候不用家*號(hào) id foo = nil ;
instancetype 類(lèi)型: 代表任意的類(lèi)型: 會(huì)返回真實(shí)的類(lèi)型瞒瘸,只能用作返回值類(lèi)型,不能作參數(shù)類(lèi)型
Person *person = 【person new】 一步
Person *person = [[Person alloc] init ]熄浓;兩步
[Person alloc] 創(chuàng)建并分配內(nèi)存 情臭, 再利用init 方法初始化對(duì)象。
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者