[swift-dev] Possibility to makes classes partial as C# language

Jordan Rose jordan_rose at apple.com
Thu Dec 10 11:45:38 CST 2015


Hi, Kévin. This sort of post is more appropriate for the swift-evolution list, and indeed there's already a bit of discussion around this. I suggest you look through the archives <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/thread.html> to see what you need to add.

Jordan


> On Dec 10, 2015, at 1:07, Kévin Machado via swift-dev <swift-dev at swift.org> wrote:
> 
> Dear colleagues,
> 
> 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 ?
> Are you interested about this kind of feature ?
> 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 model
>   partial class Bank {
> 
>     var amount: Int
> 
>     init() {
>         amount = 0
>         super.init()
>     }
> 
>     func withdraw(amount amount: Int) {
>         self.amount -= amount
>     }
> 
>   }
> 
>   // Business logic for customer within bank model
>   partial class Bank {
> 
>     unowned let owner: Customer
> 
>     init(customer: Customer) {
>         self.owner = customer
>     }
> 
>     func notifyCustomer() {
>         // some code
>     }
> 
>   }
>  <https://github.com/djnivek/swift-evolution/blob/56929274a31ff58295841a74a1eb2ace9db3e428/proposals/0008-makes-swift-class-struct-definitions-partial.md#alternative-solution>Alternative solution
> 
> We also could add more feature with the extension paradigm. Adding properties, attributes and more directly on the extension scope.
> 
>  _______________________________________________
> swift-dev mailing list
> swift-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20151210/60c5a2cd/attachment-0001.html>


More information about the swift-dev mailing list