NSXMLParserDelegate compile problem - iPhone SDK 30. vs 4.0

后端 未结 2 1657
醉酒成梦
醉酒成梦 2021-01-05 12:15

My header file is defined like this:

#import 

@interface Warning: NSObject  { 

In my .m file I do:

相关标签:
2条回答
  • 2021-01-05 12:48

    I was able to fix this with:

    #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
    @protocol NSXMLParserDelegate
    @end
    #endif
    @interface Warning: NSObject <NSXMLParserDelegate>
    

    Just be sure to implement the appropriate methods in your implementation.

    0 讨论(0)
  • 2021-01-05 13:03

    According to the library reference documentation, NSXMLParser doesn't require a strict NSXMLParserDelegate implementation :

    - (void)setDelegate:(id)delegate
    - (id)delegate
    

    NSXMLParser checks needed delegate methods availability on the fly.

    If NSXMLParser was requiring a NSXMLParserDelegate full implementation, the accessors would be :

    - (void)setDelegate:(id<NSXMLParserDelegate>)delegate
    - (id<NSXMLParserDelegate>)delegate
    

    I guess that's why there is no NSXMLParserDelegate protocol actually defined in the framework.

    So, that interface seems correct to me :

    #import <Foundation/Foundation.h>
    
    @interface Warning: NSObject  { 
    

    All you have to do is implement the delegate methods you need for.

    Edit :

    You could try using preprocessor macros to activate or deactivate the protocol usage declaration :

    #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
    @interface Warning: NSObject <NSXMLParserDelegate>
    #else
    @interface Warning: NSObject
    #endif
    {
       // interface definition ...
    

    I didn't try this with 4.0, but it worked on another example between 3.1 and 3.2

    0 讨论(0)
提交回复
热议问题