<file_sep>//
//  Categoria+CoreDataProperties.swift
//  ScreensApp
//
//  Created by Student on 12/15/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//
//  Choose "Create NSManagedObject Subclass…" from the Core Data editor menu
//  to delete and recreate this implementation file for your updated model.
//

import Foundation
import CoreData

extension Categoria {

    @NSManaged var cat_nome: String?

}
<file_sep>//
//  EventoDescricaoViewController.swift
//  ScreensApp
//
//  Created by Student on 12/16/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit

class EventoDescricaoViewController: UIViewController {

    //OutLets das Descricoes do Evento
    @IBOutlet weak var lblDataEvento: UILabel!
    @IBOutlet weak var lblNomeEvento: UILabel!
    @IBOutlet weak var lblNomeRua: UILabel!
    @IBOutlet weak var lblDescricao: UITextView!
    @IBOutlet weak var lblImagemEvento: UIImageView!
    @IBOutlet weak var lblCriadoPor: UILabel!
    @IBOutlet weak var lblTelContato: UILabel!
    var evento: Evento!
    
    //edito todos os campos com os atributos do evento selecionado
    override func viewDidLoad() {
        super.viewDidLoad()
        lblNomeEvento.text = evento.evn_nome
        lblNomeRua.text = evento.evn_endereco
        lblDescricao.text = evento.evn_descricao
        lblCriadoPor.text = evento.usuario?.usu_nome
        lblTelContato.text = evento.usuario?.usu_telefone
        lblDataEvento.text = evento.evn_data_evento
        lblImagemEvento.image = UIImage(data: evento.evn_imagem!)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
<file_sep>//
//  ViewController.swift
//  ScreensApp
//
//  Created by Student on 12/10/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit
import CoreData

class ViewController: UIViewController, UITableViewDataSource, NSFetchedResultsControllerDelegate {

    //outlet da tabela de eventos
    @IBOutlet weak var tblEventos: UITableView!
    var contexto = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
    var fetchedResultController: NSFetchedResultsController = NSFetchedResultsController()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        tblEventos.dataSource = self
        carregarEventos()
    }
    
    //carrego eventos do banco de dados
    func carregarEventos(){
        fetchedResultController = getFetchedResultController()
        fetchedResultController.delegate = self
        
        do{
            try fetchedResultController.performFetch()
        } catch let error as NSError {
            print("Erro ao buscar eventos: \(error), \(error.userInfo) ")
        }
    }
    
    
    //metodos que complementa o carregamento, passando a Tabela e a Ordenacao que sera realizada
    func getFetchedResultController() -> NSFetchedResultsController {
        fetchedResultController = NSFetchedResultsController( fetchRequest: eventoFetchRequest(), managedObjectContext: contexto, sectionNameKeyPath: nil , cacheName: nil )
        return fetchedResultController
    }

    func eventoFetchRequest() -> NSFetchRequest {
        let fetchResquest  = NSFetchRequest(entityName: "Evento")
        let sortDescriptor = NSSortDescriptor(key: "evn_nome", ascending: true)
        fetchResquest.sortDescriptors = [sortDescriptor]
        
        return fetchResquest
    }
    
    
    // TableView DataSource
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        let numberOfSection = fetchedResultController.sections?.count
        return numberOfSection!
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        let numberOfRowsInSection = fetchedResultController.sections?[section].numberOfObjects
        //print("linhas:", numberOfRowsInSection)
        return numberOfRowsInSection!
    }
    
    //Metodo onde carrego os eventos do banco na tabela principal
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! TableViewCell
        let evento = fetchedResultController.objectAtIndexPath(indexPath) as! Evento
        
        cell.lblNomeEvento.text = evento.evn_nome
        cell.lblNomeCategoria.text = evento.categoria?.cat_nome
        cell.imgImagemEvento.image = UIImage(data: evento.evn_imagem!)
        
        print("log:", evento.evn_descricao)
        cell.evento = evento
        
        print("log:\(evento.categoria?.cat_nome)")
    
        return cell
    }

    //segue para mostrar as descricoes de um evento
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "mostraDescricaoEvento"{
            if let objEvento = segue.destinationViewController as? EventoDescricaoViewController{
                if let cell = sender as? TableViewCell{
                    objEvento.evento = cell.evento
                }
            }
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //atualizacao da tabela apos algum insert, update ou delete
    func controllerDidChangeContent(controller: NSFetchedResultsController) {
        tblEventos.reloadData()
    }

}

<file_sep>//
//  TableViewCell.swift
//  ScreensApp
//
//  Created by Student on 12/15/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit

class TableViewCell: UITableViewCell {
    
    //componentes da celula dentro da tableView
    @IBOutlet weak var lblNomeEvento: UILabel!
    @IBOutlet weak var lblNomeCategoria: UILabel!
    @IBOutlet weak var imgImagemEvento: UIImageView!
    var evento : Evento!
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
<file_sep>//
//  Evento+CoreDataProperties.swift
//  ScreensApp
//
//  Created by Student on 12/17/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//
//  Choose "Create NSManagedObject Subclass…" from the Core Data editor menu
//  to delete and recreate this implementation file for your updated model.
//

import Foundation
import CoreData

extension Evento {

    @NSManaged var env_data_ultima_alteracao: NSDate?
    @NSManaged var evn_cidade: String?
    @NSManaged var evn_data_cadastro: String?
    @NSManaged var evn_data_evento: String?
    @NSManaged var evn_descricao: String?
    @NSManaged var evn_endereco: String?
    @NSManaged var evn_imagem: NSData?
    @NSManaged var evn_local_latitude: NSNumber?
    @NSManaged var evn_local_longitude: NSNumber?
    @NSManaged var evn_nome: String?
    @NSManaged var evn_numero: NSNumber?
    @NSManaged var categoria: Categoria?
    @NSManaged var usuario: Usuario?

}
<file_sep># oqfaZ
# Sumario do Projeto e ideologia
Nossa cidade de Sao Jose dos Campos possui um problema conhecido entre seus habitantes, a falta de divulgacao de envetos abertos ao publico (culturais e nao culturais). Nossa proposta e expor esse problema e mostrar uma solucao.

<file_sep>//
//  CadastroViewController.swift
//  ScreensApp
//
//  Created by <NAME> on 12/17/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit
import CoreData
import CoreLocation
import MapKit

class CadastroViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, CLLocationManagerDelegate, MKMapViewDelegate {

    let contexto = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
    
    //outlets da view de Cadastro de Eventos
    @IBOutlet weak var categoriaPicker: UIPickerView!
    @IBOutlet weak var imgImageEvento: UIImageView!
    @IBOutlet weak var txtNomeEvento: UITextField!
    @IBOutlet weak var txtEndereco: UITextField!
    @IBOutlet weak var txtDescricao: UITextView!
    @IBOutlet weak var txtTelefone: UITextField!
    @IBOutlet weak var btnAddImagem: UIButton!
    @IBOutlet weak var btnSalvar: UIBarButtonItem!
    @IBOutlet weak var btnCancelar: UIBarButtonItem!
    @IBOutlet weak var txtDataEvento: UITextField!
    @IBOutlet weak var theMap: MKMapView!
    
    var evento : Evento! = nil
    var categoriaNome: String!
    let categorias = ["Show","Festa","Exposição","Confraternização","Inauguração","Teatro","Apresentação","Promoção","Esporte"]
    
    let imagePiker = UIImagePickerController()
    
    var manager:CLLocationManager!
    var myLocations: [CLLocation] = []

    //carrega o mapa com a localizacao do usuario
    override func viewDidLoad() {
        super.viewDidLoad()
        imagePiker.delegate = self
        categoriaPicker.dataSource = self
        categoriaPicker.delegate = self
        
        manager = CLLocationManager()
        manager.delegate = self
        manager.desiredAccuracy = kCLLocationAccuracyBest
        manager.requestAlwaysAuthorization()
        manager.startUpdatingLocation()
        
        //Setup our Map View
        
        theMap.delegate = self
        theMap.mapType = MKMapType.Hybrid
        theMap.showsUserLocation = true
        
        // Do any additional setup after loading the view.
    }
    
    //metodos do MapKit
    func locationManager(manager:CLLocationManager, didUpdateLocations locations:[CLLocation]) {
        //theLabel.text = "\(locations[0])"
        
        myLocations.append(locations[0])

        let spanX = 0.007
        let spanY = 0.007
        
        let newRegion = MKCoordinateRegion(center: theMap.userLocation.coordinate, span: MKCoordinateSpanMake(spanX, spanY))
        
        theMap.setRegion(newRegion, animated: true)
        
        if (myLocations.count > 1){
            let sourceIndex = myLocations.count - 1
            let destinationIndex = myLocations.count - 2
            let c1 = myLocations[sourceIndex].coordinate
            let c2 = myLocations[destinationIndex].coordinate
            var a = [c1, c2]
            let polyline = MKPolyline(coordinates: &a, count: a.count)
            theMap.addOverlay(polyline)
        }
        
    }

    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //metodos para carregar imagens a galeria de fotos
    @IBAction func btnCarregarImagem(sender: AnyObject) {
        imagePiker.allowsEditing = false
        imagePiker.sourceType = .PhotoLibrary
        
        presentViewController(imagePiker, animated: true, completion: nil)
    }
    
    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
        if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage{
            imgImageEvento.contentMode = .ScaleAspectFit
            imgImageEvento.image = pickedImage
        }
        
        dismissViewControllerAnimated(true, completion: nil)
    }
    
    func imagePickerControllerDidCancel(picker: UIImagePickerController) {
        dismissViewControllerAnimated(true, completion: nil)
    }
    
    //MARK: - Delegates and data sources
    //MARK: Data Sources
    //Metodos que trabalham com o PickerView - Categorias
    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
        return 1
    }
    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return categorias.count
    }
    //MARK: Delegates
    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return categorias[row]
    }
    
    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        categoriaNome = categorias[row]
        print("log:\(categoriaNome)")
    }
    
    @IBAction func salvar(sender: AnyObject) {
        if evento == nil {
            criaEvento()
        }
        dismissViewController()
    }

    @IBAction func cancelar(sender: AnyObject) {
        dismissViewController()
    }
    
    // MARK:- Dismiss ViewControllers
    func dismissViewController() {
        navigationController?.popViewControllerAnimated(true)
    }
    
    
    // MARK:- Create eveto
    //Cria evento, insercao direto no banco de dados
    func criaEvento() {
        let entityEvento = NSEntityDescription.entityForName("Evento", inManagedObjectContext: contexto)
        let entityCategoria = NSEntityDescription.entityForName("Categoria", inManagedObjectContext: contexto)
        let entityUsuario = NSEntityDescription.entityForName("Usuario", inManagedObjectContext: contexto)
        
        let evento = Evento(entity: entityEvento!, insertIntoManagedObjectContext: contexto)
        let categoria = Categoria(entity: entityCategoria!, insertIntoManagedObjectContext: contexto)
        let usuario = Usuario(entity: entityUsuario!, insertIntoManagedObjectContext: contexto)
        
        let formato = NSDateFormatter()

        evento.evn_nome = txtNomeEvento.text
        evento.evn_endereco = txtEndereco.text
        evento.evn_data_evento = txtDataEvento.text!
        print("data: ", evento.evn_data_evento)
        evento.evn_descricao = txtDescricao.text
        
        let data = NSDate()
        formato.dateStyle = NSDateFormatterStyle.ShortStyle
        evento.evn_data_cadastro = formato.stringFromDate(data)
        categoria.cat_nome = categoriaNome
        usuario.usu_nome = "<NAME>"
        usuario.usu_telefone = txtTelefone.text
        evento.evn_imagem = UIImagePNGRepresentation(imgImageEvento.image!)
        
        
        evento.usuario = usuario
        evento.categoria = categoria
        
        do{
            try contexto.save()
        }catch let error as NSError {
            print("Erro ao criar evento")
            print(error)
        }
    }
    
    //pin no mapa
    func inserirPin(cx: Double, cy: Double, name: String){
        let anot: MKPointAnnotation = MKPointAnnotation()
        anot.coordinate = CLLocationCoordinate2DMake(CLLocationDegrees(cx),CLLocationDegrees(cy))
        anot.title = name
        self.theMap.addAnnotation(anot)
        
    }
    
    
    var selectedAnnotation: MKPointAnnotation!
    
    func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
        
        if control == view.rightCalloutAccessoryView {
            selectedAnnotation = view.annotation as? MKPointAnnotation
            performSegueWithIdentifier("proximo", sender: self)
        }
    }
    
    
    func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
        let annotationIdentifier = "pin"
        var view = mapView.dequeueReusableAnnotationViewWithIdentifier(annotationIdentifier)
        if view == nil {
            view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
        } else {
            view?.annotation = annotation
        }
        return view
    }
    
    
}
<file_sep>//
//  Usuario+CoreDataProperties.swift
//  ScreensApp
//
//  Created by Student on 12/15/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//
//  Choose "Create NSManagedObject Subclass…" from the Core Data editor menu
//  to delete and recreate this implementation file for your updated model.
//

import Foundation
import CoreData

extension Usuario {

    @NSManaged var usu_nome: String?
    @NSManaged var usu_senha: String?
    @NSManaged var usu_email: String?
    @NSManaged var usu_sexo: NSNumber?
    @NSManaged var usu_telefone: String?
    @NSManaged var usu_whatsapp: NSNumber?
    @NSManaged var usu_viber: NSNumber?
    @NSManaged var usu_line: NSNumber?

}
<file_sep>//  ViewController.swift
//  ScreensApp
//
//  Created by Student on 12/10/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit
import CoreData

class CadastroEventoViewController: UIViewController, UITableViewDataSource, NSFetchedResultsControllerDelegate {
	    
    let contexto = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
    @IBOutlet weak var imgVImage: UIImageView!
    @IBOutlet weak var btnAddImage: UIButton!
    @IBOutlet weak var txtFieldNomeEvento: UITextField!
    @IBOutlet weak var txtFieldEndereco: UITextField!
    @IBOutlet weak var txtViewDescricao: UITextView!
    @IBOutlet weak var txtFieldContato: UITextField!
    @IBOutlet weak var btnSalvar: UIButton!
    
    let imagePiker = UIImagePickerController()

    
    override func viewDidLoad() {
        super.viewDidLoad()
        imagePiker.delegate = self
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func loadImageButton(sender: AnyObject) {
        imagePiker.allowsEditing = false
        imagePiker.sourceType = .PhotoLibrary
        
        presentViewController(imagePiker, animated: true, completion: nil)
    }
    
    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
        if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage{
            imgVImage.contentMode = .ScaleAspectFit
            imgVImage.image = pickedImage
        }
        
        dismissViewControllerAnimated(true, completion: nil)
    }
    
    func imagePickerControllerDidCancel(picker: UIImagePickerController) {
        dismissViewControllerAnimated(true, completion: nil)
    }


    @IBAction func salvar(sender: AnyObject) {
        if evento == nil {
            criaEvento()
        }
        dismissViewController()
    }

    @IBAction func cancelar(sender: AnyObject) {
         dismissViewController()
    }
    
    // MARK:- Dismiss ViewControllers
    func dismissViewController() {
        navigationController?.popViewControllerAnimated(true)
    }

    // MARK:- Create task
    // MECHER NESSA CLASSE AQUI !!!!!! ---------------------------
    func criaEvento() {
        let entityEvento = NSEntityDescription.entityForName("Evento", inManagedObjectContext: contexto!)
        let entityCategoria = NSEntityDescription.entityForName("Categoria", inManagedObjectContext: contexto!)
        let entityUsuario = NSEntityDescription.entityForName("Usuario", inManagedObjectContext: contexto!)

        let evento = Evento(entity: entityDescription!, insertIntoManagedObjectContext: contexto)

        evento.evn_nome = lblNomeEvendo.text
        evento.evn_endereco = lblEndereco.text
        evento.evn_imagem = imgImagemEvento.image

        
        do{
            try contexto?.save()
        }catch let error as NSError {
            print("Erro ao criar tarefa")
            print(error)
        }
        
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "salvaEvento"{
            if let objEvento = segue.destinationViewController as? ViewController{
                if let cell = sender as? CadastroEventoViewController{
                    objEvento.evento = cell.evento
                }
            }
        }
    }
}