----- CAPITULO 8 -------


Ejercicio numero 1

Codigo de Ejercicio:

  • Ejercico numero 1/li>
  •                                 //
    //  MasterViewController.swift
    //  JEHOVANI DE JESUS CHAVEZ SEGOVIA 2561842011
    
    
    import UIKit
    
    
    class MasterViewController: UITableViewController {
    
        var objects = NSMutableArray()
        var myBookStore: BookStore = BookStore()
    
    
        override func awakeFromNib() {
            super.awakeFromNib()
        }
    
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
            self.navigationItem.leftBarButtonItem = self.editButtonItem()
    
            let addButton = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "insertNewObject:")
            self.navigationItem.rightBarButtonItem = addButton
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
        func insertNewObject(sender: AnyObject) {
          //  objects.insert(NSMu(), atIndex: 0)
            let indexPath = NSIndexPath(forRow: 0, inSection: 0)
            self.tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
        }
    
        // MARK: - Segues
    
        override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
            if segue.identifier == "showDetail" {
                if let indexPath = self.tableView.indexPathForSelectedRow() {
                    let selectedBook:Book = myBookStore.theBookStore[indexPath.row]
                    (segue.destinationViewController as! DetailViewController).detailItem = selectedBook
                }
            }
        }
    
        // MARK: - Table View
    
        override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
            return 1
        }
    
        override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return myBookStore.theBookStore.count
        }
    
        override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
            let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
    
            cell.textLabel?.text = myBookStore.theBookStore[indexPath.row].title
            cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
            return cell
        }
    
        override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
            // Return false if you do not want the specified item to be editable.
            return true
        }
    
        override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
            if editingStyle == .Delete {
                //objects.removeAtIndex(indexPath.row)
                tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
            } else if editingStyle == .Insert {
                // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
            }
        }
    
    
    }
    
    
    //
    //  DetailViewController.swift
    //  myBookStore
    //
    //  JEHOVANI DE JESUS CHAVEZ SEGOVIA 2561842011
    
    
    import UIKit
    
    class DetailViewController: UIViewController {
    
        
        @IBOutlet weak var titleLabel: UILabel!
        @IBOutlet weak var authorLabel: UILabel!
        @IBOutlet weak var priceLabel: UILabel!
    
        @IBOutlet weak var descriptionTextView: UITextView!
    
        var detailItem: AnyObject? {
            didSet {
                // Update the view.
                
            }
        }
    
        func configureView() {
            if let detail: AnyObject = self.detailItem{
                var myBook = detail as! Book
                titleLabel.text = myBook.title
                authorLabel.text = myBook.author
                descriptionTextView.text = myBook.description
                priceLabel.text = myBook.price
            }
        }
    
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
            self.configureView()
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
    
    }
    
    
    
                                

    CLASES

    
    //
    //  Book.swift
    //  JEHOVANI DE JESUS CHAVEZ SEGOVIA 2561842011
    
    import Foundation
    
    class Book {
        var title: String = ""
        var author: String = ""
        var price: String = ""
        var description: String = ""
        
    }
    
    //
    //  BookStore.swift
    //  JEHOVANI DE JESUS CHAVEZ SEGOVIA 2561842011
    
    import Foundation
    
    class BookStore{
        var theBookStore: [Book] = []
        
        init() {
            libros()
        }
        
        func libros(){
            var newBook = Book()
            newBook.title = "SWIFT"
            newBook.author = "PRIVADO"
            newBook.price = "$150"
            newBook.description = "PROGRAMING."
            theBookStore.append(newBook)
            
            newBook = Book()
            newBook.title = "CARRETA VIEJA"
            newBook.author = "JUAN PEREZ"
            newBook.price = "$450"
            newBook.description = "CARRETA DE LA VIEJA."
            theBookStore.append(newBook)
            
            newBook = Book()
            newBook.title = "LAS CAMELIAS"
            newBook.author = "RODRIGO ALAIN"
            newBook.price = "$0,25"
            newBook.description = "LIBRO SOBRE CAMELIAS DEMONICAS USURPADORAS DEL MAL"
            theBookStore.append(newBook)
            
            newBook = Book()
            newBook.title = "EL CARA DE NUEGADO"
            newBook.author = "SANCHEZ CEREN"
            newBook.price = "GRATIS"
            newBook.description = "HISTORIA DEL PRESIDENTE MAS ATARANTADO DE EL SALVADOR."
            theBookStore.append(newBook)
            
            newBook = Book()
            newBook.title = "DON WICHO"
            newBook.author = "MAURICIO FUNES CARTAGENA"
            newBook.price = "GRATISHISTORIAS DE UN PREPOTENTE, MUJERIEGO Y LADRON"
            theBookStore.append(newBook)
            
            return
        }
    }
    
    
                                

Corriendo aplicacion