Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YYClassPropertyInfo中按位或运算符 #310

Open
BlankConan opened this issue Jan 14, 2020 · 1 comment
Open

YYClassPropertyInfo中按位或运算符 #310

BlankConan opened this issue Jan 14, 2020 · 1 comment

Comments

@BlankConan
Copy link

BlankConan commented Jan 14, 2020

我想知道 YYClassPropertyInfo 在初始化的时候,对 type encoding 为什么使用 按位或的操作,为什么不直接对 type 赋值,这样做有什么好处吗?

          YYEncodingType type = 0;
            case 'R': {
                type |= YYEncodingTypePropertyReadonly;
            } break;
            case 'C': {
                type |= YYEncodingTypePropertyCopy;
            } break;
            case '&': {
                type |= YYEncodingTypePropertyRetain;
            } break;
            case 'N': {
                type |= YYEncodingTypePropertyNonatomic;
            } break;
            case 'D': {
                type |= YYEncodingTypePropertyDynamic;
            } break;
            case 'W': {
                type |= YYEncodingTypePropertyWeak;
            } break;
            case 'G': {
                type |= YYEncodingTypePropertyCustomGetter;
                if (attrs[i].value) {
                    _getter = NSSelectorFromString([NSString stringWithUTF8String:attrs[i].value]);
                }
            } break;

以及在 _YYModelPropertyMeta 的构造方法中:

    if ((meta->_type & YYEncodingTypeMask) == YYEncodingTypeObject) {
        meta->_nsType = YYClassGetNSType(propertyInfo.cls);
    }

希望大神们能解释一下,感谢!!!

@zengweijun
Copy link

zengweijun commented Jan 14, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants