Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update source to swift 5 #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Print2PDF.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand Down
8 changes: 4 additions & 4 deletions Print2PDF/AddItemViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -51,7 +51,7 @@ class AddItemViewController: UIViewController, UITextFieldDelegate {

// MARK: Custom Methods

func dismissKeyboard() {
@objc func dismissKeyboard() {
if currentTextfield != nil {
currentTextfield.resignFirstResponder()
currentTextfield = nil
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Print2PDF/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 9 additions & 6 deletions Print2PDF/CreatorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}

Expand Down Expand Up @@ -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"]
Expand All @@ -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()
Expand Down
15 changes: 11 additions & 4 deletions Print2PDF/CustomPrintPageRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Print2PDF/InvoiceListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions Print2PDF/PreviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

Expand Down