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

  • 相关阅读:
    HDU 1286(欧拉函数||筛选法)
    因数打表(HDU1215)
    HDU 1003
    T行数据跟着N个数据
    15校赛
    HDU 1002
    简单大数相加
    (质因子打表记录素数的位置)HDU Largest prime factor
    HDU cake
    【转】 cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
  • 原文地址:https://www.cnblogs.com/Proteas/p/2735590.html
Copyright © 2011-2022 走看看