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

conditional approach #2

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
22 changes: 22 additions & 0 deletions TaiwanReceiptLottery/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
</plist>
28 changes: 28 additions & 0 deletions TaiwanReceiptLottery/Receipt.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Receipt.swift
// TaiwanReceiptLottery
//
// Created by Paul Lee on 2021/9/14.
//

import Foundation
public struct Receipt {
public enum SpecialFieldBox {
case taxID(String)
case mobileBarCode(String)
case npoCode(String)
case non
}

let date: Date
let price: Int
let lotteryNumber: String
let specialField: SpecialFieldBox

public init(date: Date, price: Int, lotteryNumber: String, specialField: SpecialFieldBox) {
self.date = date
self.price = price
self.lotteryNumber = lotteryNumber
self.specialField = specialField
}
}
50 changes: 50 additions & 0 deletions TaiwanReceiptLottery/ReceiptViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// ReceiptViewModel.swift
// TaiwanReceiptLottery
//
// Created by Paul Lee on 2021/9/14.
//

import Foundation
public struct ReceiptViewModel {
let receipt: Receipt
public init(_ receipt: Receipt) {
self.receipt = receipt
}

public var title: String {
switch receipt.specialField {
case .taxID(let id):
return "A B2B receipt has been issued, the company tax id is \(id)."

case .mobileBarCode:
return "A B2C receipt has been issued."

case .npoCode:
return "A B2C receipt has been issued."

case .non:
return "A B2C receipt has been issued."
}
}

public var body: String {
return "The lottery number is \(receipt.lotteryNumber)."
}

public var footer: String {
switch receipt.specialField {
case .taxID:
return "You can choose to print out this receipt or send it to your customer through email."

case .mobileBarCode(let code):
return "The receipt is saved in cloud database with mobile barcode number: \(code)"

case .npoCode(let code):
return "The lottery opportunity has been donated to a non profit organization, the organization id is: \(code)"

case .non:
return "The receipt has been printed."
}
}
}
13 changes: 13 additions & 0 deletions TaiwanReceiptLottery/ReceiptViewModelsFactory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// ReceiptViewModelsFactory.swift
// TaiwanReceiptLottery
//
// Created by Paul Lee on 2021/9/14.
//

import Foundation
public class ViewModelsFactory {
public static func makeViewModels(_ receipts: [Receipt]) -> [ReceiptViewModel] {
receipts.map { ReceiptViewModel($0) }
}
}
18 changes: 18 additions & 0 deletions TaiwanReceiptLottery/TaiwanReceiptLottery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// TaiwanReceiptLottery.h
// TaiwanReceiptLottery
//
// Created by Paul Lee on 2021/9/14.
//

#import <Foundation/Foundation.h>

//! Project version number for TaiwanReceiptLottery.
FOUNDATION_EXPORT double TaiwanReceiptLotteryVersionNumber;

//! Project version string for TaiwanReceiptLottery.
FOUNDATION_EXPORT const unsigned char TaiwanReceiptLotteryVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <TaiwanReceiptLottery/PublicHeader.h>


Loading