ios技术面试题

1.Difference between shallow copy and deep copy?

浅复制 只拷贝地址 不拷贝地址指向的对象

深复制 拷贝地址 并且指向拷贝的新对象

2.What is advantage of categories? What is difference between implementing a category and inheritance?

categories: 在不影响或修改原来的类别或模组的情况下去修改原有的功能,增加新的功能

3.Difference between categories and extensions?

categories: 在不影响或修改原来的类别或模组的情况下去修改原有的功能,增加新的功能

4.Difference between protocol in objective c and interfaces in java?

暂时觉得它们是一样的 protocol 可以被继承 interfaces 不可以

在java 中的interfaces 在 objective-c 中就是 protocol

在java 中的 class 在 objective-c 中就是 interface

5.What are KVO and KVC?

转自 http://magicalboy.com/kvc_and_kvo/

一个对象拥有某些属性。比如说,一个 Person 对象有一个 name 和一个 address 属性。以 KVC 说法,Person 对象分别有一个 value 对应他的 name 和 address 的 key。 key 只是一个字符串,它对应的值可以是任意类型的对象。从最基础的层次上看,KVC 有两个方法:一个是设置 key 的值,另一个是获取 key 的值。如下面的例子:

Java代码  

  1. void changeName(Person *p, NSString *newName)
  2. {
  3. // using the KVC accessor (getter) method
  4. NSString *originalName = [p valueForKey:@"name"];
  5. // using the KVC  accessor (setter) method.
  6. [p setValue:newName forKey:@"name"];
  7. NSLog(@"Changed %@‘s name to: %@", originalName, newName);
  8. }

现在,如果 Person 有另外一个 key 配偶(spouse),spouse 的 key 值是另一个 Person 对象,用 KVC 可以这样写:

Java代码  

  1. void logMarriage(Person *p)
  2. {
  3. // just using the accessor again, same as example above
  4. NSString *personsName = [p valueForKey:@"name"];
  5. // this line is different, because it is using
  6. // a "key path" instead of a normal "key"
  7. NSString *spousesName = [p valueForKeyPath:@"spouse.name"];
  8. NSLog(@"%@ is happily married to %@", personsName, spousesName);
  9. }

Key-Value Observing (KVO) 建立在 KVC 之上,它能够观察一个对象的 KVC key path 值的变化。举个例子,用代码观察一个 person 对象的 address 变化,以下是实现的三个方法:

  • watchPersonForChangeOfAddress: 实现观察
  • observeValueForKeyPath:ofObject:change:context: 在被观察的 key path 的值变化时调用。
  • dealloc 停止观察static NSString *const KVO_CONTEXT_ADDRESS_CHANGED = @"KVO_CONTEXT_ADDRESS_CHANGED"

    Java代码  

    1. @implementation PersonWatcher
    2. -(void) watchPersonForChangeOfAddress:(Person *)p
    3. {
    4. // this begins the observing
    5. [p addObserver:self
    6. forKeyPath:@"address"
    7. options:0
    8. context:KVO_CONTEXT_ADDRESS_CHANGED];
    9. // keep a record of all the people being observed,
    10. // because we need to stop observing them in dealloc
    11. [m_observedPeople addObject:p];
    12. }
    13. // whenever an observed key path changes, this method will be called
    14. - (void)observeValueForKeyPath:(NSString *)keyPath
    15. ofObject:(id)object
    16. change:(NSDictionary *)change
    17. context:(void *)context
    18. {
    19. // use the context to make sure this is a change in the address,
    20. // because we may also be observing other things
    21. if(context == KVO_CONTEXT_ADDRESS_CHANGED) {
    22. NSString *name = [object valueForKey:@"name"];
    23. NSString *address = [object valueForKey:@"address"];
    24. NSLog(@"%@ has a new address: %@", name, address);
    25. }
    26. }
    27. -(void) dealloc;
    28. {
    29. // must stop observing everything before this object is
    30. // deallocated, otherwise it will cause crashes
    31. for(Person *p in m_observedPeople){
    32. [p removeObserver:self forKeyPath:@"address"];
    33. }
    34. [m_observedPeople release];
    35. m_observedPeople = nil;
    36. [super dealloc];
    37. }
    38. -(id) init;
    39. {
    40. if(self = [super init]){
    41. m_observedPeople = [NSMutableArray new];
    42. }
    43. return self;
    44. }
    45. @end

    这就是 KVO 的作用,它通过 key path 观察对象的值,当值发生变化的时候会收到通知。

6.What is purpose of delegates?

7.What are mutable and immutable types in Objective C?

8.When we call objective c is runtime language what does it mean?

9.what is difference between NSNotification and protocol?

10.What is push notification?

11.Polymorphism?

12.Singleton?

单例

13.What is responder chain?

14.Difference between frame and bounds?

15.Difference between method and selector?

16.Is there any garbage collection mechanism in Objective C.?

17.NSOperation queue?

18.What is lazy loading?

19.Can we use two tableview controllers on one viewcontroller?

20.Can we use one tableview with two different datasources? How you will achieve this?

21.What is advantage of using RESTful webservices?

22.When to use NSMutableArray and when to use NSArray?

23.What is the difference between REST and SOAP?

24.Give us example of what are delegate methods and what are data source methods of uitableview.

25.How many autorelease you can create in your application? Is there any limit?

26.If we don’t create any autorelease pool in our application then is there any autorelease pool already provided to us?

27.When you will create an autorelease pool in your application?

28.When retain count increase?

29.Difference between copy and assign in objective c?

30.What are commonly used NSObject class methods?

31.What is convenience constructor?

32.How to design universal application in Xcode?

33.What is keyword atomic in Objective C?

34.What are UIView animations?

35.How can you store data in iPhone applications?

36.What is coredata?

37.What is NSManagedObject model?

38.What is NSManagedobjectContext?

39.What is predicate?

40.What kind of persistence store we can use with coredata?

时间: 2024-07-30 12:21:53

ios技术面试题的相关文章

阿里百度12个iOS 技术面试题及答案总结,希望对你有帮助!

前言 随着移动互联网科技不断的发展和创新,如今无论是公司还是开发者或设计师个人而言,面试都是一项耗时耗钱的项目,而面对iOS开发者及设计师在面试时可能会遇到的问题进行了筛选与汇总.下面我们一起来一下看看吧. 一.如何绘制UIView? 绘制一个UIView最灵活的方法就是由它自己完成绘制.实际上你不是绘制一个UIView,而是子类化一个UIView并赋予绘制自己的能力.当一个UIView需要执行绘制操作时,drawRect:方法就会被调用,覆盖此方法让你获得绘图操作的机会.当drawRect:方

最全的iOS面试题及答案-转载

1. Object-c的类可以多重继承么?可以实现多个接口么?Category是什么?重写一个类的方式用继承好还是分类好?为什么? 答: Object-c的类不可以多重继承:可以实现多个接口,通过实现多个接口可以完成C++的多重继承:Category是类别,一般情况用分类好,用Category去重写类的方法,仅对本Category有效,不会影响到其他类与原有类的关系. 2. #import 跟#include 又什么区别,@class呢, #import<> 跟 #import””又什么区别?

iOS面试题之加载单张图片到底会不会崩溃?

今天,一哥们去某公司面试iOS职位.其中一道题目问,加载一张图片,到底会不会崩溃呢? 我拿到这个问题,当时以为是获取网络图片,那还是可能崩溃的,但实际问题,还有半句,图片是本地的... 这问题,加载本地的怎么会崩溃呢?写这么久加载图片也没遇到如此问题. =================================================== 原来,iPhone毕竟是手持设备,它所占有的内存是有限的,当图片过大的时候会引起内存导致的崩溃现象. 后来,我又查了下,发现,原来还有这么大学

iOS面试题 第一天

今天上午,下午分别面试了两家公司.上午是一家互联网公司,气氛还比较好,是我比较喜欢的.技术这块是直接机试,主要是给了些BUG让我修复,整个过程还算顺利.下午去了一家大型的证券公司.整理技术问题如下: 1. UIView的生命周期是什么样的,执行顺序是怎么样的?init -- loadView -- viewDidLoad -- viewWillAppear -- viewWillDisappear -- viewDidUnload -- dealloc. 2. UIViewController在

iOS 面试题 总结

#include <iostream> using namespace std; int main () { char p[]={'a','b','c'}, q[]="abc"; printf("%d %d\n",sizeof(p),sizeof(q)); //getch(); } //结果 3,4 sizeof有什么作用呢? sizeof是C语言的关键字不并不是函数,这个很容易被忽略 sizeof(a)表示a在内存中所占的字节数 以下是windows

iOS 面试题:OC基本概念题

1.什么是类和对象? 类是一组具有同样特征和功能的事物的抽象 对象描写叙述了一个物体的特征和行为实现 类是对象的抽象 对象是类的实例 2.OC中定义类,创建对象,使用对象. OC中定义类分为接口部分,实现部分 接口部分:对外声明类的特征和行为 实现部分:实现方法,即类的行为实现 创建对象须要进行分配内存空间和初始 3.声明方法,依据需求.区分:方法声明,方法实现,方法运行 4.继承.继承的全部特点 子类能够继承父类全部的声明的方法和除私有的以外实例变量 父类不能使用子类所创建的方法和实例变量 5

一些iOS面试题及简要回答

1. #import 跟#include.@class有什么区别?#import<> 跟 #import""又什么区别? 1> #import和#include都能完整地包含某个文件的内容,#import能防止同一个文件被包含多次 2> @class仅仅是声明一个类名,并不会包含类的完整声明;@class还能解决循环包含的问题 3> #import <> 用来包含系统自带的文件,#import ""用来包含自定义的文件 2.

原 iOS面试题收集

原 iOS面试题收集 发表于2年前(2013-07-22 13:47)   阅读(369) | 评论(0) 4人收藏此文章, 我要收藏 赞0 听云性能监测产品App.Server.CDN免费试用,绑定账号送京东卡 iOS 面试题 Objective-C 1.ARC 是什么? ARC 是 iOS 5 推出的新功能,全称叫 ARC(Automatic Reference Counting).简单 地说,就是代码中自动加入了 retain/release,原先需要手动添加的用来处理内存管 理的引用计数

[转载]iOS面试题总

转载自:http://blog.sina.com.cn/s/blog_67eb608b0101r6xb.html (2014-06-13 20:23:33) 转载▼ 标签: 转载   crash 原文地址:iOS面试题总作者:唯一的弟子 1.简述OC中内存管理机制.与retain配对使用的方法是dealloc还是release,为什么?需要与alloc配对使用的方法是dealloc还是release,为什么?readwrite,readonly,assign,retain,copy,nonato