zoukankan      html  css  js  c++  java
  • Get Rid of NSCachedURLResponse's Encoding Methods Warning

    Before xcode 4.3 we can use this to encode and decode NSCachedURLResponse:

    @implementation NSCachedURLResponse (NSCoder)

    - (void)encodeWithCoder:(NSCoder *)coder {

         // TODO: 

    }

     

    - (id)initWithCoder:(NSCoder *)coder {

         // TODO: 

    }

    @end

    But in xcode 4.3, it will cause a warng.

    There are two methods to avoid the warning.

    One:

    ref, https://github.com/rs/SDURLCache/pull/29

    Two:

    @interface NSCachedURLResponse (ABC)

    + (void)swapMethods;

    - (id)myInitWithCoder:(NSCoder *)aCoder;

    - (void)myEncodeWithCoder:(NSCoder *)aCoder;

    @end

     

     

    #include <objc/objc.h>

    #import <objc/runtime.h>

    #import <objc/message.h>

     

    void SwapMethods(Class cls, SEL originalSel, SEL newSel) {

        Method originalMethod = class_getInstanceMethod(cls, originalSel);

        Method newMethod = class_getInstanceMethod(cls, newSel);

        method_exchangeImplementations(originalMethod, newMethod);

    }

     

     

    @implementation NSCachedURLResponse (ABC)

    + (void)swapMethods {

        Class tempClass = [NSCachedURLResponse class];

        SwapMethods(tempClass, @selector(initWithCoder:), @selector(myInitWithCoder:));

        SwapMethods(tempClass, @selector(encodeWithCoder:), @selector(myEncodeWithCoder:));

    }

    - (id)myInitWithCoder:(NSCoder *)aCoder {

         // TODO: 

    }

    - (void)myEncodeWithCoder:(NSCoder *)aCoder {

        // TODO: 

    }

    @end

  • 相关阅读:
    识别IE11浏览器
    国庆过后老革命
    有些东西再忙也要做
    云计算
    SVN下Update出现代码文件删除状态问题
    如何避免历史回退到登录页面
    CodeSmith连Oracle
    NHibernate直接执行SQL进行插入
    nhibernate实体类主键ID赋值问题
    NHibernate不支持复杂的linq,就一定要用DataTable这么低级吗
  • 原文地址:https://www.cnblogs.com/Proteas/p/2735590.html
Copyright © 2011-2022 走看看