Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Creating a CSV file to export Property (As a test)
- @objc private func createCSV() {
- let fileName = "\(Auth.auth().currentUser!.displayName!)-spreadsheet-info.csv"
- let path = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(fileName)
- var csvText = "Name,Cost,Rent,Building Tax,Property Tax,Yearly Fees,Value Growth,Squared Feet\n"
- var totalTaxAndFees: Double = 0
- var totalRent: Double = 0
- var totalIncome: Double = 0
- for property in properties {
- // Creating line for each Property to add to spreadsheet
- csvText += "\(property.name),$ \(property.buyingPrice),$ \(property.rent),$ \(property.buildingTax),$ \(property.propertyTax),$ \(property.yearlyFees),\(property.valueGrowth),\(property.squaredFeet)\n"
- // Calculating Total tax and Fees yearly
- totalTaxAndFees += ((property.propertyTax + property.buildingTax) * 12) + property.yearlyFees
- // Calculating Total rent Yearly
- totalRent += property.rent * 12
- }
- totalIncome = totalRent - totalTaxAndFees
- csvText += " \nYearly\nTax + Fees,$ \(totalTaxAndFees)\nRent,$ \(totalRent)\nTotal,$ \(totalIncome)\n"
- csvText += " \nMothly\nTax + Fees,$ \(totalTaxAndFees / 12)\nRent,$ \(totalRent / 12)\nTotal,$ \(totalIncome / 12)\n"
- do {
- try csvText.write(to: path!, atomically: true, encoding: String.Encoding.utf8)
- let vc = UIActivityViewController(activityItems: [path], applicationActivities: [])
- vc.excludedActivityTypes = [
- UIActivity.ActivityType.assignToContact,
- UIActivity.ActivityType.saveToCameraRoll,
- UIActivity.ActivityType.postToFlickr,
- UIActivity.ActivityType.postToVimeo,
- UIActivity.ActivityType.postToTencentWeibo,
- UIActivity.ActivityType.postToTwitter,
- UIActivity.ActivityType.postToFacebook,
- UIActivity.ActivityType.openInIBooks
- ]
- present(vc, animated: true, completion: nil)
- } catch {
- print("Failed to create file")
- print("\(error)")
- }
- }
- }
- First creates a file name using the user's username.
- Create the first row of cells to sort Name, Cost, Rent, Building Tax, Property Tax, Yearly Fees, Value Growth, Squared Feet.
- Create a for loop for the user's properties' data.
- For each property, create a row with the same properties indicated in the first row (Name, Cost, Rent, Building Tax, Property Tax, Yearly Fees, Value Growth, Squared Feet.)
- At the bottom of all the properties, fill overall user properties' data.
- Lastly, provide the user with options to share the created file.
- Add a throw error in case anything fails.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement