zoukankan      html  css  js  c++  java
  • [Objective-C 面试简要笔记]

    Obj-C:

    1.消息机制

    [shape draw]  向该对象发送消息,该对象查找并运行此函数

    差不多就是shape.draw();

    2.中缀语法

    [textThing setStringValue:@“Hello” color:[UIColor RedColor]];

    3.代码重构:

    减少重复代码,写成函数或者类

    4.类的复合

    汽车类由轮子类和车架类复合而成(伪多继承实现方式)

    11.selector响应选择器

    [car respondsToSelector:@selector(doxxx:)]

    12.Category(类别)和类扩展

    类别缺点:1.不能新加变量 2.重名会覆盖

    Things为已有类

    类别:(无法添加成员变量!)

    @interface Things(Plus){

    }

    进行类扩展如下:(可以添加成员变量!)

    @interface Things(){

    }

    13.协议和delegate委托(代理)

    协议:

    //协议定义

    @protocol UpdateAlertDelegate <NSObject>

    - (void)updateAlert;

    @end

    委托:协议基础上增加

    @interface TimerControl : NSObject

    //遵循协议的一个代理变量定义

    @property (nonatomic, weak) id<UpdateAlertDelegate> delegate;

    - (void) startTheTimer;

    @end

    14.block代码块:函数指针

    创建:

    int (^multiply_block)(int number)=^(int number){

    return (number*number);

    }

    调用:

    int result=multiply_block(5);

    创建block变量:

    typedef double (^MKSampleMultiply2BlockRef)(double c,double d);

    MKSampleMultiply2BlockRef multiply2={ return c *d ; };

    调用:

    multiply2(4,5);

    GCD多线程

    15.调度队列:

    1.连续队列

    dispatch_queue_t my_serial_queue= dispatch_queue_create(“myQueue”,NULL);

    2.并发队列

    = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY,0);

    3.主队列

    = dispatch_get_current_queue(void);

    4.获取当前队列

    = dispatch_get_current_queue();

    16.程序调度

    dispatch_block_t myBlock=^{ NSLog(@“A cute block!”) }

    Block异步:dispatch_async(_serial_queue,^{  NSLog(@“TASK1 ”);   });

    Block异步:dispatch_async(_serial_queue,myBlock);

    异步函数:dispatch_async_f(_serial_queue,(_bridge void*)[NSNumber numberWithInt:3],(dispatch_function_t)myDispatchFunction);

    队列暂停:

    dispatch_suspend(_serial_queue);

    队列重新开始

    dispatch_resume(_serial_queue);

    _bridge关键字

    告诉ARC交给系统管理内存

    17 操作队列 NSOperationQueue

    1.创建代码块操作

    NSBlockOperation *blockOperation=[NSBockOperation blockOperationWithBlock:^{

    }];

    2.[blockOperation addExecutionBlock:^{

    }];

    队列操作

    1.当前队列

    NSOperationQueue *currentQueue=[NSOperationQueue currentQueue];

    2.主队列

    [NSOperationQueue mainQueue];

    3.队列添加代码块

    [theQueue addOperation:blockOperation];

    [theQueue addOperation:^{

    nslog(@“aaa”);

    }];

  • 相关阅读:
    LeetCode "Jump Game"
    LeetCode "Pow(x,n)"
    LeetCode "Reverse Linked List II"
    LeetCode "Unique Binary Search Trees II"
    LeetCode "Combination Sum II"
    LeetCode "Divide Two Integers"
    LeetCode "First Missing Positive"
    LeetCode "Clone Graph"
    LeetCode "Decode Ways"
    LeetCode "Combinations"
  • 原文地址:https://www.cnblogs.com/rayshen/p/4547806.html
Copyright © 2011-2022 走看看