按位与或取反(|&~)在项目中的运用

  • (KKUserInfoShowMask)getUserInfoShowMaskWithIndexpath:(NSIndexPath *)indexPath andSwitchOn:(BOOL)isOn {
    NSString *title = self.sectionDatas[indexPath.section][indexPath.row];
    KKUserInfoShowMask mask;
    if ([title isEqualToString:KKLocalized(@"kPhone")]) {
    mask = KKUserInfoShowMaskMobile;
    } else if ([title isEqualToString:KKLocalized(@"kTel")]) {
    mask = KKUserInfoShowMaskTel;
    }else if ([title isEqualToString:KKLocalized(@"kPosition")]) {
    mask = KKUserInfoShowMaskPost;
    } else if ([title isEqualToString:KKLocalized(@"kEMail")]) {
    mask = KKUserInfoShowMaskEmail;
    } else if ([title isEqualToString:KKLocalized(@"kAddress")]) {
    mask = KKUserInfoShowMaskAddr;
    } else if ([title isEqualToString:KKLocalized(@"kJobNumber")]) {
    mask = KKUserInfoShowMaskStaffId;
    } else {
    mask = KKUserInfoShowMaskNone;
    }
    //当开启该位时 按位或
    //当关闭该位时,先按位取反,再按位与
    if (isOn) {
    return (self.userInfo.showMask | mask);
    } else {
    return self.userInfo.showMask & (~mask);
    }
    }

你可能感兴趣的:(按位与或取反(|&~)在项目中的运用)