Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // MovieViewController.swift
- // ReptorMovies
- //
- // Created by hackeru on 24/05/2019.
- // Copyright © 2019 hackeru. All rights reserved.
- //
- import UIKit
- class MovieViewController: UIViewController {
- // our textViews and imageViews
- @IBOutlet weak var movieImage: UIImageView!
- @IBOutlet weak var movieTitle: UILabel!
- @IBOutlet weak var movieReleaseYear: UILabel!
- @IBOutlet weak var movieRating: UILabel!
- @IBOutlet weak var movieGenres: UILabel!
- // all movie details gotten from the chosen cell -
- var finalTitle:String = ""
- var finalReleaseYear:Int = 0
- var finalImage:String = ""
- var finalRating:Double = 0.0
- var finalGenre:[String] = []
- override func viewDidLoad() {
- super.viewDidLoad()
- // attaching the content from our chosen movie to the TextViews and ImageView
- movieTitle.text = finalTitle
- movieReleaseYear.text = "\(finalReleaseYear)"
- movieRating.text = "Rating: \(finalRating)"
- movieGenres.text = "Genres: \(fixTheGenres(finalGenre))"
- setPhotoURLtoImageView(finalImage,movieImage)
- }
- func fixTheGenres(_ genres:[String]) -> String {
- var fixedGenres:String = "" // will be a better-organized string with the genres in it
- if genres.count > 1 {
- for idx in 0...genres.count-2
- {
- fixedGenres += "\(genres[idx]), "
- }
- fixedGenres += "\(genres[genres.count-1])."
- } else {
- fixedGenres += "\(genres.count-1)."
- }
- return fixedGenres
- }
- func setPhotoURLtoImageView(_ url:String,_ imageView:UIImageView) { // turning url address of image into data and inserting it to imageView
- if let myURL = URL(string: url){
- do {
- let data = try Data(contentsOf: myURL)
- imageView.image = UIImage(data: data)
- } catch let err {
- print ("LOADING IMAGE ERROR = \(err.localizedDescription)")
- }
- }
- }
- /*
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destination.
- // Pass the selected object to the new view controller.
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement