美文网首页
if-else后面一定要带上{}

if-else后面一定要带上{}

作者: SDBridge | 来源:发表于2017-04-06 22:13 被阅读17次

    今天遇到一个坑
    在 用Xtrace 分析MJRefresh代码的时候,由于对NSLog进行宏定义

    #define NSLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
    

    然而

     for ( int l=0 ; l<levels ; l++ ) {
    
            if ( !swizzledClasses[aClass] && !exists( excludedClasses, aClass ) ) {
                unsigned mc = 0;
                const char *className = class_getName(aClass);
                Method *methods = class_copyMethodList(aClass, &mc);
    
               for( unsigned i=0; methods && i<mc; i++ ) {
                    const char *type = method_getTypeEncoding(methods[i]);
                    const char *name = sel_getName(method_getName(methods[i]));
                    [nameStr appendFormat:@"%s", name];
    
                    if ( ((includeMethods && ![self string:nameStr matches:includeMethods]) ||
                          (excludeMethods && [self string:nameStr matches:excludeMethods])) )
                       ;//NSLog( @"Xtrace: filters exclude: %s[%s %s] %s", mtype, className, name, type );
    
                    else if ( (excludeTypes && [self string:[NSString stringWithUTF8String:type] matches:excludeTypes]) )
                        NSLog( @"Xtrace: type filter excludes: %s[%s %s] %s", mtype, className, name, type );
    
                    else if ( name[0] == '.' ||
                             [nameStr isEqualToString:@"description"] || [nameStr hasPrefix:@"_description"] ||
                             [nameStr isEqualToString:@"retain"] || [nameStr isEqualToString:@"release"] /*||
                             [nameStr isEqualToString:@"dealloc"] || [nameStr hasPrefix:@"_dealloc"]*/ )
                        ; // best avoided
    
    #ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
                    else if ( aClass == [UIView class] && [nameStr isEqualToString:@"drawRect:"] )
                        ; // no idea why this is a problem...
    #endif
    
                    else if (params.includeProperties || !class_getProperty( aClass, name ))
                        [self intercept:aClass method:methods[i] mtype:mtype depth:depth];
    
                   [nameStr setString:@""];
                }
    
                swizzledClasses[aClass] = YES;
                free( methods );
            }
    
            aClass = class_getSuperclass(aClass);
            if ( !--depth || aClass == nsObject || aClass == nsObjectMeta ) // don't trace NSObject
                break;
        }
    

    上面这段代码 每个if-else 后面没有大括号{},会出现问题。

    相关文章

      网友评论

          本文标题:if-else后面一定要带上{}

          本文链接:https://www.haomeiwen.com/subject/izccattx.html