ppalancica
ppalancica

Reputation: 4277

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!

Upvotes: 4

Views: 3390

Answers (2)

rmaddy
rmaddy

Reputation: 318944

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.

Upvotes: 3

katleta3000
katleta3000

Reputation: 2494

@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

Upvotes: 6

Related Questions