[swift-dev] Possibility to makes classes partial as C# language
    Kévin Machado 
    machadokevin.dev at gmail.com
       
    Thu Dec 10 03:07:38 CST 2015
    
    
  
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*.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20151210/519305fc/attachment.html>
    
    
More information about the swift-dev
mailing list