Bladeren bron

Code cleanup

Iñigo Valentin 9 jaren geleden
bovenliggende
commit
ecdd875be8

+ 16 - 22
app/AlbumViewController.swift

@@ -146,7 +146,6 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 					var imgR = imgSearchResults[0]
 					image = imgR.value(forKey: "file")! as! String
 					leftId = imgR.value(forKey: "id")! as! Int
-					NSLog(":GALLERYCONTROLLER:LOG: Image Row \(i) left: \(image)")
 					row.setImage(idx: 0, filename: image)
 					if i + 1 < searchResults.count {
 						r = searchResults[i + 1]
@@ -159,15 +158,10 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 						imgR = imgSearchResults[0]
 						image = imgR.value(forKey: "file")! as! String
 						rightId = imgR.value(forKey: "id")! as! Int
-						NSLog(":GALLERYCONTROLLER:LOG: Image Row \(i) right: \(image)")
 						row.setImage(idx: 1, filename: image)
 					}
-					else{
-						NSLog(":GALLERYCONTROLLER:LOG: Image Row \(i) right: none")
-					}
-					//TODO create row, add images (L+R), add row to container.
-					//row.setImage(filename: image)
-				} catch {
+				}
+				catch {
 					NSLog(":GALLERYCONTROLLER:ERROR: Error getting image for post \(id): \(error)")
 				}
 				
@@ -183,6 +177,20 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 	}
 	
 	
+	/**
+	Run before performing a segue.
+	Assigns id if neccessary.
+	:param: segue The segue to perform.
+	:sender: The calling view.
+	*/
+	override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
+		if segue.identifier == "SeguePhotoAlbum"{
+			(segue.destination as! PhotoViewController).albumId = passAlbum
+			(segue.destination as! PhotoViewController).photoId = passId
+		}
+	}
+	
+	
 	/**
 	Gets the device language. The only recognized languages are Spanish, English and Basque.
 	If the device has another language, Spanish will be selected by default.
@@ -199,20 +207,6 @@ class AlbumViewController: UIViewController, UIGestureRecognizerDelegate {
 	}
 	
 	
-	/**
-	Run before performing a segue.
-	Assigns id if neccessary.
-	:param: segue The segue to perform.
-	:sender: The calling view.
-	*/
-	override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
-		if segue.identifier == "SeguePhotoAlbum"{
-			(segue.destination as! PhotoViewController).albumId = passAlbum
-			(segue.destination as! PhotoViewController).photoId = passId
-		}
-	}
-	
-	
 	/**
 	Shows a photo.
 	:param: id The album id.

+ 3 - 3
app/BlogView.swift

@@ -62,7 +62,7 @@ class BlogView: UIView {
 		self.storyboard = UIStoryboard(name: "Main", bundle: nil)
 		self.controller = storyboard?.instantiateViewController(withIdentifier: "GMViewController") as! ViewController
 		self.context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
-		self.delegate = UIApplication.shared.delegate as! AppDelegate
+		self.delegate = UIApplication.shared.delegate as? AppDelegate
 		self.lang = getLanguage()
 		self.context?.persistentStoreCoordinator = delegate?.persistentStoreCoordinator
 		
@@ -95,7 +95,7 @@ class BlogView: UIView {
 			var text: String
 			var image: String
 			
-			for r in searchResults as! [NSManagedObject] {
+			for r in searchResults! {
 								
 				//Create a new row
 				row = RowBlog.init(s: "rowBlog\(count)", i: count)
@@ -116,7 +116,7 @@ class BlogView: UIView {
 				imgFetchRequest.fetchLimit = 1
 				do{
 					let imgSearchResults = try context?.fetch(imgFetchRequest)
-					for imgR in imgSearchResults as! [NSManagedObject]{
+					for imgR in imgSearchResults!{
 						image = imgR.value(forKey: "image")! as! String
 						row.setImage(filename: image)
 					}

+ 0 - 1
app/PhotoViewController.swift

@@ -164,7 +164,6 @@ class PhotoViewController: UIViewController, UIGestureRecognizerDelegate {
 			let searchResults = try context.fetch(fetchRequest)
 			
 			var sTitle: String
-			var sText: String
 			var image: String
 			var date: NSDate
 			

+ 1 - 1
app/RowAlbum.swift

@@ -53,7 +53,7 @@ Extension of UIView to be formatted as sections.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 		
 		self.frame = self.bounds
 		self.autoresizingMask = [.flexibleWidth, .flexibleHeight]

+ 1 - 1
app/RowBlog.swift

@@ -51,7 +51,7 @@ Extension of UIView to be formatted as post rows.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first as! UIView
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	

+ 1 - 1
app/RowFutureActivity.swift

@@ -54,7 +54,7 @@ Extension of UIView to be formatted as future activity rows.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	

+ 1 - 1
app/RowGallery.swift

@@ -55,7 +55,7 @@ Extension of UIView to be formatted as sections.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	

+ 1 - 1
app/RowHomeGallery.swift

@@ -52,7 +52,7 @@ Extension of UIView to be formatted as sections.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first as! UIView
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	

+ 1 - 1
app/RowHomePastActivities.swift

@@ -51,7 +51,7 @@ Extension of UIView to be formatted as past activity rows.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	

+ 1 - 1
app/RowHomeSocial.swift

@@ -56,7 +56,7 @@ Extension of UIView to be formatted as sections.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	/**

+ 1 - 1
app/RowItinerary.swift

@@ -50,7 +50,7 @@ Extension of UIView to be formatted an activity itinerary.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	

+ 1 - 1
app/RowLabel.swift

@@ -46,7 +46,7 @@ Extension of UIView to be formatted as sections.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	

+ 1 - 1
app/RowLablancaDay.swift

@@ -49,7 +49,7 @@ Extension of UIView to be formatted as sections.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 		
 		self.frame = self.bounds
 		self.autoresizingMask = [.flexibleWidth, .flexibleHeight]

+ 1 - 1
app/RowLablancaOffer.swift

@@ -48,7 +48,7 @@ Extension of UIView to be formatted as sections.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 		
 		self.frame = self.bounds
 		self.autoresizingMask = [.flexibleWidth, .flexibleHeight]

+ 1 - 1
app/RowSchedule.swift

@@ -49,7 +49,7 @@ Extension of UIView to be formatted as sections.
 	private func loadViewFromNib() {
 		let bundle = Bundle(for: type(of: self))
 		let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
-		nib.instantiate(withOwner: self, options: nil).first
+		nib.instantiate(withOwner: self, options: nil)
 	}
 	
 	

+ 2 - 2
app/ScheduleViewController.swift

@@ -259,7 +259,7 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 			for r in searchResults! {
 				
 				title = r.value(forKey: "title_\(lang!)") as! String
-				if let tx = r.value(forKey: "description_\(lang!)"){
+				if r.value(forKey: "description_\(lang!)") != nil{
 					text = r.value(forKey: "description_\(lang!)") as! String
 				}
 				else{
@@ -279,7 +279,7 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 				locationFetchRequest.fetchLimit = 1
 				do{
 					var locationSearchResults = try self.context?.fetch(locationFetchRequest)
-					var locationR = locationSearchResults?[0]
+					let locationR = locationSearchResults?[0]
 					location = locationR?.value(forKey: "name_\(lang!)")! as! String
 					
 					row.setLocation(text: location)

+ 1 - 2
app/Sync.swift

@@ -1820,9 +1820,8 @@ class Sync{
 			dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
 			dateFormatter.calendar = NSCalendar(calendarIdentifier: NSCalendar.Identifier.ISO8601)! as Calendar
 			dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX") as Locale!
-			//dateFormatter.timeZone = NSTimeZone(forSecondsFromGMT: 0) as TimeZone!
 			dateFormatter.timeZone = NSTimeZone.local
-			var dayString = "\(str.subStr(start : str.indexOf(target : "\"start\":")! + 9, end : str.indexOf(target : ",\"")! - 11)) 00:00:00"
+			let dayString = "\(str.subStr(start : str.indexOf(target : "\"start\":")! + 9, end : str.indexOf(target : ",\"")! - 11)) 00:00:00"
 			var day = dateFormatter.date(from: dayString)!
 			// If on the first hours of the next day...
 			let calendar = Calendar.current

+ 2 - 6
app/UIImageView.swift

@@ -79,14 +79,10 @@ extension UIImageView {
 			let task = session.downloadTask(with: request) { (tempLocalUrl, response, error) in
 				if let tempLocalUrl = tempLocalUrl, error == nil {
 					
-					// Success
-					if let statusCode = (response as? HTTPURLResponse)?.statusCode {
-						// TODO something.
-					}
-					
 					do {
 						try FileManager.default.copyItem(at: tempLocalUrl, to: destinationFileUrl)
-					} catch (let writeError) {
+					}
+					catch (let writeError) {
 						NSLog(":IMAGE:ERROR: Error creating a file \(destinationFileUrl) : \(writeError)")
 					}
 					

+ 0 - 1
app/UIView.swift

@@ -63,7 +63,6 @@ import UIKit
 	
 	var parentViewController: ViewController? {
 		var parentResponder: UIResponder? = self
-		var i = 0
 		while parentResponder != nil {
 			parentResponder = parentResponder!.next
 			if let viewController = parentResponder as? ViewController {

+ 2 - 6
app/ViewController.swift

@@ -157,6 +157,7 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 			Sync(synchronous: true)
 		}
 		else{
+			// TODO CHECK this
 			NSLog(":CONTROLLER:DEBUG: Re-populating disabled: Throws error.")
 			//self.populate()
 			syncSegue?.destination.dismiss(animated: true, completion: nil)
@@ -329,8 +330,6 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	//Make a cell for each section
 	func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
 		
-		var first = true
-		
 		//Get a reference to our storyboard cell
 		let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! MenuCollectionViewCell
 		
@@ -340,7 +339,6 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 		// Mark the first one as selected.
 		if indexPath.item == 0{
 			cell.isSelected = true
-			first = false
 		}
 		
 		return cell
@@ -358,9 +356,7 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	:param: selected Index of the selected item.
 	*/
 	@IBAction func showComponent(selected: Int) {
-		//Activate label
-		var i = 0
-		
+				
 		//Show the view
 		if selected == 0 {
 			UIView.animate(withDuration: 0.5, animations: {