masonry 代码中的装箱操作

equalTo(...)不能传数值参数,因为参数是 id 类型的。mas_equalTo(...) 可以传数值参数,因为mas_equalTo(...) 宏定义替换为一个equalTo(...)装箱操作。如下:

#define mas_equalTo(...)                equalTo(MASBoxValue((__VA_ARGS__)))

其中MASBoxValue((__VA_ARGS__))定义如下:

#define MASBoxValue(value) _MASBoxValue(@encode(__typeof__((value))), (value))

staticinlineid_MASBoxValue(constchar*type, ...) {

    va_list v;

    va_start(v, type);

    idobj =nil;

    if(strcmp(type,@encode(id)) ==0) {

        idactual =va_arg(v,id);

        obj = actual;

    }elseif(strcmp(type,@encode(CGPoint)) ==0) {

        CGPointactual = (CGPoint)va_arg(v,CGPoint);

        obj = [NSValuevalue:&actualwithObjCType:type];

    }elseif(strcmp(type,@encode(CGSize)) ==0) {

        CGSizeactual = (CGSize)va_arg(v,CGSize);

        obj = [NSValuevalue:&actualwithObjCType:type];

    }elseif(strcmp(type,@encode(MASEdgeInsets)) ==0) {

        MASEdgeInsets actual = (MASEdgeInsets)va_arg(v, MASEdgeInsets);

        obj = [NSValuevalue:&actualwithObjCType:type];

    }elseif(strcmp(type,@encode(double)) ==0) {

        doubleactual = (double)va_arg(v,double);

        obj = [NSNumbernumberWithDouble:actual];

    }elseif(strcmp(type,@encode(float)) ==0) {

        floatactual = (float)va_arg(v,double);

        obj = [NSNumbernumberWithFloat:actual];

    }elseif(strcmp(type,@encode(int)) ==0) {

        intactual = (int)va_arg(v,int);

        obj = [NSNumbernumberWithInt:actual];

    }elseif(strcmp(type,@encode(long)) ==0) {

        longactual = (long)va_arg(v,long);

        obj = [NSNumbernumberWithLong:actual];

    }elseif(strcmp(type,@encode(longlong)) ==0) {

        longlongactual = (longlong)va_arg(v,longlong);

        obj = [NSNumbernumberWithLongLong:actual];

    }elseif(strcmp(type,@encode(short)) ==0) {

        shortactual = (short)va_arg(v,int);

        obj = [NSNumbernumberWithShort:actual];

    }elseif(strcmp(type,@encode(char)) ==0) {

        charactual = (char)va_arg(v,int);

        obj = [NSNumbernumberWithChar:actual];

    }elseif(strcmp(type,@encode(bool)) ==0) {

        boolactual = (bool)va_arg(v,int);

        obj = [NSNumbernumberWithBool:actual];

    }elseif(strcmp(type,@encode(unsignedchar)) ==0) {

        unsigned char actual = (unsigned char)va_arg(v, unsigned int);

        obj = [NSNumbernumberWithUnsignedChar:actual];

    }elseif(strcmp(type,@encode(unsignedint)) ==0) {

        unsigned int actual = (unsigned int)va_arg(v, unsigned int);

        obj = [NSNumbernumberWithUnsignedInt:actual];

    }elseif(strcmp(type,@encode(unsignedlong)) ==0) {

        unsigned long actual = (unsigned long)va_arg(v, unsigned long);

        obj = [NSNumbernumberWithUnsignedLong:actual];

    }else if (strcmp(type, @encode(unsigned long long)) == 0) {

        unsigned long long actual = (unsigned long long)va_arg(v, unsigned long long);

        obj = [NSNumber numberWithUnsignedLongLong:actual];

    }elseif(strcmp(type,@encode(unsignedshort)) ==0) {

        unsigned short actual = (unsigned short)va_arg(v, unsigned int);

        obj = [NSNumbernumberWithUnsignedShort:actual];

    }

    va_end(v);

    returnobj;

}

你可能感兴趣的:(masonry 代码中的装箱操作)