Advertisement
Guest User

Yuval

a guest
May 27th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.55 KB | None | 0 0
  1. //
  2. //  MovieViewController.swift
  3. //  ReptorMovies
  4. //
  5. //  Created by hackeru on 24/05/2019.
  6. //  Copyright © 2019 hackeru. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class MovieViewController: UIViewController {
  12.    
  13.    
  14.     // our textViews and imageViews
  15.     @IBOutlet weak var movieImage: UIImageView!
  16.    
  17.     @IBOutlet weak var movieTitle: UILabel!
  18.    
  19.     @IBOutlet weak var movieReleaseYear: UILabel!
  20.    
  21.     @IBOutlet weak var movieRating: UILabel!
  22.    
  23.     @IBOutlet weak var movieGenres: UILabel!
  24.    
  25.     // all movie details gotten from the chosen cell -
  26.    
  27.     var finalTitle:String = ""
  28.     var finalReleaseYear:Int = 0
  29.     var finalImage:String = ""
  30.     var finalRating:Double = 0.0
  31.     var finalGenre:[String] = []
  32.    
  33.     override func viewDidLoad() {
  34.         super.viewDidLoad()
  35.  
  36.             // attaching the content from our chosen movie to the TextViews and ImageView
  37.         movieTitle.text = finalTitle
  38.         movieReleaseYear.text = "\(finalReleaseYear)"
  39.         movieRating.text = "Rating: \(finalRating)"
  40.         movieGenres.text = "Genres: \(fixTheGenres(finalGenre))"
  41.         setPhotoURLtoImageView(finalImage,movieImage)
  42.        
  43.        
  44.     }
  45.    
  46.     func fixTheGenres(_ genres:[String]) -> String {
  47.        
  48.         var fixedGenres:String = ""  // will be a better-organized string with the genres in it
  49.        
  50.         if genres.count > 1 {
  51.         for idx in 0...genres.count-2
  52.         {
  53.             fixedGenres += "\(genres[idx]), "
  54.         }
  55.         fixedGenres += "\(genres[genres.count-1])."
  56.         } else {
  57.             fixedGenres += "\(genres.count-1)."
  58.  
  59.         }
  60.            
  61.         return fixedGenres
  62.    
  63.     }
  64.    
  65.    
  66.    
  67.     func setPhotoURLtoImageView(_ url:String,_ imageView:UIImageView) { // turning url address of image into data and inserting it to imageView
  68.        
  69.         if let myURL = URL(string: url){
  70.             do {
  71.                 let data = try Data(contentsOf: myURL)
  72.                 imageView.image = UIImage(data: data)
  73.             } catch let err {
  74.                 print ("LOADING IMAGE ERROR = \(err.localizedDescription)")
  75.             }
  76.            
  77.         }
  78.        
  79.     }
  80.  
  81.    
  82.  
  83.     /*
  84.     // MARK: - Navigation
  85.  
  86.     // In a storyboard-based application, you will often want to do a little preparation before navigation
  87.     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  88.         // Get the new view controller using segue.destination.
  89.         // Pass the selected object to the new view controller.
  90.     }
  91.     */
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement