iOS面试题,重要知识点整理

2016-07-25  本文已影响137人  eightzg

写在前面的话

为了找工作,找实习的同学一定在网上找了很多关于iOS的面试题,大部分的题都是千篇一律,或者就是没有答案。今天将自己总结数月的面试笔试题、知识点拿出来和大家分享,错误和遗漏之处还请多多指教。

1.NSObject中description属性的意义,它可以重写吗?
//通过重写person的description方法,在打印的时候就能输出person的name和age属性
- (NSString *)description{  
    return [NSString stringWithFormat:@"name = %@,age = %d", self.name,self.age];
}
2.单例模式的实现思路和代码(MRC)
// 用来保存唯一的单例对象
static id _instace;

//调用alloc方法的底层会调用allocWithZone:方法
+ (id)allocWithZone:(struct _NSZone *)zone
{
    //用GCD的一次性代码,防止多线程抢夺资源
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instace = [super allocWithZone:zone];
    });
    return _instace;
}

//设计一个类方法供对象的实例化
+ (instancetype)sharedTool
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instace = [[self alloc] init];
    });
    return _instace;
}

//在调用copy的底层会调用copyWithZone:方法,返回当前对象。
- (id)copyWithZone:(NSZone *)zone
{
    return _instace;
}

/*
 * 适配MRC。
 */
- (oneway void)release { }
- (id)retain { return self; }
- (NSUInteger)retainCount { return 1;}
- (id)autorelease { return self;}
3.retain的setter和getter方法

setter方法

- (void)setName:(NSString *)name {
    [_name release];    //旧值release
    [name retain];    //新值retain
    _name = name;    //把新值赋值给旧值
}

getter方法

- (NSString *)name {
    return [[_name retain] autorelease];
}
4.远程通知
5.动态绑定
6.事件传递链和响应者链

事件传递链

//调用UIView的hitTest方法进行触碰测试
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;

响应者链条

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
7.方法和选择器有什么不同
8.NSTimer不准的原因和解决办法

原因

解决

9.iOS数据持久化

encodeWithCoder告诉什么对象需要归档
initWithCoder。解档,解析文件的时候调用

10.写框架的时候注意点
11.数据库事务ACID
12.谓词(NSPredicate)
NSArray *array = [[NSArray alloc]initWithObjects:@"beijing",@"shanghai",@"guangzou",@"wuhan", nil]; 
NSString *string = @"ang";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF CONTAINS %@",string]; 
NSLog(@"%@",[array filteredArrayUsingPredicate:pred]);
上一篇 下一篇

猜你喜欢

热点阅读