Code Monkey home page Code Monkey logo

ios-interview-question-answer's People

Contributors

liberalisman avatar ziyouzhe4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ios-interview-question-answer's Issues

16题答案有错误

在十六题的答案错误的是 FMDB是对sqlite3的封装 并不是对coredata的封装

看到第二个答案MVC时候的疑问

之前看斯坦福大学关于MVC模式的那个视频讲到MVC中的M和V之间是不允许通信的,而是通过C作为桥梁。所以,这里为什么说MVC模式所有的模块通信都是单向的?

NSMutableString *copyMutableString = [mutableCopyString copy];

NSString *string = @"测试数据";
NSString *copyString = [string copy];
NSMutableString *mutableCopyString = [string mutableCopy];
NSMutableString *copyMutableString = [string copy];
NSLog(@"%p,%p,%p,%p", string, copyString, mutableCopyString, copyMutableString);

第三行改一下 严谨一点

NSString *string = @"测试数据";
NSString *copyString = [string copy];
NSMutableString *mutableCopyString = [string mutableCopy];
NSMutableString *copyMutableString = [mutableCopyString copy];
NSLog(@"%p,%p,%p,%p", string, copyString, mutableCopyString, copyMutableString);

第5题解释的有些问题

5.NSString为什么要用copy关键字,如果用strong会有什么问题?
该题回答的不够全面。
NSString 使用 copy 和它的子类并没有关系,而且凡是 NSObject 都有 copy 方法,并不是 NSString 独有。
既然你提到了 NSMutableString,那么就应该会想到还有一个和 copy 对应的 mutableCopy 方法。
如下代码:

NSString *string = @"测试数据";
NSString *copyString = [string copy];
NSMutableString *mutableCopyString = [string mutableCopy];
NSMutableString *copyMutableString = [string copy];
NSLog(@"%p,%p,%p,%p", string, copyString, mutableCopyString, copyMutableString);

输出它们的地址,string 和 copyString 的地址是相同的,说明它们的指针指向同一个地址,也就是说 copy 是浅拷贝,即指针拷贝;mutableCopyString 和其他的地址都不一样,说明新开辟了一块内存空间,也就是和前两个没有任何关系,也就是说 mutableCopy 发生了深拷贝;copyMutableString 和其他的地址也不一样,同 mutableCopyString ,也是发生了深拷贝。
对于 copyString 和 copyMutableString 同是使用的 copy,但是地址却不一样,是因为苹果对于不可变的对象执行的引用操作,而对于可变对象,相对于之前的不可变对象,那么地址肯定会不一样,所以这个时候就要拷贝一份,和之前的就没有任何关系了。
还有就是属性中的 copy 关键字,如下代码:

@property (nonatomic, copy) NSString *copyString;
@property (nonatomic, strong) NSString *strongString;

对于上面的代码,copyString 和 strongString 的 set 方法中,

-(void)setCopyString:(NSString *)copyString {
    _copyString = [copyString copy];  // 调用 copy 方法,所以并不是直接赋值
}
-(void)setStrongString:(NSString *)strongString {
    _strongString = strongString;  // 直接引用
}

如果想要外界赋值的值对 string 有影响,那么就用 strong,这样两者相当于还是一个对象,如果在赋值以后不想要外界再对string 有影响,那么就用 copy。也就是说用 strong 还是 copy 可以根据情况而定。

第 19题 参考答案

遵循三个规则(约束条件)

  1. 子类如果有指定初始化函数,那么指定初始化函数实现时必须调用它的直接父类的指定初始化函数。
  2. 如果子类有指定初始化函数,那么便利初始化函数必须调用自己的其它初始化函数(包括指定初始化函数以及其他的便利初始化函数),不能调用super的初始化函数。
  3. 如果子类提供了指定初始化函数,那么一定要实现所有父类的指定初始化函数。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.