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

fix: Build error and warning #10

Merged
merged 4 commits into from
Oct 15, 2024
Merged
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
22 changes: 12 additions & 10 deletions .github/workflows/higgs-shop-sample-app-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,46 @@ jobs:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Run swiftlint
run: swiftlint
run: |
brew install swiftlint
swiftlint

ui-tests:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Run UI tests
run: xcodebuild test -project HiggsShopSampleApp.xcodeproj -destination "platform=iOS Simulator,name=iPhone 12,OS=latest" -scheme HiggsShopSampleApp
run: xcodebuild test -project HiggsShopSampleApp.xcodeproj -destination "platform=iOS Simulator,name=iPhone 15,OS=latest" -scheme HiggsShopSampleApp

run-tests-with-thread-sanitizer:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Run tests with thread sanitizer
run: xcodebuild test -project HiggsShopSampleApp.xcodeproj -destination "platform=iOS Simulator,name=iPhone 12,OS=latest" -scheme HiggsShopSampleApp -enableThreadSanitizer YES
run: xcodebuild test -project HiggsShopSampleApp.xcodeproj -destination "platform=iOS Simulator,name=iPhone 15,OS=latest" -scheme HiggsShopSampleApp -enableThreadSanitizer YES


run-tests-with-address-sanitizer:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Run tests with address sanitizer
run: xcodebuild test -project HiggsShopSampleApp.xcodeproj -destination "platform=iOS Simulator,name=iPhone 12,OS=latest" -scheme HiggsShopSampleApp -enableAddressSanitizer YES
run: xcodebuild test -project HiggsShopSampleApp.xcodeproj -destination "platform=iOS Simulator,name=iPhone 15,OS=latest" -scheme HiggsShopSampleApp -enableAddressSanitizer YES

run-analyzer:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Run static analyzer
run: xcodebuild analyze -project HiggsShopSampleApp.xcodeproj -scheme HiggsShopSampleApp -destination "platform=iOS Simulator,name=iPhone 12,OS=latest"
run: xcodebuild analyze -project HiggsShopSampleApp.xcodeproj -scheme HiggsShopSampleApp -destination "platform=iOS Simulator,name=iPhone 15,OS=latest"
4 changes: 2 additions & 2 deletions .github/workflows/higgs-shop-sample-app-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: macOS-latest
steps:
- name: Git checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Branch name
run: |
Expand All @@ -43,7 +43,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Release --dry-run
if: ${{ github.event.inputs.dryRun == 'true'}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync-higgs-shop-data-plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
GIT_COMMITTER_EMAIL: [email protected]
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ref: development

Expand Down
5 changes: 5 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
disabled_rules:
- function_body_length
- type_body_length
- line_length
- file_length
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, MPListenerProtocol

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
}

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return .portrait
}
Expand All @@ -32,19 +32,22 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, MPListenerProtocol
}
}
if let options = makeOptions() {
if let reset = parseBool(getConfigInfo("MPARTICLE_RESET")) {
if reset == true {
MParticle.sharedInstance().reset()
let completion = {
if let optOut = self.parseBool(self.getConfigInfo("MPARTICLE_OPTOUT")) {
MParticle.sharedInstance().optOut = optOut
}
MParticle.sharedInstance().start(with: options)
}
if let optOut = parseBool(getConfigInfo("MPARTICLE_OPTOUT")) {
MParticle.sharedInstance().optOut = optOut

if let reset = parseBool(getConfigInfo("MPARTICLE_RESET")), reset == true {
MParticle.sharedInstance().reset(completion)
} else {
completion()
}
MParticle.sharedInstance().start(with: options)
} else {
log("Error: Unable to create mParticle Options object")
}

UITabBarItem.appearance().setTitleTextAttributes([.font: Utils.font(ofSize: 12)], for: .normal)
UITabBarItem.appearance().setTitleTextAttributes([.font: Utils.font(ofSize: 12)], for: .selected)
UITabBarItem.appearance().setTitleTextAttributes([.font: Utils.font(ofSize: 12)], for: .highlighted)
Expand Down Expand Up @@ -98,12 +101,12 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, MPListenerProtocol
options.proxyAppDelegate = false
}
}

// Sideloaded kits are simply classes that conform to MPKitProtocol and can be used to receive callbacks when various things happen such as events being logged.
// This example is a simple implementation that only logs the callbacks to the console, but the data in the callbacks can be used for anything.
// NOTE: Sideloaded kits are always active regardless of server-side configuration.
options.sideloadedKits = [ConsoleLoggingKit()]
options.sideloadedKits = [MPSideloadedKit(kitInstance: ConsoleLoggingKit())]

return options
}

Expand Down Expand Up @@ -157,7 +160,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, MPListenerProtocol
}
return nil
}

// This code allows us to create predefined Schemes with with different settings and accounts for MParticleOptions. If you would like to use schemes in this way for simulator testing, add these keys as 'Environment Variables' under the 'Arguments' section of the 'Run' tab of the scheme.
func getOverrideConfig(_ key: String) -> String? {
#if targetEnvironment(simulator)
Expand All @@ -176,7 +179,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, MPListenerProtocol
if overrideValue == "REPLACEME" {
overrideValue = nil
}

var shouldOverride = true
if let disableOverride = parseBool(getDefaultConfig("CONFIG_DISABLEOVERRIDE")), disableOverride {
shouldOverride = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import SnapKit

final class CartTableCell: UITableViewCell {
static let reuseId = "CartTableCell"

let productImageView = UIImageView()
let productNameLabel = UILabel()
let productDetailLabel = UILabel()
let productPriceLabel = UILabel()
let removeProductButton = UIButton()

var cartItem: CartItem? {
didSet {
if let cartItem = cartItem {
Expand All @@ -26,10 +26,10 @@ final class CartTableCell: UITableViewCell {
}
}
}

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)

productImageView.accessibilityIdentifier = "CartCellProductImageView"
productImageView.contentMode = .scaleAspectFill
addSubview(productImageView)
Expand All @@ -39,7 +39,7 @@ final class CartTableCell: UITableViewCell {
make.bottom.equalTo(self.snp.bottom).offset(-16)
make.width.equalTo(100)
}

productNameLabel.accessibilityIdentifier = "CartCellProductNameLabel"
productNameLabel.textColor = .label
productNameLabel.font = Utils.font(ofSize: 16)
Expand All @@ -52,7 +52,7 @@ final class CartTableCell: UITableViewCell {
make.height.equalTo(24).priority(.high)
make.trailing.equalTo(productPriceLabel.snp.leading).offset(-5)
}

productPriceLabel.accessibilityIdentifier = "CartCellProductPriceLabel"
productPriceLabel.textColor = .label
productPriceLabel.font = Utils.font(ofSize: 15)
Expand All @@ -62,7 +62,7 @@ final class CartTableCell: UITableViewCell {
make.trailing.equalTo(self.snp.trailing).offset(-32)
make.height.equalTo(16)
}

productDetailLabel.accessibilityIdentifier = "CartCellProductDetailLabel"
productDetailLabel.textColor = .secondaryLabel
productDetailLabel.font = Utils.font(ofSize: 14)
Expand All @@ -73,7 +73,7 @@ final class CartTableCell: UITableViewCell {
make.leading.equalTo(productImageView.snp.trailing).offset(20)
make.height.equalTo(20)
}

addSubview(removeProductButton)
removeProductButton.snp.makeConstraints { make in
make.top.equalTo(productDetailLabel.snp.bottom)
Expand All @@ -88,7 +88,7 @@ final class CartTableCell: UITableViewCell {
removeProductButton.layer.borderWidth = 0
removeProductButton.contentHorizontalAlignment = .left
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ final class CartViewController: UITableViewController {
let subtotalLabel = UILabel()
let subtotalValueLabel = UILabel()
let subtotalDivider = UIView()

let checkoutButton = UIButton()
let checkoutDisclaimerLabel = UILabel()

override func viewDidLoad() {
navigationItem.title = "My Cart"
edgesForExtendedLayout = []
Expand All @@ -18,27 +18,27 @@ final class CartViewController: UITableViewController {
for item in AppDelegate.cart.items {
subTotal += Double(item.quantity) * item.product.price
}

// Renders an initial cart view when the screen loads
MParticle.sharedInstance().logScreen("View My Cart", eventInfo: ["number_of_products": numberOfProducts, "total_product_amounts": subTotal])

tableView.accessibilityIdentifier = "CartTableView"
tableView.register(CartTableCell.self, forCellReuseIdentifier: CartTableCell.reuseId)
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 80

calculateCosts()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
reloadTable()
calculateCosts()
}

private func reloadTable() {
tableView.reloadData()

let count = AppDelegate.cart.items.count
tabBarController?.tabBar.items?.last?.badgeValue = (count == 0 ? nil : "\(AppDelegate.cart.items.count)")

Expand All @@ -56,7 +56,7 @@ final class CartViewController: UITableViewController {
tableView.tableHeaderView = nil
let footerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 164))
footerView.backgroundColor = UIColor.clear

footerView.addSubview(subtotalLabel)
subtotalLabel.snp.makeConstraints { make in
make.top.equalTo(footerView.snp.top).offset(14)
Expand Down Expand Up @@ -86,7 +86,7 @@ final class CartViewController: UITableViewController {
make.trailing.equalTo(footerView.snp.trailing).offset(-16)
}
subtotalDivider.backgroundColor = .separator

footerView.addSubview(checkoutButton)
checkoutButton.snp.makeConstraints { make in
make.top.equalTo(subtotalDivider.snp.bottom).offset(38)
Expand All @@ -99,7 +99,7 @@ final class CartViewController: UITableViewController {
checkoutButton.backgroundColor = UIColor(red: 64/255.0, green: 121/255.0, blue: 254/255.0, alpha: 1.0)
checkoutButton.layer.cornerRadius = 8
checkoutButton.titleLabel?.font = Utils.font(ofSize: 16)

footerView.addSubview(checkoutDisclaimerLabel)
checkoutDisclaimerLabel.snp.makeConstraints { make in
make.top.equalTo(checkoutButton.snp.bottom).offset(19)
Expand All @@ -111,17 +111,17 @@ final class CartViewController: UITableViewController {
checkoutDisclaimerLabel.font = Utils.font(ofSize: 12)
checkoutDisclaimerLabel.textAlignment = .center
checkoutDisclaimerLabel.textColor = .secondaryLabel

footerView.frame.size.height = 164
tableView.tableFooterView = footerView
tableView.isScrollEnabled = true
}
}

override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return AppDelegate.cart.items.count
}
Expand All @@ -136,7 +136,7 @@ final class CartViewController: UITableViewController {
cartTableCell.cartItem = AppDelegate.cart.items[indexPath.row]
return cartTableCell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let removedItem = AppDelegate.cart.items.remove(at: indexPath.row)
let detailView = ProductDetailViewController(product: removedItem.product)
Expand All @@ -148,17 +148,17 @@ final class CartViewController: UITableViewController {
event.shouldBeginSession = AppDelegate.eventsBeginSessions
MParticle.sharedInstance().logEvent(event)
}

private func calculateCosts() {
var subtotal = 0.00
for cartItem in AppDelegate.cart.items {
subtotal += cartItem.totalAmount
}

subtotalValueLabel.text = "$" + String(format: "%.2f", subtotal)
checkoutButton.isEnabled = subtotal != 0
}

@objc private func checkout() {
if let event = MPCommerceEvent(action: .checkout) {
var products = [MPProduct]()
Expand Down Expand Up @@ -189,7 +189,7 @@ final class CartViewController: UITableViewController {
event.transactionAttributes = transactionAttributes // transaction attributes are required
event.shouldBeginSession = AppDelegate.eventsBeginSessions
MParticle.sharedInstance().logEvent(event)

let checkoutVC = CheckoutViewController()
checkoutVC.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(checkoutVC, animated: true)
Expand Down
Loading
Loading