It's a good idea, and one I've often wanted. For both logical and implementation reasons, it makes a lot of sense to start with (1) same-module extensions (2) of concrete types (i.e. you can't add stored properties to protocols (probably ever) or UIKit classes (yet)).
There's been some discussion of this in the past:
Introduction
In swift we are able to add extension of classes that allows us to add methods but we cannot add attributes, properties.
C# language allows developers to make its classes partial. It is possible to split the definition of class, struct or interface over two or more source files.
Could we make swift able to do this stuff ?
Proposed solution
Add partial keyword to alert the compiler that this class is splited over one or more source files.
Example
// Common logic for bank mod…
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20161003/027723.html
Hello,
very often, it is necessary to define stored properties in extensions. It
is currently only possible in Swift that has access to ObjC runtime with
associated objects (in theory it might be possible with some global
dictionary) and it requires a lot of boilerplate. Associated objects are
used in UIKit quite heavily so it is something that authors of frameworks
need.
It would be nice to able to create properties in extensions natively in
Swift without need of Objective-C and without…
5 Likes