iOS 2015-3-9笔记

本文详细介绍了枚举赋值的使用方法及左移位运算的优点,并阐述了NSHashTable作为代理列表的实现方式及其特点。同时,强调了用户队列与全局队列的区别与优势。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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(@"有序");

    });





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值