Ejemplo numero 1

Codigo de Ejercicio:

  • RADIO ESTACION
  • Clases y metodos

    
    //  RadioStation.swift
    //  RadioStations
    
    //Jehovani de Jesus Chavez Segovia 2561842011
    
    //Radio estacion
    
    import UIKit
    
    class RadioStation {
         
        
        var name: String
        var frequency: Double
        
        
        init() {
            name="Default"
            frequency=100
        }
        
        class func minAMFrequency() -> Double {
            return 520.0
        }
        
        class func maxAMFrequency() -> Double {
            return 1610.0
        }
        
        class func minFMFrequency() -> Double {
            return 88.3
        }
        
        class func maxFMFrequency() -> Double {
            return 107.9
        }
        
        func band() ->Int {
            if frequency >= RadioStation.minFMFrequency() && frequency <= RadioStation.maxFMFrequency() {
                return 1 //FM
            } else {
                return 0 //AM
            }
        }
        
    }
    
                                

    Metodos en ViewController

    //  ViewController.swift
    //  RadioStations
    
    //Jehovani de Jesus Chavez Segovia 2561842011
    
    //Radio estacion
    
    import UIKit
    
    class ViewController: UIViewController {
    
        var myStation: RadioStation
        
        @IBOutlet var stationName : UILabel!
        @IBOutlet var stationFrequency : UILabel!
        @IBOutlet var stationBand : UILabel!
        
        required init(coder aDecoder: NSCoder) {
            
            myStation = RadioStation()
            myStation.frequency=102.5
            myStation.name = "Knix"
            super.init(coder: aDecoder)
        }
    
        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.
        }
    
        @IBAction func buttonClick(sender: AnyObject) {
            stationName.text = myStation.name
            stationFrequency.text = String(format:"%f", myStation.frequency)
            
            if myStation.frequency >= RadioStation.minFMFrequency() && myStation.frequency <= RadioStation.maxFMFrequency() {
                stationBand.text = "FM"
            } else {
                stationBand.text = "AM"
            }
            
        }
     
    }
    
       

Corriendo aplicacion

Seleccionando boton para mostrar resultado