diff --git a/Print2PDF.xcodeproj/project.pbxproj b/Print2PDF.xcodeproj/project.pbxproj index ac625d4..bbe8667 100644 --- a/Print2PDF.xcodeproj/project.pbxproj +++ b/Print2PDF.xcodeproj/project.pbxproj @@ -137,6 +137,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -296,7 +297,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.appcoda.Print2PDF; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -308,7 +309,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.appcoda.Print2PDF; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/Print2PDF/AddItemViewController.swift b/Print2PDF/AddItemViewController.swift index 2415c8f..8b1ffbb 100644 --- a/Print2PDF/AddItemViewController.swift +++ b/Print2PDF/AddItemViewController.swift @@ -28,7 +28,7 @@ class AddItemViewController: UIViewController, UITextFieldDelegate { txtPrice.delegate = self // Add a tap gesture recognizer to the view to dismiss the keyboard. - let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(AddItemViewController.dismissKeyboard)) + let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) view.addGestureRecognizer(tapGestureRecognizer) } @@ -51,7 +51,7 @@ class AddItemViewController: UIViewController, UITextFieldDelegate { // MARK: Custom Methods - func dismissKeyboard() { + @objc func dismissKeyboard() { if currentTextfield != nil { currentTextfield.resignFirstResponder() currentTextfield = nil @@ -68,8 +68,8 @@ class AddItemViewController: UIViewController, UITextFieldDelegate { // MARK: IBAction Methods @IBAction func saveItem(_ sender: AnyObject) { - if (txtItemDescription.text?.characters.count)! > 0 && - (txtPrice.text?.characters.count)! > 0 { + if (txtItemDescription.text?.count)! > 0 && + (txtPrice.text?.count)! > 0 { if saveCompletionHandler != nil { // Call the save completion handler to pass the item description and the price back to the CreatorViewController object. diff --git a/Print2PDF/AppDelegate.swift b/Print2PDF/AppDelegate.swift index 5d59471..604d594 100644 --- a/Print2PDF/AppDelegate.swift +++ b/Print2PDF/AppDelegate.swift @@ -16,7 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { let currencyCode = "eur" - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { // Override point for customization after application launch. return true } diff --git a/Print2PDF/CreatorViewController.swift b/Print2PDF/CreatorViewController.swift index 222f73f..3e558ec 100644 --- a/Print2PDF/CreatorViewController.swift +++ b/Print2PDF/CreatorViewController.swift @@ -100,9 +100,12 @@ class CreatorViewController: UIViewController, UITableViewDelegate, UITableViewD else { UserDefaults.standard.set("002", forKey: "nextInvoiceNumber") } - - saveCompletionHandler(_: invoiceNumber, _: tvRecipientInfo.text, _: bbiTotal.title!, _: items) - _ = navigationController?.popViewController(animated: true) + if let total = bbiTotal.title, let items = items { + saveCompletionHandler(_: invoiceNumber, _: tvRecipientInfo.text, _: total, _: items) + _ = navigationController?.popViewController(animated: true) + } else { + print("Error: add invoice items") + } } } @@ -184,7 +187,7 @@ class CreatorViewController: UIViewController, UITableViewDelegate, UITableViewD var cell: UITableViewCell! = tableView.dequeueReusableCell(withIdentifier: "itemCell", for: indexPath as IndexPath) if cell == nil { - cell = UITableViewCell(style: UITableViewCellStyle.value1, reuseIdentifier: "itemCell") + cell = UITableViewCell(style: UITableViewCell.CellStyle.value1, reuseIdentifier: "itemCell") } cell.textLabel?.text = items[indexPath.row]["item"] @@ -198,8 +201,8 @@ class CreatorViewController: UIViewController, UITableViewDelegate, UITableViewD } - func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { - if editingStyle == UITableViewCellEditingStyle.delete { + func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { + if editingStyle == UITableViewCell.EditingStyle.delete { items.remove(at: indexPath.row) tblInvoiceItems.reloadData() displayTotalAmount() diff --git a/Print2PDF/CustomPrintPageRenderer.swift b/Print2PDF/CustomPrintPageRenderer.swift index a4c3694..35d7939 100644 --- a/Print2PDF/CustomPrintPageRenderer.swift +++ b/Print2PDF/CustomPrintPageRenderer.swift @@ -42,10 +42,16 @@ class CustomPrintPageRenderer: UIPrintPageRenderer { let font = UIFont(name: "AmericanTypewriter-Bold", size: 30.0) // Specify some text attributes we want to apply to the header text. - let textAttributes = [NSFontAttributeName: font!, NSForegroundColorAttributeName: UIColor(red: 243.0/255, green: 82.0/255.0, blue: 30.0/255.0, alpha: 1.0), NSKernAttributeName: 7.5] as [String : Any] + let textAttributes : [NSAttributedString.Key : Any] = [ + .font : font, + .foregroundColor: UIColor(red: 243.0/255, green: 82.0/255.0, blue: 30.0/255.0, alpha: 1.0), + .kern: 7.5 + ] // Calculate the text size. - let textSize = getTextSize(text: headerText as String, font: nil, textAttributes: textAttributes as [String : AnyObject]!) + let attributeString = NSMutableAttributedString(string: headerText as String, attributes: textAttributes) + + let textSize = getTextSize(text: headerText as String, font: font, textAttributes: textAttributes) // Determine the offset to the right side. let offsetX: CGFloat = 20.0 @@ -67,7 +73,7 @@ class CustomPrintPageRenderer: UIPrintPageRenderer { let centerX = footerRect.size.width/2 - textSize.width/2 let centerY = footerRect.origin.y + self.footerHeight/2 - textSize.height/2 - let attributes = [NSFontAttributeName: font!, NSForegroundColorAttributeName: UIColor(red: 205.0/255.0, green: 205.0/255.0, blue: 205.0/255, alpha: 1.0)] + let attributes = [NSAttributedString.Key.font: font!, NSAttributedString.Key.foregroundColor: UIColor(red: 205.0/255.0, green: 205.0/255.0, blue: 205.0/255, alpha: 1.0)] footerText.draw(at: CGPoint(x: centerX, y: centerY), withAttributes: attributes) @@ -83,10 +89,11 @@ class CustomPrintPageRenderer: UIPrintPageRenderer { - func getTextSize(text: String, font: UIFont!, textAttributes: [String: AnyObject]! = nil) -> CGSize { + func getTextSize(text: String, font: UIFont!, textAttributes: [NSAttributedString.Key: Any]! = nil) -> CGSize { let testLabel = UILabel(frame: CGRect(x: 0.0, y: 0.0, width: self.paperRect.size.width, height: footerHeight)) if let attributes = textAttributes { testLabel.attributedText = NSAttributedString(string: text, attributes: attributes) + } else { testLabel.text = text diff --git a/Print2PDF/InvoiceListViewController.swift b/Print2PDF/InvoiceListViewController.swift index 37e7775..adb6631 100644 --- a/Print2PDF/InvoiceListViewController.swift +++ b/Print2PDF/InvoiceListViewController.swift @@ -104,7 +104,7 @@ class InvoiceListViewController: UIViewController, UITableViewDelegate, UITableV var cell: UITableViewCell! = tableView.dequeueReusableCell(withIdentifier: "invoiceCell", for: indexPath as IndexPath) if cell == nil { - cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "invoiceCell") + cell = UITableViewCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: "invoiceCell") } cell.textLabel?.text = "\(invoices[indexPath.row]["invoiceNumber"] as! String) - \(invoices[indexPath.row]["invoiceDate"] as! String) - \(invoices[indexPath.row]["totalAmount"] as! String)" @@ -124,8 +124,8 @@ class InvoiceListViewController: UIViewController, UITableViewDelegate, UITableV } - func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { - if editingStyle == UITableViewCellEditingStyle.delete { + func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { + if editingStyle == UITableViewCell.EditingStyle.delete { invoices.remove(at: indexPath.row) tblInvoices.reloadData() UserDefaults.standard.set(self.invoices, forKey: "invoices") diff --git a/Print2PDF/PreviewViewController.swift b/Print2PDF/PreviewViewController.swift index e003700..d9f3f0b 100644 --- a/Print2PDF/PreviewViewController.swift +++ b/Print2PDF/PreviewViewController.swift @@ -78,22 +78,22 @@ class PreviewViewController: UIViewController { func showOptionsAlert() { - let alertController = UIAlertController(title: "Yeah!", message: "Your invoice has been successfully printed to a PDF file.\n\nWhat do you want to do now?", preferredStyle: UIAlertControllerStyle.alert) + let alertController = UIAlertController(title: "Yeah!", message: "Your invoice has been successfully printed to a PDF file.\n\nWhat do you want to do now?", preferredStyle: UIAlertController.Style.alert) - let actionPreview = UIAlertAction(title: "Preview it", style: UIAlertActionStyle.default) { (action) in + let actionPreview = UIAlertAction(title: "Preview it", style: UIAlertAction.Style.default) { (action) in if let filename = self.invoiceComposer.pdfFilename, let url = URL(string: filename) { let request = URLRequest(url: url) self.webPreview.loadRequest(request) } } - let actionEmail = UIAlertAction(title: "Send by Email", style: UIAlertActionStyle.default) { (action) in + let actionEmail = UIAlertAction(title: "Send by Email", style: UIAlertAction.Style.default) { (action) in DispatchQueue.main.async { self.sendEmail() } } - let actionNothing = UIAlertAction(title: "Nothing", style: UIAlertActionStyle.default) { (action) in + let actionNothing = UIAlertAction(title: "Nothing", style: UIAlertAction.Style.default) { (action) in }