Created
May 15, 2017 06:23
-
-
Save DennisdeBest/4aa306244a000b123ff82265665c0541 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// PoneyContainer.swift | |
// PetitPonaay | |
// | |
// Created by Developer on 20/03/2017. | |
// Copyright © 2017 Developer. All rights reserved. | |
// | |
import Foundation | |
class PoneyContainer { | |
var PoneyList = [Poney](); | |
func addPoney(Poney :Poney) -> Void { | |
PoneyList.append(Poney) | |
} | |
func printPoneys () -> Void { | |
for Item in PoneyList { | |
print("Name : ",Item.name," Level : ", Item.Level) | |
} | |
} | |
func getList() -> String { | |
var str = "" | |
for Item in PoneyList { | |
str += "Name : \(Item.name) Level : \(Item.Level) \n" | |
} | |
return str | |
} | |
func evolveAllPoneys () -> Void { | |
for Item in PoneyList { | |
var tempPoney = Item | |
tempPoney.levelUp() | |
PoneyList.removeFirst() | |
PoneyList.append(tempPoney) | |
} | |
} | |
func getLastPoney() -> Poney { | |
return PoneyList.popLast()! | |
} | |
} | |
// | |
// ViewController.swift | |
// PetitPonaay | |
// | |
// Created by Developer on 20/03/2017. | |
// Copyright © 2017 Developer. All rights reserved. | |
// | |
import UIKit | |
class ViewController: UIViewController { | |
let container = PoneyContainer() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
//Actions | |
@IBAction func SavePoney(_ sender: UIButton) { | |
print(PoneyName.text) | |
print(PoneyLevel.text) | |
guard let LevelString = PoneyLevel.text else { | |
print("No level set") | |
return | |
} | |
guard let LevelInt = Int(LevelString) else { | |
return | |
} | |
guard let Name = PoneyName.text else { | |
print("This is not an americana song") | |
return | |
} | |
let poney = Poney(Level: LevelInt, name: Name) | |
container.addPoney(Poney: poney) | |
PoneyList.text = "Poneys"; | |
PoneyList.text = container.getList() | |
container.printPoneys() | |
} | |
@IBOutlet weak var PoneyList: UITextView! | |
@IBOutlet weak var PoneyLevel: UITextField! | |
@IBOutlet weak var PoneyName: UITextField! | |
} | |
// | |
// Poney.swift | |
// PetitPonaay | |
// | |
// Created by Developer on 20/03/2017. | |
// Copyright © 2017 Developer. All rights reserved. | |
// | |
import Foundation | |
struct Poney { | |
var Level = 1 | |
var name = "dada" | |
mutating func levelUp() -> Void { | |
self.Level += 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment