收集iOS--基本数据类型

作者: TenMios | 来源:发表于2016-12-24 15:35 被阅读106次
面试:解释weak 和 assign 什么时候使用 Weak 和 assign
    @property (nonatomic, weak )UIView *view;
ARC 中才有weak MRC 没有
weak :弱指针,不会让引用计数器+1 , 如果指向对象被销毁,指针会自动清空。
assign: 很容易造成坏内存访问。     用的是  __unsafe_unretained(三年之前的经验) 修饰,不会让引用计数器+1 如果指向内存被销毁。指针不会清空。


/** VIP */
@property (nonatomic,assign,getter = isVip) BOOL vip;

if(status.isVip)
{
self.vipImageView.hidden =NO;
}else{
self.vipImageView.hidden =YES;
}
特定构造方法: 后面带有  NS_DESIGNATED_INITIALIZER  

1. 子类如果重写了父类的 【特定构造方法】 那么必须调用 super 调用 父类的指定构造方法。 不然会出现警告。 

@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   后面保留两位 



// 把字符串转成数值
NSInteger sum = [strString integerValue];
[floatValue doubleValue  intValue  longlongValue]


知识点:
if(username.length == 0)
    {
        [self showInfo:@"账号不能为空" message:@"提示" cancelMess:@"我知道了"];
        return; 
        //return 就不会提醒后面的信息了。
    }

 %.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] ; //返回的是数组, 把数组转成字符串

NSLog(@“%f”,sum);



 1. OC 提供基本数据类型  
int   整型  四个字节 (32位)  符号%d
float  = 59.5f  浮点数         符号%f
double   双精度浮点数 %f
 char = ^a^ 字符类型:一个字节(8位) 范围:-128 + 127   符号:%c

  其他类型 : id 类型:可以转化为任何数据类型。可以存放任何数据类型的对象。
                 (一个指向这种对象的实例变量的指针)   id 是一个指针  使用时候不用家*号   id foo = nil ;
 instancetype  类型: 代表任意的类型: 会返回真实的类型,只能用作返回值类型,不能作参数类型

Person *person = 【person new】  一步

Person *person = [[Person alloc] init ];两步

[Person alloc] 创建并分配内存 , 再利用init 方法初始化对象。

相关文章

网友评论

    本文标题:收集iOS--基本数据类型

    本文链接:https://www.haomeiwen.com/subject/gholvttx.html