You could move getAge() to be a private func outside of the scope of Person?


> On 23 May 2016, at 11:24 PM, James Campbell via swift-evolution 
> <[email protected]> wrote:
> 
> 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⎥
> 
> [email protected] <mailto:[email protected]>⎥supmenow.com 
> <http://supmenow.com/>
> Sup
> 
> Runway East
> 
> 
> 10 Finsbury Square
> 
> London
> 
> 
> EC2A 1AF 
> 
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to