[swift-evolution] Initialiser Helper

James Campbell james at supmenow.com
Mon May 23 08:24:36 CDT 2016


I would like to be able to use functions to help me initilise a class or
struct so I can break down a init into seperate methods, like so:

struct Person {

let age: Int

init (json: Dictionary) {
// lots of code

age = json["age"]
}

}

This can become un-wieldly, so I would love to be able to do this:


struct Person {

let age: Int

init (json: Dictionary) {
// lots of code

age = getAge(json)
}

private func getAge(json: Dictionary) -> Int {

}

}

*___________________________________*

*James⎥*

*james at supmenow.com <james at supmenow.com>⎥supmenow.com <http://supmenow.com>*

*Sup*

*Runway East *

*10 Finsbury Square*

*London*

* EC2A 1AF *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160523/ede4f03d/attachment.html>


More information about the swift-evolution mailing list