Skip to content

Instantly share code, notes, and snippets.

@FabiolaRamirez
Created February 14, 2019 20:36
Show Gist options
  • Select an option

  • Save FabiolaRamirez/e0c9e571372520449f456ac20c21a416 to your computer and use it in GitHub Desktop.

Select an option

Save FabiolaRamirez/e0c9e571372520449f456ac20c21a416 to your computer and use it in GitHub Desktop.
algo.swift
//
// TipsScreenTips.swift
// finance
//
// Created by DavidMora on 5/2/18.
// Copyright © 2018 creditsesame. All rights reserved.
//
import UIKit
class TipsScreenTips: Model {
var creditAge: [Tip]?
var accountMix: [Tip]?
var creditUsage: [Tip]?
var paymentHistory: [Tip]?
var creditInquiries: [Tip]?
func tipForSection(_ section: TipsViewSection) -> Tip? {
if section == .tipOfTheMonth {
return ClientConfigurationManager.shared.needsToShowIntroTip ? ClientConfigurationManager.shared.configurationFile?.tips?.introTip : ClientConfigurationManager.shared.configurationFile?.tips?.topTip
}
return tipForFactor(section.factorForSection)
}
func tipForFactor(_ factor: CreditFactorOption) -> Tip? {
if !factor.isTipsFactorEnabled {
return nil
}
var grade = factor.creditFactorData?.grade ?? "F"
let creditUsageFactor = CreditFactorOption.creditUsage.creditFactorData as? CreditUsageFactor
if let creditUsageFactor = creditUsageFactor, creditUsageFactor.isFZero {
grade = "Z"
}
let factorTips: [Tip]?
switch factor {
case .creditAge:
factorTips = creditAge
case .accountMix:
factorTips = accountMix
case .creditUsage:
factorTips = creditUsage
case .paymentHistory:
factorTips = paymentHistory
case .creditInquiries:
factorTips = creditInquiries
}
let currentBuild = AppSettingsManager.shared.getValueInPList(key: kCFBundleVersionKey as String)
let currentBuildNumber = Int(currentBuild ?? "1") ?? 1
if let factorTips = factorTips {
let filtered = factorTips.filter { $0.grade == grade && ($0.iOSBuild ?? NSNumber(value: Int.max)).intValue <= currentBuildNumber }
return filtered[0]
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment