Просмотр исходного кода

Merge branch 'Lablanca' into BaseProject

Iñigo Valentin 9 лет назад
Родитель
Сommit
32a04b5963

+ 4 - 1
app/Base.lproj/Main.storyboard

@@ -783,7 +783,7 @@
                                                                     <constraint firstAttribute="width" constant="45" id="0J5-54-fFO"/>
                                                                     <constraint firstAttribute="height" constant="45" id="bRL-x7-mQS"/>
                                                                 </constraints>
-                                                                <fontDescription key="fontDescription" type="boldSystem" pointSize="35"/>
+                                                                <fontDescription key="fontDescription" type="boldSystem" pointSize="30"/>
                                                                 <nil key="textColor"/>
                                                                 <nil key="highlightedColor"/>
                                                             </label>
@@ -946,9 +946,12 @@
                     <connections>
                         <outlet property="btNext" destination="gEL-Ik-UfU" id="yfe-ny-2eZ"/>
                         <outlet property="btPrev" destination="ean-uL-e8X" id="8ah-gF-AV8"/>
+                        <outlet property="btToolbarButton" destination="cV9-gT-2OC" id="NLD-kG-O3O"/>
                         <outlet property="lbDayMonth" destination="g7M-sJ-teh" id="Wwr-mS-Y3D"/>
                         <outlet property="lbDayName" destination="TH3-vv-4wy" id="hbO-Yb-NUo"/>
                         <outlet property="lbDayNumber" destination="EUB-BM-L7c" id="UjL-xN-CcE"/>
+                        <outlet property="lbToolbarTitle" destination="RJE-Hu-oDM" id="nCW-fh-Pst"/>
+                        <outlet property="lbWindowTitle" destination="663-n7-Jwn" id="0p7-02-Veb"/>
                         <outlet property="svScheduleList" destination="bHp-Km-KNL" id="aSi-lC-w6H"/>
                     </connections>
                 </viewController>

+ 95 - 125
app/HomeView.swift

@@ -21,55 +21,45 @@
 import Foundation
 import CoreData
 import UIKit
-
-
 /**
-Class to handle the home view.
-*/
+ Class to handle the home view.
+ */
 class HomeView: UIView {
 	
-	// Outlets
-	@IBOutlet var scrollView: UIScrollView!
-	@IBOutlet var container: UIView!
-	@IBOutlet var locationSection: Section!
-	@IBOutlet var lablancaSection: Section!
-	@IBOutlet var futureActivitiesSection: Section!
-	@IBOutlet var blogSection: Section!
-	@IBOutlet var gallerySection: Section!
-	@IBOutlet var pastActivitiesSection: Section!
-	@IBOutlet var socialSection: Section!
-
-	var lang: String? = nil
-	var moc: NSManagedObjectContext? = nil
-	var appDelegate: AppDelegate? = nil
+	//The main scroll view.
+	@IBOutlet weak var scrollView: UIScrollView!
 	
-	let dbgTxt = "IVV"
+	//The container of the view.
+	@IBOutlet weak var container: UIView!
 	
+	//Each of the sections of the view.
+	@IBOutlet weak var locationSection: Section!
+	@IBOutlet weak var lablancaSection: Section!
+	@IBOutlet weak var futureActivitiesSection: Section!
+	@IBOutlet weak var blogSection: Section!
+	@IBOutlet weak var gallerySection: Section!
+	@IBOutlet weak var pastActivitiesSection: Section!
+	@IBOutlet weak var socialSection: Section!
 	
-	/**
-	Run when the view is started.
-	:param: frame Frame for the view.
-	*/
 	override init(frame: CGRect){
 		super.init(frame: frame)
 	}
 	
-	
 	/**
-	Run when the view is started.
-	:param: coder Application decoder.
+	 Run when the view is started.
 	*/
 	required init?(coder aDecoder: NSCoder) {
 		
 		super.init(coder: aDecoder)
 		
-		// Load the contents of the HomeView.xib file.
+		//Load the contents of the HomeView.xib file.
 		Bundle.main.loadNibNamed("HomeView", owner: self, options: nil)
 		self.addSubview(container)
-		self.container.frame = self.bounds
+		container.frame = self.bounds
 		
 
-		// Set titles for each section
+		
+		//Set titles for each section
 		locationSection.setTitle(text: "Encuentranos")
 		lablancaSection.setTitle(text: "La Blanca")
 		futureActivitiesSection.setTitle(text: "Proximas actividades")
@@ -78,53 +68,35 @@ class HomeView: UIView {
 		pastActivitiesSection.setTitle(text: "Ultimas actividades")
 		socialSection.setTitle(text: "Siguenos")
 		
-		// Get info to populate sections
-		self.moc = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
-		self.appDelegate = UIApplication.shared.delegate as! AppDelegate
-		self.moc?.persistentStoreCoordinator = appDelegate?.persistentStoreCoordinator
-		self.lang = getLanguage()
+		//Get info to populate sections
+		let moc = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
 		
-		// Populate sections
-		self.populate()
+		let appDelegate = UIApplication.shared.delegate as! AppDelegate
+		moc.persistentStoreCoordinator = appDelegate.persistentStoreCoordinator
+		let lang : String = getLanguage()
 		
+		//Populate sections
+		setUpPastActivities(context: moc, delegate: appDelegate, lang: lang, parent: pastActivitiesSection.getContentStack())
+		setUpBlog(context: moc, delegate: appDelegate, lang: lang, parent: blogSection.getContentStack())
+		setUpFutureActivities(context: moc, delegate: appDelegate, lang: lang, parent: futureActivitiesSection.getContentStack())
+		setUpSocial(parent: socialSection.getContentStack())
+		setUpGallery(context: moc, delegate: appDelegate, parent: gallerySection.getContentStack())
 		
-		//Always at the end: update scrollview
-		//var h: Int = 0
-		//for view in scrollView.subviews {
-		//	//contentRect = contentRect.union(view.frame);
-		//	h = h + Int(view.frame.height) + 30 //Why 30?
-		//	print("curh: \(h)")
-		//}
-		// TODO: Calculate at the end
-		//self.scrollView.contentSize.height = 1300// CGFloat(h);
-	}
-
-	
-	func populate2(){
-		NSLog(":HOME:DEBUG: Dummy Populating home view.")
-	}
-	
-	/**
-	Triggers a reloading (or initial loading) of all sections.
-	*/
-	open func populate(){
 		
-		NSLog(":HOME:DEBUG: Populating home view.")
+		pastActivitiesSection.expandSection()
 		
-		//Populate sections
-		self.setUpPastActivities(context: self.moc!, delegate: appDelegate!, lang: self.lang!, parent: self.pastActivitiesSection.getContentStack())
-		self.setUpBlog(context: self.moc!, delegate: self.appDelegate!, lang: self.lang!, parent: self.blogSection.getContentStack())
-		self.setUpFutureActivities(context: self.moc!, delegate: self.appDelegate!, lang: self.lang!, parent: self.futureActivitiesSection.getContentStack())
-		self.setUpSocial(parent: self.socialSection.getContentStack())
-		self.setUpGallery(context: self.moc!, delegate: self.appDelegate!, parent: self.gallerySection.getContentStack())
-		self.pastActivitiesSection.expandSection()
+		
+		//Always at the end: update scrollview
+		var h: Int = 0
+		for view in scrollView.subviews {
+			//contentRect = contentRect.union(view.frame);
+			h = h + Int(view.frame.height) + 30 //Why 30?
+			print("curh: \(h)")
+		}
+		// TODO: Calculate at the end
+		self.scrollView.contentSize.height = 1300// CGFloat(h);
 	}
 	
-	
-	/**
-	Retrieves the device language. The only available ones are Spanish, English and Basque.
-	:return: Two letter language code (en, eu, es). If other, spanish will be selected.
-	*/
 	func getLanguage() -> String{
 		let pre = NSLocale.preferredLanguages[0].subStr(start: 0, end: 1)
 		if(pre == "es" || pre == "en" || pre == "eu"){
@@ -135,17 +107,9 @@ class HomeView: UIView {
 		}
 	}
 	
-	
-	/**
-	Sets the future activities section.
-	Loads up to two future activities.
-	:param: context Aplication context.
-	:param: delegate Application delegate.
-	:param: lang Device language. Two letter code. Accepts 'es', 'en' and 'eu'.
-	:param: parent View where the rows will be loaded.
-	*/
 	func setUpFutureActivities(context : NSManagedObjectContext, delegate: AppDelegate, lang: String, parent : UIStackView){
 		
+		//context.persistentStoreCoordinator = delegate.persistentStoreCoordinator
 		let fetchRequest: NSFetchRequest<Activity> = Activity.fetchRequest()
 		let sortDescriptor = NSSortDescriptor(key: "date", ascending: true)
 		let sortDescriptors = [sortDescriptor]
@@ -154,8 +118,11 @@ class HomeView: UIView {
 		fetchRequest.fetchLimit = 2
 		
 		do {
+			//go get the results
 			let searchResults = try context.fetch(fetchRequest)
-			NSLog(":HOME:DEBUG: Future activity count: \(searchResults.count)")
+			
+			//I like to check the size of the returned results!
+			print ("Activities: \(searchResults.count)")
 			
 			var row : RowHomePastActivities
 			var count = 0
@@ -164,14 +131,19 @@ class HomeView: UIView {
 			var text: String
 			var image: String
 			
+			//You need to convert to NSManagedObject to use 'for' loops
 			for r in searchResults as [NSManagedObject] {
 				count = count + 1
+				//get the Key Value pairs (although there may be a better way to do that...
+				print("Perm: \(r.value(forKey: "permalink"))")
+				
 				
 				//Create a new row
 				row = RowHomePastActivities.init(s: "rowHomeFutureActivities\(count)", i: count)
 				id = r.value(forKey: "id")! as! Int
 				title = r.value(forKey: "title_\(lang)")! as! String
 				text = r.value(forKey: "text_\(lang)")! as! String
+				print(title)
 				row.setTitle(text: title)
 				row.setText(text: text)
 				
@@ -187,30 +159,26 @@ class HomeView: UIView {
 					let imgSearchResults = try context.fetch(imgFetchRequest)
 					for imgR in imgSearchResults as [NSManagedObject]{
 						image = imgR.value(forKey: "image")! as! String
+						print ("IMAGE: \(image)")
 						row.setImage(filename: image)
 					}
 				} catch {
-					NSLog(":HOME:ERROR: Error getting image for futureactivity \(id): \(error)")
+					print("Error getting image for activity \(id): \(error)")
 				}
+				
+				print("Row height: \(row.frame.height)")
+				
 				parent.addArrangedSubview(row)
 				
 			}
 		} catch {
-			NSLog(":HOME:ERROR: Error setting the future activities section up: \(error)")
+			print("Error with request: \(error)")
 		}
 	}
 	
-	
-	/**
-	Sets the blog section.
-	Loads up to two posts.
-	:param: context Aplication context.
-	:param: delegate Application delegate.
-	:param: lang Device language. Two letter code. Accepts 'es', 'en' and 'eu'.
-	:param: parent View where the rows will be loaded.
-	*/
 	func setUpBlog(context : NSManagedObjectContext, delegate: AppDelegate, lang: String, parent : UIStackView){
 		
+		//context.persistentStoreCoordinator = delegate.persistentStoreCoordinator
 		let fetchRequest: NSFetchRequest<Post> = Post.fetchRequest()
 		let sortDescriptor = NSSortDescriptor(key: "dtime", ascending: false)
 		let sortDescriptors = [sortDescriptor]
@@ -218,8 +186,11 @@ class HomeView: UIView {
 		fetchRequest.fetchLimit = 2
 		
 		do {
+			//go get the results
 			let searchResults = try context.fetch(fetchRequest)
-			NSLog(":HOME:DEBUG: Post count: \(searchResults.count)")
+			
+			//I like to check the size of the returned results!
+			print ("Post: \(searchResults.count)")
 			
 			var row : RowHomeBlog
 			var count = 0
@@ -228,8 +199,12 @@ class HomeView: UIView {
 			var text: String
 			var image: String
 			
+			//You need to convert to NSManagedObject to use 'for' loops
 			for r in searchResults as [NSManagedObject] {
 				count = count + 1
+				//get the Key Value pairs (although there may be a better way to do that...
+				print("Perm: \(r.value(forKey: "permalink"))")
+				
 				
 				//Create a new row
 				row = RowHomeBlog.init(s: "rowHomeBlog\(count)", i: count)
@@ -253,12 +228,15 @@ class HomeView: UIView {
 					let imgSearchResults = try context.fetch(imgFetchRequest)
 					for imgR in imgSearchResults as [NSManagedObject]{
 						image = imgR.value(forKey: "image")! as! String
+						print ("IMAGE: \(image)")
 						row.setImage(filename: image)
 					}
 				} catch {
-					NSLog(":HOME:ERROR: Error getting image for post \(id): \(error)")
+					print("Error getting image for post \(id): \(error)")
 				}
 				
+				print("Row height: \(row.frame.height)")
+				
 				parent.addArrangedSubview(row)
 				
 				let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(openPost(_:)))
@@ -267,21 +245,13 @@ class HomeView: UIView {
 				
 			}
 		} catch {
-			NSLog(":HOME:ERROR: Error setting the blog section up: \(error)")
+			print("Error with request: \(error)")
 		}
 	}
 	
-	
-	/**
-	Sets the past activities section.
-	Loads up to two past activities.
-	:param: context Aplication context.
-	:param: delegate Application delegate.
-	:param: lang Device language. Two letter code. Accepts 'es', 'en' and 'eu'.
-	:param: parent View where the rows will be loaded.
-	*/
 	func setUpPastActivities(context : NSManagedObjectContext, delegate: AppDelegate, lang: String, parent : UIStackView){
 		
+		//context.persistentStoreCoordinator = delegate.persistentStoreCoordinator
 		let fetchRequest: NSFetchRequest<Activity> = Activity.fetchRequest()
 		let sortDescriptor = NSSortDescriptor(key: "date", ascending: false)
 		let sortDescriptors = [sortDescriptor]
@@ -290,8 +260,11 @@ class HomeView: UIView {
 		fetchRequest.fetchLimit = 2
 		
 		do {
+			//go get the results
 			let searchResults = try context.fetch(fetchRequest)
-			NSLog(":HOME:LOG: Setting past activities up. Count: \(searchResults.count)")
+			
+			//I like to check the size of the returned results!
+			print ("Activities: \(searchResults.count)")
 			
 			var row : RowHomePastActivities
 			var count = 0
@@ -300,8 +273,12 @@ class HomeView: UIView {
 			var text: String
 			var image: String
 			
+			//You need to convert to NSManagedObject to use 'for' loops
 			for r in searchResults as [NSManagedObject] {
 				count = count + 1
+				//get the Key Value pairs (although there may be a better way to do that...
+				print("Perm: \(r.value(forKey: "permalink"))")
+				
 				
 				//Create a new row
 				row = RowHomePastActivities.init(s: "rowHomePastActivities\(count)", i: count)
@@ -325,35 +302,32 @@ class HomeView: UIView {
 					let imgSearchResults = try context.fetch(imgFetchRequest)
 					for imgR in imgSearchResults as [NSManagedObject]{
 						image = imgR.value(forKey: "image")! as! String
+						print ("IMAGE: \(image)")
 						row.setImage(filename: image)
 					}
 				} catch {
-					NSLog(":HOME:ERROR: Error getting image for past activity \(id): \(error)")
+					print("Error getting image for activity \(id): \(error)")
 				}
 				
+				print("Row height: \(row.frame.height)")
+				
 				parent.addArrangedSubview(row)
 				
 			}
 		} catch {
-			NSLog(":HOME:ERROR: Error setting the past activities section up: \(error)")
+			print("Error with request: \(error)")
 		}
 	}
 	
-	/**
-	Sets the fgallery section.
-	Loads up to four photos.
-	:param: context Aplication context.
-	:param: delegate Application delegate.
-	:param: parent View where the rows will be loaded.
-	*/
 	func setUpGallery(context : NSManagedObjectContext, delegate: AppDelegate,parent: UIStackView){
-		NSLog(":HOME:LOG: Setting gallery section up.")
+		print("HOME:LOG: Setting up gallery.")
 		
 		// Create the row
 		var row: RowHomeGallery
 		row = RowHomeGallery.init(s: "rowHomeGallery", i: 0)
 		parent.addArrangedSubview(row)
 		
+		
 		// Set images
 		let fetchRequest: NSFetchRequest<Photo> = Photo.fetchRequest()
 		let sortDescriptor = NSSortDescriptor(key: "uploaded", ascending: false)
@@ -362,7 +336,10 @@ class HomeView: UIView {
 		fetchRequest.fetchLimit = 4
 		
 		do {
+			//go get the results
 			let searchResults = try context.fetch(fetchRequest)
+	
+			var id: Int
 			var image: String
 			
 			// Loop images
@@ -379,31 +356,24 @@ class HomeView: UIView {
 			
 		}
 		catch{
-			NSLog(":HOME:ERROR: Error setting gallery up: \(error)")
+			print("HOME:ERROR: Error setting gallery up: \(error)")
 		}
 		
 	}
 	
-	/**
-	Sets the social section.
-	:param: parent View where the rows will be loaded.
-	*/
 	func setUpSocial(parent : UIStackView){
-		NSLog(":HOME:LOG: Setting soceial section up.")
+		print("SETING UP SOCIAL")
 		//Create a new row
 		var row : RowHomeSocial
 		row = RowHomeSocial.init(s: "rowHomeSocial", i: 0)
+		print("ROW CREATED")
 		parent.addArrangedSubview(row)
 	}
 	
-	/**
-	opens the blog section, showing a post.
-	:param: sender: View calling the function.
-	*/
 	func openPost(_ sender:UITapGestureRecognizer? = nil){
-		NSLog(":HOME:DEBUG: Getting delegate and showing post.")
+		print("HOME:DEBUG: getting delegate and showing post.")
 		let delegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
 		delegate.controller?.showPost(id: (sender?.view as! RowHomeBlog).id)
-		NSLog(":HOME:DEBUG: Post should be shown.")
+		print("HOME:DEBUG: Post should be shown.")
 	}
 }

+ 6 - 6
app/HomeView.xib

@@ -1,15 +1,15 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
     <device id="retina3_5" orientation="portrait">
         <adaptation id="fullscreen"/>
     </device>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
-        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner">
+        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="HomeView" customModule="app" customModuleProvider="target">
             <connections>
                 <outlet property="blogSection" destination="uHa-Mu-U68" id="RUp-Jg-AxI"/>
                 <outlet property="container" destination="iN0-l3-epB" id="cfT-rm-jA0"/>
@@ -23,17 +23,17 @@
             </connections>
         </placeholder>
         <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
-        <view contentMode="scaleToFill" id="iN0-l3-epB" customClass="HomeView" customModule="app">
+        <view contentMode="scaleToFill" id="iN0-l3-epB">
             <rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <subviews>
                 <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" ambiguous="YES" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Poy-ba-9jX">
                     <rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
                     <subviews>
-                        <stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" axis="vertical" alignment="center" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="gOz-rr-CeQ">
+                        <stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" axis="vertical" alignment="center" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="gOz-rr-CeQ">
                             <rect key="frame" x="0.0" y="0.0" width="320" height="780"/>
                             <subviews>
-                                <view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Ljm-NP-c4e" customClass="Section" customModule="app">
+                                <view autoresizesSubviews="NO" contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Ljm-NP-c4e" customClass="Section" customModule="app">
                                     <rect key="frame" x="0.0" y="0.0" width="320" height="50"/>
                                 </view>
                                 <view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="9nu-j1-wGI" customClass="Section" customModule="app">

+ 22 - 22
app/LablancaView.xib

@@ -1,11 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
     <device id="retina4_7" orientation="portrait">
         <adaptation id="fullscreen"/>
     </device>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
         <capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
@@ -33,13 +33,13 @@
                     <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
                     <subviews>
                         <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="onh-i9-8Tz">
-                            <rect key="frame" x="0.0" y="0.0" width="375" height="1255.5"/>
+                            <rect key="frame" x="0.0" y="0.0" width="375" height="1395.5"/>
                             <subviews>
                                 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="1tl-Rf-vmM">
-                                    <rect key="frame" x="0.0" y="0.0" width="375" height="1255.5"/>
+                                    <rect key="frame" x="0.0" y="0.0" width="375" height="1395.5"/>
                                     <subviews>
                                         <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ANk-4K-DBn" userLabel="NoFestivals">
-                                            <rect key="frame" x="10" y="10" width="355" height="1235.5"/>
+                                            <rect key="frame" x="10" y="10" width="355" height="1375.5"/>
                                             <subviews>
                                                 <label opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" restorationIdentifier="NFTitle" text="NoFestivals" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="rbu-EN-1UC" userLabel="NFTitle">
                                                     <rect key="frame" x="0.0" y="0.0" width="355" height="30"/>
@@ -52,13 +52,13 @@
                                                     <nil key="highlightedColor"/>
                                                 </label>
                                                 <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="61P-J5-lJc">
-                                                    <rect key="frame" x="0.0" y="30" width="355" height="1205.5"/>
+                                                    <rect key="frame" x="0.0" y="30" width="355" height="1345.5"/>
                                                     <subviews>
                                                         <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fMm-Rh-0GJ">
-                                                            <rect key="frame" x="0.0" y="0.0" width="355" height="1205.5"/>
+                                                            <rect key="frame" x="0.0" y="0.0" width="355" height="1345.5"/>
                                                             <subviews>
                                                                 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="JSe-pA-fF3" userLabel="NFText">
-                                                                    <rect key="frame" x="8" y="8" width="339" height="1189.5"/>
+                                                                    <rect key="frame" x="8" y="8" width="339" height="1329.5"/>
                                                                     <string key="text">Las Fiestas de La Blanca. Esos días, del 4 al 9 de agosto, en los que Vitoria-Gasteiz se transforma. Se llena de color y alegría, y en cada esquina puedes encontrar actividades y espectáculos.
 
 Nosotros, como cuadrilla de Blusas y Nescas, ya estamos trabajando en ello. Tan pronto como vayamos sabiendo más, aquí iremos publicando nuestro programa y otra información sobre las fiestas.
@@ -119,15 +119,15 @@ Margolaris: Todo lo demás no sirve de nada si en una cuadrilla no hay buen ambi
                                             </userDefinedRuntimeAttributes>
                                         </view>
                                         <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="O30-vI-Tga" userLabel="Festivals">
-                                            <rect key="frame" x="10" y="10" width="355" height="1235.5"/>
+                                            <rect key="frame" x="10" y="10" width="355" height="1375.5"/>
                                             <subviews>
                                                 <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="zWn-KM-9py">
-                                                    <rect key="frame" x="0.0" y="0.0" width="355" height="1235.5"/>
+                                                    <rect key="frame" x="0.0" y="0.0" width="355" height="1375.5"/>
                                                     <subviews>
                                                         <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Trj-oS-RaI" userLabel="FestivalsIntro">
                                                             <rect key="frame" x="0.0" y="0.0" width="355" height="300"/>
                                                             <subviews>
-                                                                <label opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" restorationIdentifier="FTitle" text="Festivals" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Uf0-CR-dfk" userLabel="FTitle">
+                                                                <label opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" restorationIdentifier="FTitle" text=" Fiestas de La Blanca" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Uf0-CR-dfk" userLabel="FTitle">
                                                                     <rect key="frame" x="0.0" y="0.0" width="355" height="30"/>
                                                                     <color key="backgroundColor" red="0.0" green="0.47058823529999999" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                                                     <constraints>
@@ -260,9 +260,9 @@ Margolaris: Todo lo demás no sirve de nada si en una cuadrilla no hay buen ambi
                                                             </userDefinedRuntimeAttributes>
                                                         </view>
                                                         <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="feb-ob-HAK" userLabel="FestivalsPrices">
-                                                            <rect key="frame" x="0.0" y="410" width="355" height="825.5"/>
+                                                            <rect key="frame" x="0.0" y="410" width="355" height="965.5"/>
                                                             <subviews>
-                                                                <label opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Programas de Fiestas" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="swA-jU-3wo" userLabel="FesivalsPricesTitle">
+                                                                <label opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Precios y ofertas" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="swA-jU-3wo" userLabel="FesivalsPricesTitle">
                                                                     <rect key="frame" x="0.0" y="0.0" width="355" height="30"/>
                                                                     <color key="backgroundColor" red="0.0" green="0.47058823529999999" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                                                     <constraints>
@@ -277,27 +277,27 @@ Margolaris: Todo lo demás no sirve de nada si en una cuadrilla no hay buen ambi
                                                                     <constraints>
                                                                         <constraint firstAttribute="height" constant="20" id="lCP-xA-gT6"/>
                                                                     </constraints>
-                                                                    <fontDescription key="fontDescription" type="system" pointSize="17"/>
-                                                                    <nil key="textColor"/>
+                                                                    <fontDescription key="fontDescription" type="boldSystem" pointSize="18"/>
+                                                                    <color key="textColor" red="0.1529411765" green="0.33333333329999998" blue="0.45098039220000002" alpha="1" colorSpace="calibratedRGB"/>
                                                                     <nil key="highlightedColor"/>
                                                                 </label>
                                                                 <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="rcX-IS-Hmj" userLabel="StackOffers">
-                                                                    <rect key="frame" x="13" y="70" width="330" height="200"/>
+                                                                    <rect key="frame" x="13" y="70" width="330" height="330"/>
                                                                     <constraints>
-                                                                        <constraint firstAttribute="height" constant="200" id="YNZ-ap-Ful"/>
+                                                                        <constraint firstAttribute="height" constant="330" id="YNZ-ap-Ful"/>
                                                                     </constraints>
                                                                 </stackView>
                                                                 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Dias sueltos" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xp7-EC-6OW">
-                                                                    <rect key="frame" x="8" y="285" width="339" height="20.5"/>
+                                                                    <rect key="frame" x="8" y="425" width="339" height="20.5"/>
                                                                     <constraints>
                                                                         <constraint firstAttribute="height" constant="20" id="Ecc-N8-k3S"/>
                                                                     </constraints>
-                                                                    <fontDescription key="fontDescription" type="system" pointSize="17"/>
-                                                                    <nil key="textColor"/>
+                                                                    <fontDescription key="fontDescription" type="boldSystem" pointSize="18"/>
+                                                                    <color key="textColor" red="0.1529411765" green="0.33333333329999998" blue="0.45098039220000002" alpha="1" colorSpace="calibratedRGB"/>
                                                                     <nil key="highlightedColor"/>
                                                                 </label>
                                                                 <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="qKn-wk-VDT" userLabel="StackDays">
-                                                                    <rect key="frame" x="12.5" y="315.5" width="330" height="510"/>
+                                                                    <rect key="frame" x="12.5" y="455.5" width="330" height="510"/>
                                                                     <constraints>
                                                                         <constraint firstAttribute="height" constant="510" id="Hzw-0S-h69"/>
                                                                     </constraints>
@@ -306,7 +306,7 @@ Margolaris: Todo lo demás no sirve de nada si en una cuadrilla no hay buen ambi
                                                             <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                                             <constraints>
                                                                 <constraint firstItem="swA-jU-3wo" firstAttribute="top" secondItem="feb-ob-HAK" secondAttribute="top" id="7hg-wz-EVN"/>
-                                                                <constraint firstItem="xp7-EC-6OW" firstAttribute="top" secondItem="rcX-IS-Hmj" secondAttribute="bottom" constant="15" id="EiC-Rv-Dog"/>
+                                                                <constraint firstItem="xp7-EC-6OW" firstAttribute="top" secondItem="rcX-IS-Hmj" secondAttribute="bottom" constant="25" id="EiC-Rv-Dog"/>
                                                                 <constraint firstItem="xp7-EC-6OW" firstAttribute="width" secondItem="feb-ob-HAK" secondAttribute="width" constant="-16" id="Gg5-Ev-py5"/>
                                                                 <constraint firstItem="swA-jU-3wo" firstAttribute="width" secondItem="feb-ob-HAK" secondAttribute="width" id="Gj1-HV-kbf"/>
                                                                 <constraint firstItem="xp7-EC-6OW" firstAttribute="centerX" secondItem="feb-ob-HAK" secondAttribute="centerX" id="HFH-0V-hcn"/>

+ 12 - 12
app/RowLablancaOffer.xib

@@ -28,24 +28,24 @@
                     <rect key="frame" x="0.0" y="278.5" width="375" height="110"/>
                     <subviews>
                         <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Name" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="W8f-8e-Vh4" userLabel="Name">
-                            <rect key="frame" x="10" y="0.0" width="285" height="30"/>
+                            <rect key="frame" x="10" y="0.0" width="355" height="30"/>
                             <constraints>
                                 <constraint firstAttribute="height" constant="30" id="9HV-WP-2oH"/>
                             </constraints>
-                            <fontDescription key="fontDescription" type="boldSystem" pointSize="30"/>
+                            <fontDescription key="fontDescription" type="boldSystem" pointSize="22"/>
                             <nil key="textColor"/>
                             <nil key="highlightedColor"/>
                         </label>
                         <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Description" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="OZG-PW-52K" userLabel="Description">
-                            <rect key="frame" x="15" y="30" width="270" height="64"/>
-                            <fontDescription key="fontDescription" type="system" pointSize="17"/>
-                            <nil key="textColor"/>
+                            <rect key="frame" x="10" y="30" width="260" height="69"/>
+                            <fontDescription key="fontDescription" type="system" pointSize="15"/>
+                            <color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
                             <nil key="highlightedColor"/>
                         </label>
                         <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="60 E" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="t8q-un-0XX" userLabel="Price">
-                            <rect key="frame" x="295" y="0.0" width="70" height="110"/>
+                            <rect key="frame" x="275" y="30" width="90" height="80"/>
                             <constraints>
-                                <constraint firstAttribute="width" constant="70" id="gbg-aG-Zmc"/>
+                                <constraint firstAttribute="width" constant="90" id="gbg-aG-Zmc"/>
                             </constraints>
                             <fontDescription key="fontDescription" type="boldSystem" pointSize="30"/>
                             <color key="textColor" red="0.0" green="0.47058823529999999" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
@@ -66,13 +66,13 @@
                         <constraint firstAttribute="height" constant="110" id="GMt-Dq-C0S"/>
                         <constraint firstItem="W8f-8e-Vh4" firstAttribute="top" secondItem="PZc-6H-I81" secondAttribute="top" id="LxG-fT-ndV"/>
                         <constraint firstItem="OZG-PW-52K" firstAttribute="top" secondItem="W8f-8e-Vh4" secondAttribute="bottom" id="PUk-Sf-BmJ"/>
-                        <constraint firstItem="OZG-PW-52K" firstAttribute="trailing" secondItem="t8q-un-0XX" secondAttribute="leading" constant="-10" id="R2G-LD-nql"/>
-                        <constraint firstItem="t8q-un-0XX" firstAttribute="height" secondItem="PZc-6H-I81" secondAttribute="height" id="aJN-bs-o8J"/>
-                        <constraint firstItem="OZG-PW-52K" firstAttribute="bottom" secondItem="I6q-za-hiX" secondAttribute="top" constant="-10" id="iBu-xJ-9uF"/>
-                        <constraint firstItem="W8f-8e-Vh4" firstAttribute="trailing" secondItem="t8q-un-0XX" secondAttribute="leading" id="r4u-JN-4Ha"/>
+                        <constraint firstItem="OZG-PW-52K" firstAttribute="trailing" secondItem="t8q-un-0XX" secondAttribute="leading" constant="-5" id="R2G-LD-nql"/>
+                        <constraint firstItem="OZG-PW-52K" firstAttribute="bottom" secondItem="I6q-za-hiX" secondAttribute="top" constant="-5" id="iBu-xJ-9uF"/>
+                        <constraint firstItem="W8f-8e-Vh4" firstAttribute="trailing" secondItem="t8q-un-0XX" secondAttribute="trailing" id="r4u-JN-4Ha"/>
                         <constraint firstItem="W8f-8e-Vh4" firstAttribute="leading" secondItem="PZc-6H-I81" secondAttribute="leading" constant="10" id="tzL-MW-RWT"/>
-                        <constraint firstItem="OZG-PW-52K" firstAttribute="leading" secondItem="PZc-6H-I81" secondAttribute="leading" constant="15" id="vna-d2-mZd"/>
+                        <constraint firstItem="OZG-PW-52K" firstAttribute="leading" secondItem="PZc-6H-I81" secondAttribute="leading" constant="10" id="vna-d2-mZd"/>
                         <constraint firstAttribute="bottom" secondItem="I6q-za-hiX" secondAttribute="bottom" constant="5" id="wFz-ft-j8d"/>
+                        <constraint firstItem="t8q-un-0XX" firstAttribute="top" secondItem="W8f-8e-Vh4" secondAttribute="bottom" id="yuo-bb-5cI"/>
                         <constraint firstItem="I6q-za-hiX" firstAttribute="width" secondItem="PZc-6H-I81" secondAttribute="width" multiplier="0.9" id="zPU-dZ-XRD"/>
                         <constraint firstItem="I6q-za-hiX" firstAttribute="centerX" secondItem="PZc-6H-I81" secondAttribute="centerX" id="zcK-G2-veL"/>
                     </constraints>

+ 111 - 24
app/ScheduleViewController.swift

@@ -27,12 +27,15 @@ The controller of the schedule view.
 class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 
 	// Outlets
+	@IBOutlet weak var lbWindowTitle: UILabel!
 	@IBOutlet weak var btPrev: UIButton!
 	@IBOutlet weak var btNext: UIButton!
 	@IBOutlet weak var lbDayNumber: UILabel!
 	@IBOutlet weak var lbDayMonth: UILabel!
 	@IBOutlet weak var lbDayName: UILabel!
 	@IBOutlet weak var svScheduleList: UIStackView!
+	@IBOutlet weak var lbToolbarTitle: UILabel!
+	@IBOutlet weak var btToolbarButton: UIButton!
 	
 	var context: NSManagedObjectContext? = nil
 	var lang: String? = nil
@@ -42,7 +45,7 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 	var margolari: Bool = false
 
 	// Day indicator
-	var days: [String] = [String]()
+	var days: [NSDate] = [NSDate]()
 	var selectedDay: Int = 0
 
 	/**
@@ -63,10 +66,18 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 		super.viewDidLoad()
 		self.loadSchedule(margolari: margolari)
 		
-		//TODO Title
+		// Set titles
+		if margolari == true{
+			lbToolbarTitle.text = " Programa Margolari"
+			lbWindowTitle.text = " Programa Margolari"
+		}
+		else{
+			lbToolbarTitle.text = " Programa de Fiestas"
+			lbWindowTitle.text = " Programa de Fiestas"
+		}
 		
-		// TODO Set button action
-		//barButton.addTarget(self, action: #selector(self.back), for: .touchUpInside)
+		// Set back button action
+		btToolbarButton.addTarget(self, action: #selector(self.back), for: .touchUpInside)
 	}
 	
 	/**
@@ -106,25 +117,45 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 		self.context?.persistentStoreCoordinator = self.delegate?.persistentStoreCoordinator
 
 		// Get days
+		// TODO: Get current year
+		let year = 2016
+		let dateFormatter = DateFormatter()
+		dateFormatter.dateFormat = "yyyy-MM-dd"
+		dateFormatter.locale = Locale.init(identifier: "en_GB")
+		var dateString = "\(year)-01-01"
+		let sDate = dateFormatter.date(from: dateString)
+		dateString = "\(year)-12-31"
+		let eDate = dateFormatter.date(from: dateString)
 		let dayFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Festival_event")
 		dayFetchRequest.propertiesToFetch = ["day"]
 		if self.margolari == true{
-			dayFetchRequest.predicate = NSPredicate(format: "gm = %i", 1)
+			dayFetchRequest.predicate = NSPredicate(format: "(gm = %i) AND (start >= %@) AND (start <= %@)", argumentArray: [1, sDate, eDate])
 		}
 		else{
-			dayFetchRequest.predicate = NSPredicate(format: "gm = %i", 0)
+			dayFetchRequest.predicate = NSPredicate(format: "(gm = %i) AND (start >= %@) AND (start <= %@)", argumentArray: [0, sDate, eDate])
 		}
 
 		dayFetchRequest.returnsDistinctResults = true
-		dayFetchRequest.resultType = NSFetchRequestResultType.dictionaryResultType
+		//dayFetchRequest.resultType = NSFetchRequestResultType.dictionaryResultType
 
 		do {
 			let results = try self.context?.fetch(dayFetchRequest)
-
-				let resultsDict = results as! [[String: String]]
-				for r in resultsDict {
-					self.days.append(r["name"]!)
+			
+			for r in results as! [NSManagedObject] {
+				let day: NSDate = r.value(forKey: "day") as! NSDate
+				// Don't add duplicates
+				if self.days.contains(day) == false{
+					NSLog(":SCHEDULECONTROLLER:DEBUG: Day \(day)")
+					self.days.append(day)
 				}
+			}
+
+			/*let resultsDict = results as! [[String: String]]
+			for r in resultsDict {
+				//let dayStr: String = r.value(forKey: "day") as! String
+				NSLog(":SCHEDULECONTROLLER:DEBUG: Day \(r["day"])")
+				//self.days.append(r.value(forKey: "day") as! NSDate)
+			}*/
 
 		}
 		catch let err as NSError {
@@ -154,8 +185,64 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 	*/
 	func loadDay(){
 		
-		// TODO: Clear list.
+		let dateFormatter = DateFormatter()
+		dateFormatter.dateFormat = "yyyy-MM-dd"
+		dateFormatter.locale = Locale.init(identifier: "en_GB")
+		
+		// Clear list.
+		for v in (self.svScheduleList?.subviews)!{
+			v.removeFromSuperview()
+		}
+		
 		// TODO: Set toolbar elements.
+		if margolari == true{
+			let dayFetchRequest: NSFetchRequest<Festival_day> = Festival_day.fetchRequest()
+			dayFetchRequest.predicate = NSPredicate(format: "date = %@", argumentArray: [days[selectedDay]])
+			var name: String = ""
+			do {
+				let daySearchResults = try self.context?.fetch(dayFetchRequest)
+				for r in daySearchResults as! [NSManagedObject] {
+					name = r.value(forKey: "name_\(lang!)") as! String
+				}
+				self.lbDayName.text = name
+			}
+			catch {
+				NSLog(":SCHEDULECONTROLLER:ERROR: Error getting info about days: \(error)")
+			}
+		}
+		else{
+			self.lbDayName.text = ""
+		}
+		let dateString: String = dateFormatter.string(from: days[selectedDay] as Date)
+		let nDay: String = dateString.subStr(start: 8, end: 9)
+		let month: String = dateString.subStr(start: 5, end: 6)
+		var nMonth: String = "Agosto" // TODO: Reference
+		if month == "07"{
+			nMonth = "Julio" // TODO: Reference
+		}
+		self.lbDayMonth.text = nMonth
+		self.lbDayNumber.text = "\(Int(nDay)!)"
+		
+		// Enable or disable buttons
+		if self.selectedDay <= 0{
+			self.btPrev.alpha = 0.5
+			self.btPrev.isUserInteractionEnabled = false
+		}
+		else{
+			self.btPrev.alpha = 1
+			self.btPrev.isUserInteractionEnabled = true
+		}
+		if self.selectedDay >= (days.count - 1){
+			self.btNext.alpha = 0.5
+			self.btNext.isUserInteractionEnabled = false
+		}
+		else{
+			self.btNext.alpha = 1
+			self.btNext.isUserInteractionEnabled = true
+		}
+
+		
+		
 		
 		var rowcount = 0
 		var row: RowSchedule
@@ -166,15 +253,15 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 		var location: String
 
 		let fetchRequest: NSFetchRequest<Festival_event> = Festival_event.fetchRequest()
-		let sortDescriptor = NSSortDescriptor(key: "start", ascending: false)
+		let sortDescriptor = NSSortDescriptor(key: "start", ascending: true)
 		let sortDescriptors = [sortDescriptor]
 		fetchRequest.sortDescriptors = sortDescriptors
 		
 		if margolari == true{
-			fetchRequest.predicate = NSPredicate(format: "(gm = %i) AND (day = @)", argumentArray: [1, days[selectedDay]])
+			fetchRequest.predicate = NSPredicate(format: "(gm = %i) AND (day = %@)", argumentArray: [1, days[selectedDay]])
 		}
 		else{
-			fetchRequest.predicate = NSPredicate(format: "(gm = %i) AND (day = @)", argumentArray: [0, days[selectedDay]])
+			fetchRequest.predicate = NSPredicate(format: "(gm = %i) AND (day = %@)", argumentArray: [0, days[selectedDay]])
 		}
 				
 		do {
@@ -186,9 +273,9 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 			
 			for r in searchResults as! [NSManagedObject] {
 				
-				title = r.value(forKey: "title_\(lang)") as! String
-				if let tx = r.value(forKey: "description_\(lang)"){
-					text = r.value(forKey: "description_\(lang)") as! String
+				title = r.value(forKey: "title_\(lang!)") as! String
+				if let tx = r.value(forKey: "description_\(lang!)"){
+					text = r.value(forKey: "description_\(lang!)") as! String
 				}
 				else{
 					text = ""
@@ -208,14 +295,13 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 				do{
 					var locationSearchResults = try self.context?.fetch(locationFetchRequest)
 					var locationR = locationSearchResults?[0]
-					location = locationR?.value(forKey: "name_\(lang)")! as! String
+					location = locationR?.value(forKey: "name_\(lang!)")! as! String
 					
 					row.setLocation(text: location)
 				} catch {
 					NSLog(":SCHEDULECONTROLLER:ERROR: Error getting location: \(error)")
 				}
 				
-				NSLog(":SCHEDULECONTROLLER:DEBUG: Adding row: height: \(row.frame.height)")
 				svScheduleList.addArrangedSubview(row)
 				
 				rowcount = rowcount + 1
@@ -255,12 +341,13 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 	:param: increment Days to advance the schedule. Negative values to back it up.
 	*/
 	func changeDay(increment: Int){
-		selectedDay = selectedDay + increment
-		if selectedDay <= -1{
-			selectedDay = 0
+		NSLog(":SCHEDULECONTROLLER:DEBUG: Change day increment: \(increment)")
+		self.selectedDay = self.selectedDay + increment
+		if self.selectedDay <= -1{
+			self.selectedDay = 0
 		}
 		if self.selectedDay >= self.days.count{
-			selectedDay = (self.days.count - 1)
+			self.selectedDay = (self.days.count - 1)
 		}
 		loadDay()
 	}

+ 2 - 2
app/ViewController.swift

@@ -171,8 +171,8 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	func populate(){
 		if (self.containerViewHome != nil){
 			//(self.containerViewHome as HomeView).populate2()
-			let ng = self.containerViewHome.dbgTxt
-			NSLog("AAAAA \(ng)")
+			//let ng = self.containerViewHome.dbgTxt
+			//NSLog("AAAAA \(ng)")
 		}
 		else{
 			NSLog("CONTROLLER:ERROR: containerViewHome couldn't be populated: It is nil.")