import UIKit class Movie { let title: String let director: String let releaseYear: Int init(title: String, director: String, releaseYear: Int){ self.title = title self.director = director self.releaseYear = releaseYear } }
class MovieArchive { var movies:[Movie] func filterByYear(year:Int) -> [Movie]{ var filteredArray = [Movie]() for movie in self.movies { if movie.releaseYear == year { filteredArray.append(movie) } } return filteredArray } init(movies:[Movie]){ self.movies = movies } }
import UIKit class ViewController: UIViewController { var count = 0 var label:UILabel! override func viewDidLoad(){ super.viewDidLoad() // Label var label = UILabel() label.frame = CGRectMake(150, 150, 60, 60) label.text = "0" self.view.addSubview(label) self.label = label // Button var button = UIButton() button.addTarget(self, action: "incrementCount", forControlEvents: UIControlEvents.TouchUpInside) self.view.addSubview(button) button.frame = CGRectMake(150, 250, 60, 60) button.setTitle("Click", forState: .Normal) button.setTitleColor(UIColor.blueColor(), forState:.Normal) } @IBAction func incrementCount(){ self.count++ self.label.text = "\(self.count)" } }
Access Control
Level, Class, App/Framework, Work
public: Y Y Y
internal: Y Y N
private Y N N
class Movie { let title: String let director: String let releaseYear: Int init(title: String, director: String, releaseYear: Int){ self.title = title self.director = director self.releaseYear = releaseYear } } var thursdayNightMovie = Movie(title: "Point Break", director: "Kathryn Bigelow", releaseYear: 1991) thursdayNightMovie.title