Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ChenYilong/iOSInterviewQuestions
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: liruqi/iOSInterviewQuestions
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 16 commits
  • 3 files changed
  • 1 contributor

Commits on Oct 29, 2015

  1. 删除关于深拷贝相关的描述和代码

    文中的 `- deepCopy` 方法并不能实现深拷贝。
    
    `CYLUser` 的 `- copyWithZone` 方法里,`_friends` 成员的的赋值使用的 `- mutableCopy` 是浅拷贝,只是创建了`NSMutableSet` 对象;导致 `- deepCopy`方法中, _friends 的每一个对象的 _friends 列表并未创建实例。
    
    为了测试 `NSArray`, `NSSet` 容器类初始化行为,我写了测试代码,
    
    ```
        NSMutableArray *objects = [NSMutableArray array];
        [objects insertObject:[NSDate date] atIndex:0];
    
        if ([objects count] > 0) {
            NSArray *arr = [[NSArray alloc] initWithArray: objects];
            for (int i=0; i<arr.count; i++) {
                NSLog(@"%d %x %x", i, (uint) objects[i], (uint)arr[i]);
            }
            
            NSMutableSet* set = [[NSMutableSet alloc] initWithArray: objects];
            NSMutableSet* setcopy = [set mutableCopy];
            NSLog(@"set 1: %@ %x", set, (uint) [set allObjects][0]);
            NSLog(@"set 2: %@ %x", setcopy, (uint) [setcopy allObjects][0]);
        } 
    ```
    
    执行结果:
    ```
    2015-10-29 17:44:29.240 NSSpec[12024:438388] 0 2a43ec60 2a43ec60
    2015-10-29 17:44:29.241 NSSpec[12024:438388] set 1: {(
        2015-10-29 09:44:26 +0000
    )} 2a43ec60
    2015-10-29 17:44:29.241 NSSpec[12024:438388] set 2: {(
        2015-10-29 09:44:26 +0000
    )} 2a43ec60
    
    ```
    liruqi committed Oct 29, 2015
    Configuration menu
    Copy the full SHA
    e71a4b1 View commit details
    Browse the repository at this point in the history
  2. 更新 *重写带 copy 关键字的 setter* 的答案

    首先,if 的确比对象 copy 要快。
    另外,判断对象是否相同是为了保证代码执行的正确性。在非 ARC 环境下,如果穿入对象 retain count 为 1,不做判断的话,release 之后对象内存释放,下一步 copy 也会出错。
    liruqi committed Oct 29, 2015
    Configuration menu
    Copy the full SHA
    4127d6b View commit details
    Browse the repository at this point in the history
  3. Merge pull request #1 from liruqi/patch-2

    更新 *重写带 copy 关键字的 setter* 的答案
    liruqi committed Oct 29, 2015
    Configuration menu
    Copy the full SHA
    be757c7 View commit details
    Browse the repository at this point in the history

Commits on Oct 30, 2015

  1. Merge pull request #2 from liruqi/patch-1

    Correct answers
    liruqi committed Oct 30, 2015
    Configuration menu
    Copy the full SHA
    464da5a View commit details
    Browse the repository at this point in the history
  2. Fix links

    liruqi committed Oct 30, 2015
    Configuration menu
    Copy the full SHA
    ad9197a View commit details
    Browse the repository at this point in the history
  3. Clean up

    liruqi committed Oct 30, 2015
    Configuration menu
    Copy the full SHA
    9483218 View commit details
    Browse the repository at this point in the history
  4. Clean up

    liruqi committed Oct 30, 2015
    Configuration menu
    Copy the full SHA
    9354dd0 View commit details
    Browse the repository at this point in the history
  5. Remove hard link

    liruqi committed Oct 30, 2015
    Configuration menu
    Copy the full SHA
    48dce04 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    8ca28ac View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    a614da9 View commit details
    Browse the repository at this point in the history
  8. Add weak runtime impl link

    liruqi committed Oct 30, 2015
    Configuration menu
    Copy the full SHA
    082730b View commit details
    Browse the repository at this point in the history
  9. Clean up

    liruqi committed Oct 30, 2015
    Configuration menu
    Copy the full SHA
    38ddaf6 View commit details
    Browse the repository at this point in the history

Commits on Oct 31, 2015

  1. Fix hard link

    liruqi committed Oct 31, 2015
    Configuration menu
    Copy the full SHA
    7dcb9d0 View commit details
    Browse the repository at this point in the history
  2. Clean up

    liruqi committed Oct 31, 2015
    Configuration menu
    Copy the full SHA
    fe6813d View commit details
    Browse the repository at this point in the history

Commits on Nov 2, 2015

  1. Configuration menu
    Copy the full SHA
    365fe63 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    07dc88c View commit details
    Browse the repository at this point in the history
Loading