Forráskód Böngészése

Fixes in location reports, schedule and COREDATA.

Iñigo Valentin 8 éve
szülő
commit
798777db2c

BIN
.DS_Store


+ 20 - 20
app.xcodeproj/project.pbxproj

@@ -178,6 +178,8 @@
 		93EB2F0B1EBF5AEB00F64186 /* RowSchedule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowSchedule.swift; sourceTree = "<group>"; };
 		93EB2F0D1EBF5BF500F64186 /* RowSchedule.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RowSchedule.xib; sourceTree = "<group>"; };
 		93EE9ECA1EE9B87100288F6E /* PastActivityViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PastActivityViewController.swift; sourceTree = "<group>"; };
+		FC27E07220E95ABB00963227 /* Base */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Base; path = "app/Base.lproj/Festival_event_city+CoreDataClass.swift"; sourceTree = "<group>"; };
+		FC27E07420E95ABD00963227 /* Base */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Base; path = "app/Base.lproj/Festival_event_city+CoreDataProperties.swift"; sourceTree = "<group>"; };
 		FC63DC6420DC16B300C9A2E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Base; path = "app/Base.lproj/Activity_comment+CoreDataClass.swift"; sourceTree = "<group>"; };
 		FC63DC6620DC16B300C9A2E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Base; path = "app/Base.lproj/Activity_comment+CoreDataProperties.swift"; sourceTree = "<group>"; };
 		FC63DC6820DC16B300C9A2E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Base; path = "app/Base.lproj/Photo+CoreDataClass.swift"; sourceTree = "<group>"; };
@@ -192,8 +194,6 @@
 		FC63DC7A20DC16B300C9A2E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Base; path = "app/Base.lproj/Festival_offer+CoreDataProperties.swift"; sourceTree = "<group>"; };
 		FC63DC7C20DC16B300C9A2E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Base; path = "app/Base.lproj/Route_point+CoreDataClass.swift"; sourceTree = "<group>"; };
 		FC63DC7E20DC16B300C9A2E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Base; path = "app/Base.lproj/Route_point+CoreDataProperties.swift"; sourceTree = "<group>"; };
-		FC63DC8020DC16B300C9A2E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Base; path = "app/Base.lproj/Festival_event+CoreDataClass.swift"; sourceTree = "<group>"; };
-		FC63DC8220DC16B300C9A2E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Base; path = "app/Base.lproj/Festival_event+CoreDataProperties.swift"; sourceTree = "<group>"; };
 		FC63DC8420DC16B300C9A2E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Base; path = "app/Base.lproj/Activity+CoreDataClass.swift"; sourceTree = "<group>"; };
 		FC63DC8620DC16B300C9A2E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Base; path = "app/Base.lproj/Activity+CoreDataProperties.swift"; sourceTree = "<group>"; };
 		FC63DC8820DC16B300C9A2E1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Base; path = "app/Base.lproj/Version+CoreDataClass.swift"; sourceTree = "<group>"; };
@@ -379,6 +379,8 @@
 			isa = PBXGroup;
 			children = (
 				FC63DC6320DC16B300C9A2E1 /* Activity_comment+CoreDataClass.swift */,
+				FC27E07120E95ABB00963227 /* Festival_event_city+CoreDataClass.swift */,
+				FC27E07320E95ABD00963227 /* Festival_event_city+CoreDataProperties.swift */,
 				FC63DC6520DC16B300C9A2E1 /* Activity_comment+CoreDataProperties.swift */,
 				FC63DC6720DC16B300C9A2E1 /* Photo+CoreDataClass.swift */,
 				FC63DC6920DC16B300C9A2E1 /* Photo+CoreDataProperties.swift */,
@@ -392,8 +394,6 @@
 				FC63DC7920DC16B300C9A2E1 /* Festival_offer+CoreDataProperties.swift */,
 				FC63DC7B20DC16B300C9A2E1 /* Route_point+CoreDataClass.swift */,
 				FC63DC7D20DC16B300C9A2E1 /* Route_point+CoreDataProperties.swift */,
-				FC63DC7F20DC16B300C9A2E1 /* Festival_event+CoreDataClass.swift */,
-				FC63DC8120DC16B300C9A2E1 /* Festival_event+CoreDataProperties.swift */,
 				FC63DC8320DC16B300C9A2E1 /* Activity+CoreDataClass.swift */,
 				FC63DC8520DC16B300C9A2E1 /* Activity+CoreDataProperties.swift */,
 				FC63DC8720DC16B300C9A2E1 /* Version+CoreDataClass.swift */,
@@ -602,6 +602,22 @@
 			name = LaunchScreen.storyboard;
 			sourceTree = "<group>";
 		};
+		FC27E07120E95ABB00963227 /* Festival_event_city+CoreDataClass.swift */ = {
+			isa = PBXVariantGroup;
+			children = (
+				FC27E07220E95ABB00963227 /* Base */,
+			);
+			name = "Festival_event_city+CoreDataClass.swift";
+			sourceTree = "<group>";
+		};
+		FC27E07320E95ABD00963227 /* Festival_event_city+CoreDataProperties.swift */ = {
+			isa = PBXVariantGroup;
+			children = (
+				FC27E07420E95ABD00963227 /* Base */,
+			);
+			name = "Festival_event_city+CoreDataProperties.swift";
+			sourceTree = "<group>";
+		};
 		FC63DC6320DC16B300C9A2E1 /* Activity_comment+CoreDataClass.swift */ = {
 			isa = PBXVariantGroup;
 			children = (
@@ -714,22 +730,6 @@
 			name = "Route_point+CoreDataProperties.swift";
 			sourceTree = "<group>";
 		};
-		FC63DC7F20DC16B300C9A2E1 /* Festival_event+CoreDataClass.swift */ = {
-			isa = PBXVariantGroup;
-			children = (
-				FC63DC8020DC16B300C9A2E1 /* Base */,
-			);
-			name = "Festival_event+CoreDataClass.swift";
-			sourceTree = "<group>";
-		};
-		FC63DC8120DC16B300C9A2E1 /* Festival_event+CoreDataProperties.swift */ = {
-			isa = PBXVariantGroup;
-			children = (
-				FC63DC8220DC16B300C9A2E1 /* Base */,
-			);
-			name = "Festival_event+CoreDataProperties.swift";
-			sourceTree = "<group>";
-		};
 		FC63DC8320DC16B300C9A2E1 /* Activity+CoreDataClass.swift */ = {
 			isa = PBXVariantGroup;
 			children = (

+ 1 - 3
app/FetchLocation.swift

@@ -41,9 +41,7 @@ class FetchLocation{
 	func fetch(){
 		NSLog(":LOCATION:LOG: Fetching location...")
 		
-		// TODO Change for production
-		//let url = URL(string: "https://margolariak.com/API/V1/location.php")
-		let url = URL(string: "http://192.168.1.101/API/V3/location.php")
+        let url = URL(string: "https://margolariak.com/API/V3/location.php")
 		
 		let task = URLSession.shared.dataTask(with: url!) { data, response, error in
 			if error != nil {

+ 1 - 1
app/HomeView.swift

@@ -202,7 +202,7 @@ class HomeView: UIView {
 				self.lablancaSection.addGestureRecognizer(tapRecognizer)
 				
 				// TODO: Get current year
-				let year = 2017
+				let year = 2018
 				
 				// Get info about festivals
 				let fetchRequest: NSFetchRequest<Festival> = Festival.fetchRequest()

+ 1 - 1
app/LablancaView.swift

@@ -88,7 +88,7 @@ class LablancaView: UIView {
 		self.nfWindow.isHidden = true
 		
 		// TODO: Get current year
-		let year = 2017
+		let year = 2018
 		
 		let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
 		let appDelegate = UIApplication.shared.delegate as! AppDelegate

+ 7 - 7
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="12121" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14113" 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="12089"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
         <capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
@@ -41,7 +41,7 @@
                                         <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ANk-4K-DBn" userLabel="NoFestivals">
                                             <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">
+                                                <label opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" restorationIdentifier="NFTitle" text=" Fiestas de La Blanca" 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"/>
                                                     <color key="backgroundColor" red="0.0" green="0.47058823529999999" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                                     <constraints>
@@ -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="1345.5"/>
+                                                    <rect key="frame" x="0.0" y="40" width="355" height="1335.5"/>
                                                     <subviews>
                                                         <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fMm-Rh-0GJ">
-                                                            <rect key="frame" x="0.0" y="0.0" width="355" height="1345.5"/>
+                                                            <rect key="frame" x="0.0" y="0.0" width="355" height="1335.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="1329.5"/>
+                                                                    <rect key="frame" x="8" y="8" width="339" height="1319.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.
@@ -98,7 +98,7 @@ Margolaris: Todo lo demás no sirve de nada si en una cuadrilla no hay buen ambi
                                             <color key="backgroundColor" red="0.59607843137254901" green="0.78431372549019607" blue="1" alpha="1" colorSpace="calibratedRGB"/>
                                             <constraints>
                                                 <constraint firstItem="rbu-EN-1UC" firstAttribute="width" secondItem="ANk-4K-DBn" secondAttribute="width" id="2rM-dk-8qK"/>
-                                                <constraint firstItem="61P-J5-lJc" firstAttribute="top" secondItem="rbu-EN-1UC" secondAttribute="bottom" id="8zQ-01-cy2"/>
+                                                <constraint firstItem="61P-J5-lJc" firstAttribute="top" secondItem="rbu-EN-1UC" secondAttribute="bottom" constant="10" id="8zQ-01-cy2"/>
                                                 <constraint firstItem="rbu-EN-1UC" firstAttribute="top" secondItem="ANk-4K-DBn" secondAttribute="top" id="EtJ-4V-V4H"/>
                                                 <constraint firstAttribute="bottom" secondItem="61P-J5-lJc" secondAttribute="bottom" id="H19-rV-6q8"/>
                                                 <constraint firstItem="rbu-EN-1UC" firstAttribute="centerX" secondItem="ANk-4K-DBn" secondAttribute="centerX" id="YlB-Dt-nSZ"/>

+ 0 - 16
app/NSManagedObjects/app/Base.lproj/Festival_event+CoreDataClass.swift

@@ -1,16 +0,0 @@
-//
-//  Festival_event+CoreDataClass.swift
-//  app
-//
-//  Created by Iñigo Valentin on 21/6/18.
-//  Copyright © 2018 Margolariak. All rights reserved.
-//
-//
-
-import Foundation
-import CoreData
-
-
-public class Festival_event: NSManagedObject {
-
-}

+ 0 - 35
app/NSManagedObjects/app/Base.lproj/Festival_event+CoreDataProperties.swift

@@ -1,35 +0,0 @@
-//
-//  Festival_event+CoreDataProperties.swift
-//  app
-//
-//  Created by Iñigo Valentin on 21/6/18.
-//  Copyright © 2018 Margolariak. All rights reserved.
-//
-//
-
-import Foundation
-import CoreData
-
-
-extension Festival_event {
-
-    @nonobjc public class func fetchRequest() -> NSFetchRequest<Festival_event> {
-        return NSFetchRequest<Festival_event>(entityName: "Festival_event_city")
-    }
-
-    @NSManaged public var day: NSDate?
-    @NSManaged public var description_en: String?
-    @NSManaged public var description_es: String?
-    @NSManaged public var description_eu: String?
-    @NSManaged public var end: NSDate?
-    @NSManaged public var host: Int32
-    @NSManaged public var id: Int32
-    @NSManaged public var place: Int32
-    @NSManaged public var route: Int32
-    @NSManaged public var sponsor: Int32
-    @NSManaged public var start: NSDate?
-    @NSManaged public var title_en: String?
-    @NSManaged public var title_es: String?
-    @NSManaged public var title_eu: String?
-
-}

+ 2 - 2
app/RowLablancaDay.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="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14113" 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="11757"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
         <capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>

+ 101 - 35
app/ScheduleViewController.swift

@@ -115,7 +115,7 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 		
 		// Get days
 		// TODO: Get current year
-		let year = 2017
+		let year = 2018
 		let dateFormatter = DateFormatter()
 		dateFormatter.dateFormat = "yyyy-MM-dd"
 		dateFormatter.locale = Locale.init(identifier: "en_GB")
@@ -175,24 +175,32 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 		dateFormatter.locale = Locale.init(identifier: "en_GB")
 		
 		// Clear list.
-		for v in (self.svScheduleList?.subviews)!{
-			v.removeFromSuperview()
-		}
+        DispatchQueue.main.async() {
+            for v in (self.svScheduleList?.subviews)!{
+                v.removeFromSuperview()
+            }
+        }
+
 		
 		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! {
-					name = (r.value(forKey: "name_\(lang!)") as! String).decode()
-				}
-				self.lbDayName.text = name
-			}
-			catch {
-				NSLog(":SCHEDULECONTROLLER:ERROR: Error getting info about days: \(error)")
-			}
+            if selectedDay >= 0 && selectedDay < days.count{
+                dayFetchRequest.predicate = NSPredicate(format: "date = %@", argumentArray: [days[selectedDay]])
+                var name: String = ""
+                do {
+                    let daySearchResults = try self.context?.fetch(dayFetchRequest)
+                    for r in daySearchResults! {
+                        name = (r.value(forKey: "name_\(lang!)") as! String).decode()
+                    }
+                    self.lbDayName.text = name
+                }
+                catch{
+                    NSLog(":SCHEDULECONTROLLER:ERROR: Error getting info about days: \(error)")
+                }
+            }
+            else{
+                NSLog(":SCHEDULECONTROLLER:ERROR: No events")
+            }
 		}
 		else{
 			self.lbDayName.text = ""
@@ -214,23 +222,11 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 		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
-		}
+		// Disable all arrow buttons to prevent fast clicking, which leads to the list not being cleared
+        self.btPrev.alpha = 0.5
+        self.btPrev.isUserInteractionEnabled = false
+        self.btNext.alpha = 0.5
+        self.btNext.isUserInteractionEnabled = false
 		
 		var rowcount = 0
 		var row: RowSchedule
@@ -249,6 +245,8 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 			
 			if margolari == true{
 				let fetchRequest: NSFetchRequest<Festival_event_gm> = Festival_event_gm.fetchRequest()
+                fetchRequest.predicate = NSPredicate(format: "day = %@", days[selectedDay] as NSDate)
+                //fetchRequest.predicate = NSPredicate(format: "day = %@", argumentArray: [days[selectedDay]])
 				let sortDescriptor = NSSortDescriptor(key: "start", ascending: true)
 				let sortDescriptors = [sortDescriptor]
 				fetchRequest.sortDescriptors = sortDescriptors
@@ -299,11 +297,74 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 				}
 				
 			} // if margolari == true
+            else{
+                let fetchRequest: NSFetchRequest<Festival_event> = Festival_event.fetchRequest()
+                fetchRequest.predicate = NSPredicate(format: "day = %@", days[selectedDay] as NSDate)
+                let sortDescriptor = NSSortDescriptor(key: "start", ascending: true)
+                let sortDescriptors = [sortDescriptor]
+                fetchRequest.sortDescriptors = sortDescriptors
+                let searchResults = try self.context?.fetch(fetchRequest)
+                
+                for r in searchResults! {
+                    
+                    id = r.value(forKey: "id") as! Int
+                    
+                    title = r.value(forKey: "title_\(lang!)") as! String
+                    if r.value(forKey: "description_\(lang!)") != nil{
+                        text = r.value(forKey: "description_\(lang!)") as! String
+                    }
+                    else{
+                        text = ""
+                    }
+                    start = r.value(forKey: "start")! as! NSDate
+                    locationId = r.value(forKey: "place")! as! Int
+                    row = RowSchedule.init(s: "rowSchedule\(rowcount)", i: rowcount)
+                    
+                    row.setTitle(text: title)
+                    row.setText(text: text)
+                    row.setTime(dtime: start)
+                    row.id = id
+                    
+                    // Get location info from Place entity
+                    let locationFetchRequest: NSFetchRequest<Place> = Place.fetchRequest()
+                    locationFetchRequest.predicate = NSPredicate(format: "id == %i", locationId)
+                    locationFetchRequest.fetchLimit = 1
+                    do{
+                        var locationSearchResults = try self.context?.fetch(locationFetchRequest)
+                        if (locationSearchResults?.count)! > 0{
+                            let locationR = locationSearchResults?[0]
+                            location = locationR?.value(forKey: "name_\(lang!)")! as! String
+                            row.setLocation(text: location)
+                        }
+                        else{
+                            row.setLocation(text: "")
+                        }
+                    }
+                    catch {
+                        NSLog(":SCHEDULECONTROLLER:ERROR: Error getting location: \(error)")
+                    }
+                    
+                    svScheduleList.addArrangedSubview(row)
+                    
+                    rowcount = rowcount + 1
+                }
+            }
 
 			svScheduleList.setNeedsLayout()
 			svScheduleList.layoutIfNeeded()
+            
+            // Enable buttons
+            if self.selectedDay > 0{
+                self.btPrev.alpha = 1
+                self.btPrev.isUserInteractionEnabled = true
+            }
+            if self.selectedDay < (days.count - 1){
+                self.btNext.alpha = 1
+                self.btNext.isUserInteractionEnabled = true
+            }
 
-		} catch {
+		}
+        catch {
 			NSLog(":SCHEDULECONTROLLER:ERROR: Error with event: \(error)")
 		}
 	}
@@ -350,7 +411,12 @@ class ScheduleViewController: UIViewController, UIGestureRecognizerDelegate {
 	*/
 	func showEvent(id: Int){
 		NSLog(":SCHEDULECONTROLLER:DEBUG: Show event \(id)")
-		self.passId = id
+        if id < 0{
+            self.passId = 0
+        }
+        else{
+            self.passId = id
+        }
 		performSegue(withIdentifier: "SegueEvent", sender: nil)
 	}
 	

+ 5 - 6
app/Sync.swift

@@ -85,7 +85,6 @@ class Sync{
 		}
 
 		// Build URL
-		// TODO: Change host for production
 		
 		var urlStr: String = ""
 		
@@ -93,7 +92,7 @@ class Sync{
 		//	urlStr = "https://margolariak.com/API/v3/fastsync.php?client=com.margolariak.app&user=\(uId)\(strVersions)"
 		//}
 		//else{
-			urlStr = "https://margolariak.com/API/v3/sync.php?client=com.margolariak.app&user=\(uId)\(strVersions)"
+            urlStr = "https://margolariak.com/API/v3/sync.php?client=com.margolariak.app&user=\(uId)\(strVersions)"
 		//}
 		let url = URL(string: urlStr)
 
@@ -210,16 +209,16 @@ class Sync{
 			while row.indexOf(target: ",\"") != nil{
 				tuple = row.subStr(start: 0, end: row.indexOf(target: ",\"")! - 1)
 				
-				column = tuple.subStr(start: tuple.indexOf(target: "\"")! + 1, end: tuple.indexOf(target: "\":")! - 1)
-				
-				if column.length + 4 >= tuple.length - 2{
+				column = tuple.subStr(start: tuple.indexOf(target: "\"")! + 1, end: tuple.indexOf(target: "\":")! - 1)
+                
+				if column.length + 4 > tuple.length - 2{
 					value = "ul"
 				}
 				else{
 					value = tuple.subStr(start: column.length + 4, end: tuple.length - 2)
 				}
 				
-				if value != "ul"{ // 'ul' rom 'null' or empty. If it is, just do nothing.
+				if value != "ul"{ // 'ul' from 'null' or empty. If it is, just do nothing.
 					if entity?.attributesByName[column]?.attributeType == .stringAttributeType{
 						query.setValue(value, forKey: column)
 					}