Incompatible pointer types assigning to 'id' from 'Class'

后端 未结 2 1052
一整个雨季
一整个雨季 2021-02-04 11:34

I have a \"Utility\" class that implements the AVAudioPlayerDelegate protocol.

This is my Utility.h

@i         


        
2条回答
  •  执笔经年
    2021-02-04 12:12

    When you don't need an instance of a Class, just manually get ride of the warning:

    audioPlayer.delegate = (id)self;
    

    On the other hand, please note that if you need a Delegate, it means you should have an instance of a Class as a good coding practice instead of a static Class. It can be made a singleton easily:

    static id _sharedInstance = nil;
    +(instancetype)sharedInstance
    {
        static dispatch_once_t p;
        dispatch_once(&p, ^{
            _sharedInstance = [[self alloc] init];
        });
        return _sharedInstance;
    }
    

提交回复
热议问题