iOS 2015-3-9笔记

来源:互联网 发布:淘宝搜索词查询在哪里 编辑:程序博客网 时间:2024/05/20 23:33
1.枚举赋值用法   

0x1       = 1 (0001)

0x1 << 1  = 2 (0010)

0x1 << 2  = 4 (0100)

0x1 << 3  = 8 (1000)

typedef enum {

    

    MessageNotificationTypePraise =0x1,

    MessageNotificationTypeUpPopular =0x1 <<1,

    MessageNotificationTypeFriendAdd =0x1 <<2,

    MessageNotificationTypeFriendAdded =0x1 <<3,

    MessageNotificationTypeActivityUpdate =0x1 <<4,

    MessageNotificationTypeNewFriendActivity =0x1 <<5,

    MessageNotificationTypeGerenalFriendWatchTimesRestore =0x1 <<6,

    MessageNotificationTypeBeAccept =0x1 <<7,

    MessageNotificationTypeTo_evaluate_friend =0x1 <<8,

    MessageNotificationTypeCongenial_person =0x1 <<9,

    

    MessageNotificationTypeBeValuate =0x1 <<kMessageNotifityTypeOffsetMax,

    MessageNotificationTypeAll =0x7F,

    

}MessageNotificationType;

优点:左移位一位  做 与或 运算方便!

2.hash表做代理列表

NSHashTable是可变的
* NSHashTable可以持有weak类型的成员变量(delegate只能为weak类型)
* NSHashTable可以在添加成员变量的时候复制成员
* NSHashTable可以随意的存储指针并且利用指针的唯一性来进行hash同一性检查(检查成员变量是否有重复)和对比操作(equal)

@property (nonatomic,strong)NSHashTable *delegateList;

添加:[self.delegateListaddObject:delegate];

回调:

- (void)callbackDelegates:(NSHashTable *)delegates withSelector:(SEL)selector withObject:(id)obj withObject:(id)obj1

{

    if (delegates.count >0)

    {

        for (id<MSPushModelManagerDelegate> delegatein delegates)

        {

            if ([delegate respondsToSelector:selector])

            {

                void (*callFunction)(id,SEL,id, id) = (void (*)(id,SEL,id, id))objc_msgSend;

                callFunction(delegate, selector, obj, obj1);

            }

        }

    }


}

3.用户队列使用:

self.contactMainQueue =dispatch_queue_create("com.contact.contactMain",DISPATCH_QUEUE_SERIAL);

注意:apple推荐用倒置域名来命名 方便调试的时候输出
优点:跟全局队列相比,用户队列是有序的

#pragma mark - 线程处理

void processToQueue(dispatch_queue_t queue,void(^block)(void))

{

    dispatch_async(queue, block);

}


processToQueue(self.contactMainQueue, ^{

        NSLog(@"有序");

    });





0 0
原创粉丝点击