Swift should have a keyword to mark a protocol method as optional, every solution right now feels like a band aid which doesn't fix the problem. @objc isn't great, a protocol extension with an empty implementation is better, but still not great. This feels like Swift should have a keyword to mark a section or individual methods as optional

@cocoasamurai why isn’t a default implementation identical and nicer? Forcing the function itself to be optional (ie requiring optional chaining) feels annoying.

@cocoaphony it accomplishes the desired effect, but it doesn't communicate it very well. ObjC protocols do this very easily at the time of protocol declaration with the optional & required keywords, no further source code or documentation reading is required to understand what you do, or don't have to implement.

@cocoasamurai @cocoaphony A nice alternative would be either:
- An annotation at declaration level to notify that a default implementation exists, for instance `@implemented func foo() -> Bar`
- A required override hint at re-implementation level, so that the dev knows there's a default impl, similar to subclasses and `@override` keyword

Follow

@bmt @cocoaphony i'd probably go for a declaration level solution myself. It feels like the problem is a lack of an official annotation to express this concept rather than how it is actually implemented

@cocoasamurai @cocoaphony Yes indeed. The concept is sound, we just miss a piece of information to convey that the method is already implemented (and thus optional), but I wouldn't go back to Obj-C style with optional chaining, respondsToSelector etc.

Sign in to participate in the conversation
Hostux.social

Fast, secure and up-to-date instance, welcoming everyone around the world. Join us! 🌍

Up since 02/04/2017. ✅

Why should you sign up on hostux.social?

This instance is not focused on any theme or subject, feel free to talk about whatever you want. Although the main language is french, we accept every single language and country.

We're connected to the whole OStatus/ActivityPub fediverse and we do not block any foreign instance nor user.

We do have rules, but the goal is to have responsible users. So far we haven't had any issue with moderation.

The instance uses a powerful server to ensure speed and stability, and it has good uptime.


Instance rapide, sécurisée et à jour, accueillant tout le monde dans le monde entier. Rejoignez-nous ! 🌍

En ligne depuis le 02/04/2017. ✅

Pourquoi devriez-vous vous inscrire sur hostux.social ?

Cette instance n'est pas centrée sur un thème ou un sujet, n'hésitez pas à parler de ce que vous voulez. Bien que la langue principale soit le français, nous acceptons toutes les langues et tous les pays.

Nous sommes connectés à l'ensemble du fediverse OStatus/ActivityPub et nous ne bloquons aucune autre instance ni aucun utilisateur.

Nous avons des règles, mais l'objectif est d'avoir des utilisateurs responsables. Jusqu'à présent, nous n'avons pas eu de problème avec la modération.

L'instance utilise un serveur puissant pour assurer la vitesse et la stabilité, et elle a un bon uptime.