Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is optional or required the default for protocol methods?

I used to think that the default/implicit specifier for protocol methods is optional. However, in my current project I see a warning if I do not add the @optional specifier specifically. Not a big deal. I am just wondering, was it optional the default for a while, and now it is required? Or maybe I missed something while I was learning Objective-C a while ago.

Thanks in advance!

like image 801
ppalancica Avatar asked Jan 08 '23 07:01

ppalancica


2 Answers

@required was always by default to gurantee, that you app won't crash if you inherit protocol and forget to implemet methods. So you should manuall set @optional

like image 142
katleta3000 Avatar answered Jan 14 '23 00:01

katleta3000


From the Apple documentation

By default, all methods declared in a protocol are required methods.

It's always been required by default. There is no way that has changed or many things would suddenly start breaking.

like image 28
rmaddy Avatar answered Jan 14 '23 02:01

rmaddy