Before the order

Some time ago, DUE to the needs of the course, I issued a set of iOS exam papers, thinking that VIP students did a very good job. With the spirit of sharing also open source out a set of iOS bottom test paper – I want to share with you the results of the response is huge! A lot of beautiful young beautiful female in succession private chat me…. It can be roughly divided into the following two types:

  • 1: Cooci aren't you exacerbating intra-industry roll-up??
  • 2: Cooci, your test paper is really good. I will study hard if there are any answers

Based on the above two kinds of feedback, I simply plan to open source a set of exams, let the inner paper come more fierce!! 😁 😁 😁

Introduction to the second exam of the master class

The normal exam is divided into four types of questions. 200 out of 100 (don’t ask me why IT’s not 100, eh… Is play!!!!!!!!!! 😸)

  • 1. Multiple choice questions (5 points for each question, a total of 7 questions 35 points)

  • 2. Judging questions (5 points for each question, a total of 6 questions 30 points)

  • 3, simple questions (12 points for each question, a total of 10 questions 120 points)

  • 4. Expand the full score (15 points)

IOS – KvC-kVO – multi-threaded – CD – Block

I will post the topic below, if you have time, might as well take a pen notebook test, see how many points can do, in the article message I will send you the first time the answer! Or add me to wechat: KC_Cooci


1. Multiple Choice questions (5 points for each question)

  1. LGTeacherInheritance inLGPersonWhy is () worth 5 points
LGTeacher *t = [[LGTeacher alloc] init];

- (instancetype)init{
    self = [super init];
    if (self) {
        NSLog(@"%@ - %@",[self class],[super class]);
    }
    return self;
}
Copy the code
  • A: LGTeacher – LGTeacher

  • B: LGTeacher – LGPerson

  • C: LGTeacher – NSObject

  • D: LGTeacher – it can output whatever it likes, I don’t know

  1. The following code can be executed normally and the output () score is 5 points
@interface LGPerson : NSObject
@property (nonatomic, retain) NSString *kc_name;
- (void)saySomething;
@end

@implementation LGPerson
- (void)saySomething{ 
    NSLog(@"%s - %@",__func__,self.kc_name);
}
@end


- (void)viewDidLoad {
    [super viewDidLoad] ;
    
    Class cls = [LGPerson class];
    void  *kc = &cls;
    [(__bridge id)kc saySomething];
}
Copy the code
  • A: – ViewController

  • B: can you – null

  • C: Yes – ViewController: 0x7FF8D240ad30

  • D: Can you run it by yourself? You have to ask me – it can output whatever it likes, I don’t know

  1. The following code is executed. What is the output of the console
NSObject *objc = [NSObject new];
NSLog(@"%ld",CFGetRetainCount((__bridge CFTypeRef)(objc)));

void(^block1)(void) = ^{
    NSLog(@"---%ld",CFGetRetainCount((__bridge CFTypeRef)(objc)));
};
block1();

void(^__weak block2)(void) = ^{
    NSLog(@"---%ld",CFGetRetainCount((__bridge CFTypeRef)(objc)));
};
block2();

void(^block3)(void) = [block2 copy];
block3();

__block NSObject *obj = [NSObject new];
void(^block4)(void) = ^{
    NSLog(@"---%ld",CFGetRetainCount((__bridge CFTypeRef)(obj)));
};
block4();
Copy the code
  • A: 1 2 2 2 2

  • B: 1 2 3 3 2

  • C: 1 3 3 4 1

  • D: 1 3 4 5 1

  1. The following code is executed. What is the output of the console
- (void)MTDemo{
    while (self.num < 5) {
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            self.num++;
        });
    }
    NSLog(@"KC : %d",self.num);
}

- (void)KSDemo{
   
    for (int i= 0; i<10000; i++) {
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            self.num++;
        });
    }
    NSLog(@"Cooci : %d",self.num);
}
Copy the code
  • A: 0 , 10000

  • B: 0 , <10000

  • C: <=5 , <10000

  • D: >=5 , <10000

  1. The following code is executed. What is the output of the console
- (void)textDemo2{
    dispatch_queue_t queue = dispatch_queue_create("cooci", DISPATCH_QUEUE_CONCURRENT);
    NSLog(@"1");
    dispatch_async(queue, ^{
        NSLog(@"2");
        dispatch_sync(queue, ^{
            NSLog(@"3");
        });
        NSLog(@"4");
    });
    NSLog(@"5");
}

- (void)textDemo1{
    
    dispatch_queue_t queue = dispatch_queue_create("cooci", NULL);
    NSLog(@"1");
    dispatch_async(queue, ^{
        NSLog(@"2");
        dispatch_sync(queue, ^{
            NSLog(@"3");
        });
        NSLog(@"4");
    });
    NSLog(@"5");
}
Copy the code
  • A: 1 5 2 3 4 , 1 5 2

  • B: 1, 5, 2, 4, 3, deadlock collapse

  • C: 1, 5, 2, 3, 4, deadlock collapse

  • D: 1, 5, 2, 3, deadlock collapse

  1. The following code is executed. What is the output of the console
@property (nonatomic, strong) NSMutableArray *mArray; - (NSMutableArray *)mArray{ if (! _mArray) _mArray = [NSMutableArray arrayWithCapacity:1]; return _mArray; } - (void)viewDidLoad { [super viewDidLoad]; NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"1",@"2", nil]; self.mArray = arr; void (^kcBlock)(void) = ^{ [arr addObject:@"3"]; [self.mArray addObject:@"a"]; NSLog(@"KC %@",arr); NSLog(@"Cooci: %@",self.mArray); }; [arr addObject:@"4"]; [self.mArray addObject:@"5"]; arr = nil; self.mArray = nil; kcBlock(); }Copy the code
  • A: 1 2 4 5 3 , nil

  • B: 1 2 4 5 3 , a

  • C: 1 2 4 5 3 , 1 2 4 5 3 a

  • D: 1 2 4 5 3 a , 1 2 4 5 3 a

Ii. Judgment questions (5 points for each question)

  1. Mutable array threads are safe () points worth 5 points
  1. A deadlock is generated when the main queue is paired with a synchronization function
  1. The following code will execute without error () score is 5 points
int a = 0;
void(^ __weak weakBlock)(void) = ^{
    NSLog(@"-----%d", a);
};

struct _LGBlock *blc = (__bridge struct _LGBlock *)weakBlock;
id __strong strongBlock = [weakBlock copy];
blc->invoke = nil;
void(^strongBlock1)(void) = strongBlock;
strongBlock1();
Copy the code
  1. The following code will execute without error () score is 5 points
NSObject *a = [NSObject alloc];
void(^__weak block1)(void) = nil;
{
    void(^block2)(void) = ^{
        NSLog(@"---%@", a);
    };
    block1 = block2;
    NSLog(@"1 - %@ - %@",block1,block2);
}
block1();
Copy the code
  1. The following code generates a circular reference () score of 5 points
__weak typeof(self) weakSelf = self;
self.doWork = ^{
    __strong typeof(self) strongSelf = weakSelf;
    weakSelf.doStudent = ^{
        NSLog(@"%@", strongSelf);
    };
   weakSelf.doStudent();
};
self.doWork();
Copy the code
  1. Is there a problem with the following code? () The score is 5 points
- (void)demo3{ dispatch_queue_t concurrentQueue = dispatch_get_global_queue(0, 0); for (int i = 0; i<5000; i++) { dispatch_async(concurrentQueue, ^{ NSString *imageName = [NSString stringWithFormat:@"%d.jpg", (i % 10)]; NSURL *url = [[NSBundle mainBundle] URLForResource:imageName withExtension:nil]; NSData *data = [NSData dataWithContentsOfURL:url]; UIImage *image = [UIImage imageWithData:data]; dispatch_barrier_async(concurrentQueue, ^{ [self.mArray addObject:image]; }); }); }}Copy the code
  1. The following code does not generate a circular reference () score of 5 points
static ViewController *staticSelf_;

- (void)blockWeak_static {
    __weak typeof(self) weakSelf = self;
    staticSelf_ = weakSelf;
}
Copy the code

3. Simple questions (10 points for each question)

Please treat it as an interview and take it seriously. Please be patient and avoid impetuousness.

  • 1, please use GCD to implement read/write lock, explain why the design is worth 10 points

  • 2. Why is the maximum score of @synchronized 10 points

  • 3. How many types of blocks are eligible for differentiation? Score 10 points

  • 4, KVC ordinary object setter process score value of 10 points

  • 5. The score of KVO underlying principle and mechanism analysis is 10

  • 6. What is the stack frame loading situation of the following code? Score 10 points

- (void)viewDidLoad { 
    [super viewDidLoad] ; 
    
    
    Class cls = [LGPersonP class];
    void  *kc = &cls;
    [(__bridge id)kc saySomething]; 
    
    LGPersonP *person = [LGPersonP alloc];
}
Copy the code
  • 7. How to keep iOS threads alive, and why should the thread alive score be 10 points

  • 8, circular reference, why add strong to block, not add 10 points

  • 9. Have you used dispatch_once? Know the bottom? How do you implement one? Score 10 points

  • What is the principle of iOS multi-threading and thread lifecycle

  • 11. Please briefly describe the principle value of semaphore and scheduling group 10 points

  • 12. Briefly describe the __block modifier after it is captured by a block. 10 points

4. Expand the full score (15 points)

  1. What are your plus points and strengths as a mid-level iOS developer?

PS:

Congratulations on finishing, this problem is a bit difficult, but if you can do it quickly and reach around 150! I believe your next iOS development should not be too difficult (you can develop well without 150)

Of course, there will be a lot of beautiful boy will have some problems, need to answer the paper of the beautiful boy, with the article like screenshots to find me: KC_Cooci to send you in PDF form! Come on, pretty boy pretty girl…..