Browse Source

Moving from count to isEmpty!

pull/92/head
Abhishek Banthia 6 years ago
parent
commit
742102109c
  1. 8
      .swiftlint.yml
  2. 5
      Clocker/Clocker.xcodeproj/xcuserdata/ban.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
  3. 2
      Clocker/Clocker/LocationController.swift
  4. 4
      Clocker/Dependencies/Date Additions/TimePeriodChain.swift
  5. 2
      Clocker/Events and Reminders/CalendarHandler.swift
  6. 2
      Clocker/Events and Reminders/RemindersHandler.swift
  7. 2
      Clocker/Menu Bar/MenubarHandler.swift
  8. 12
      Clocker/Panel/Data Layer/TimezoneData.swift
  9. 12
      Clocker/Panel/Data Layer/TimezoneDataOperations.swift
  10. 2
      Clocker/Panel/Notes Popover/NotesPopover.swift
  11. 4
      Clocker/Panel/ParentPanelController.swift
  12. 10
      Clocker/Panel/UI/TimezoneDataSource.swift
  13. 14
      Clocker/Preferences/General/PreferencesViewController.swift

8
.swiftlint.yml

@ -2,10 +2,12 @@ disabled_rules: # rule identifiers to exclude from running
- colon - colon
- comma - comma
- control_statement - control_statement
- line_length
- type_body_length
- file_length
- nesting
opt_in_rules: # some rules are only opt-in opt_in_rules: # some rules are only opt-in
- empty_count - empty_count
# Find all the available rules by running:
# swiftlint rules
# included: # paths to include during linting. `--path` is ignored if present. # included: # paths to include during linting. `--path` is ignored if present.
# - Clocker # - Clocker
# excluded: # paths to ignore during linting. Takes precedence over `included`. # excluded: # paths to ignore during linting. Takes precedence over `included`.
@ -24,7 +26,7 @@ force_try:
severity: warning # explicitly severity: warning # explicitly
# rules that have both warning and error levels, can set just the warning level # rules that have both warning and error levels, can set just the warning level
# implicitly # implicitly
line_length: 110 line_length: 200
# they can set both implicitly with an array # they can set both implicitly with an array
type_body_length: type_body_length:
- 300 # warning - 300 # warning

5
Clocker/Clocker.xcodeproj/xcuserdata/ban.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
</Bucket>

2
Clocker/Clocker/LocationController.swift

@ -90,7 +90,7 @@ class LocationController: NSObject {
extension LocationController: CLLocationManagerDelegate { extension LocationController: CLLocationManagerDelegate {
func locationManager(_: CLLocationManager, didUpdateLocations locations: [CLLocation]) { func locationManager(_: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard locations.count > 0, let coordinates = locations.first?.coordinate else { return } guard !locations.isEmpty, let coordinates = locations.first?.coordinate else { return }
let reverseGeoCoder = CLGeocoder() let reverseGeoCoder = CLGeocoder()

4
Clocker/Dependencies/Date Additions/TimePeriodChain.swift

@ -28,7 +28,7 @@ open class TimePeriodChain: TimePeriodGroup {
* - parameter period: TimePeriodProtocol to add to the collection * - parameter period: TimePeriodProtocol to add to the collection
*/ */
public func append(_ period: TimePeriodProtocol) { public func append(_ period: TimePeriodProtocol) {
let beginning = (self.periods.count > 0) ? self.periods.last!.end! : period.beginning let beginning = (self.periods.isEmpty == false) ? self.periods.last!.end! : period.beginning
let newPeriod = TimePeriod(beginning: beginning!, duration: period.duration) let newPeriod = TimePeriod(beginning: beginning!, duration: period.duration)
self.periods.append(newPeriod) self.periods.append(newPeriod)
@ -50,7 +50,7 @@ open class TimePeriodChain: TimePeriodGroup {
*/ */
public func append<G: TimePeriodGroup>(contentsOf group: G) { public func append<G: TimePeriodGroup>(contentsOf group: G) {
for period in group.periods { for period in group.periods {
let beginning = (self.periods.count > 0) ? self.periods.last!.end! : period.beginning let beginning = (self.periods.isEmpty == false) ? self.periods.last!.end! : period.beginning
let newPeriod = TimePeriod(beginning: beginning!, duration: period.duration) let newPeriod = TimePeriod(beginning: beginning!, duration: period.duration)
self.periods.append(newPeriod) self.periods.append(newPeriod)

2
Clocker/Events and Reminders/CalendarHandler.swift

@ -33,7 +33,7 @@ extension EventCenter {
// Fetch the user-selected calendars. Initially, all the calendars will be selected // Fetch the user-selected calendars. Initially, all the calendars will be selected
var setOfCalendars: Set<String> = Set() var setOfCalendars: Set<String> = Set()
if let userCalendars = UserDefaults.standard.array(forKey: CLSelectedCalendars) as? [String], userCalendars.count > 0 { if let userCalendars = UserDefaults.standard.array(forKey: CLSelectedCalendars) as? [String], !userCalendars.isEmpty {
setOfCalendars = Set(userCalendars) setOfCalendars = Set(userCalendars)
} }

2
Clocker/Events and Reminders/RemindersHandler.swift

@ -13,7 +13,7 @@ extension EventCenter {
let predicate = NSPredicate(format: "title matches %@", calendarTitle) let predicate = NSPredicate(format: "title matches %@", calendarTitle)
let filtered = calendars.filter({ predicate.evaluate(with: $0) }) let filtered = calendars.filter({ predicate.evaluate(with: $0) })
if filtered.count > 0 { if !filtered.isEmpty {
calendar = filtered.first calendar = filtered.first
} else { } else {
calendar = EKCalendar(for: .reminder, eventStore: store) calendar = EKCalendar(for: .reminder, eventStore: store)

2
Clocker/Menu Bar/MenubarHandler.swift

@ -19,7 +19,7 @@ class MenubarHandler: NSObject {
return nil return nil
} }
if menubarTitles.count > 0 { if menubarTitles.isEmpty == false {
let titles = menubarTitles.map({ (data) -> String? in let titles = menubarTitles.map({ (data) -> String? in
let timezone = TimezoneData.customObject(from: data) let timezone = TimezoneData.customObject(from: data)
let operationsObject = TimezoneDataOperations(with: timezone!) let operationsObject = TimezoneDataOperations(with: timezone!)

12
Clocker/Panel/Data Layer/TimezoneData.swift

@ -210,7 +210,7 @@ class TimezoneData: NSObject, NSCoding {
/// Converts the Obj-C model objects into Swift /// Converts the Obj-C model objects into Swift
class func convert() { class func convert() {
if let timezones = DataStore.shared().retrieve(key: CLDefaultPreferenceKey) as? [Data], timezones.count > 0 { if let timezones = DataStore.shared().retrieve(key: CLDefaultPreferenceKey) as? [Data], !timezones.isEmpty {
let newModels = converter(timezones) let newModels = converter(timezones)
if newModels.count == timezones.count { if newModels.count == timezones.count {
@ -224,7 +224,7 @@ class TimezoneData: NSObject, NSCoding {
} }
} }
if let menubarTimezones = DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data], menubarTimezones.count > 0 { if let menubarTimezones = DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data], !menubarTimezones.isEmpty {
let newMenubarModels = converter(menubarTimezones) let newMenubarModels = converter(menubarTimezones)
if newMenubarModels.count == menubarTimezones.count { if newMenubarModels.count == menubarTimezones.count {
@ -296,17 +296,17 @@ class TimezoneData: NSObject, NSCoding {
func formattedTimezoneLabel() -> String { func formattedTimezoneLabel() -> String {
// First check if there's an user preferred custom label set // First check if there's an user preferred custom label set
if let label = customLabel, label.count > 0 { if let label = customLabel, !label.isEmpty {
return label return label
} }
// No custom label, return the formatted address/timezone // No custom label, return the formatted address/timezone
if let address = formattedAddress, address.count > 0 { if let address = formattedAddress, !address.isEmpty {
return address return address
} }
// No formatted address, return the timezoneID // No formatted address, return the timezoneID
if let timezone = timezoneID, timezone.count > 0 { if let timezone = timezoneID, !timezone.isEmpty {
let hashSeperatedString = timezone.components(separatedBy: "/") let hashSeperatedString = timezone.components(separatedBy: "/")
// Return the second component! // Return the second component!
@ -323,7 +323,7 @@ class TimezoneData: NSObject, NSCoding {
} }
func setLabel(_ label: String) { func setLabel(_ label: String) {
customLabel = label.count > 0 ? label : CLEmptyString customLabel = !label.isEmpty ? label : CLEmptyString
} }
func setShouldOverrideGlobalTimeFormat(_ shouldOverride: Int) { func setShouldOverrideGlobalTimeFormat(_ shouldOverride: Int) {

12
Clocker/Panel/Data Layer/TimezoneDataOperations.swift

@ -58,16 +58,16 @@ extension TimezoneDataOperations {
let shouldDateBeShown = dataStore.shouldDisplay(.dateInMenubar) let shouldDateBeShown = dataStore.shouldDisplay(.dateInMenubar)
if shouldCityBeShown { if shouldCityBeShown {
if let address = dataObject.formattedAddress, address.count > 0 { if let address = dataObject.formattedAddress, address.isEmpty == false {
if let label = dataObject.customLabel { if let label = dataObject.customLabel {
label.count > 0 ? menuTitle.append(label) : menuTitle.append(address) label.isEmpty == false ? menuTitle.append(label) : menuTitle.append(address)
} else { } else {
menuTitle.append(address) menuTitle.append(address)
} }
} else { } else {
if let label = dataObject.customLabel { if let label = dataObject.customLabel {
label.count > 0 ? menuTitle.append(label) : menuTitle.append(dataObject.timezone()) label.isEmpty == false ? menuTitle.append(label) : menuTitle.append(dataObject.timezone())
} else { } else {
menuTitle.append(dataObject.timezone()) menuTitle.append(dataObject.timezone())
} }
@ -79,7 +79,7 @@ extension TimezoneDataOperations {
let endIndex = substring.index(substring.startIndex, offsetBy: 2) let endIndex = substring.index(substring.startIndex, offsetBy: 2)
substring = String(substring[substring.startIndex ... endIndex]) substring = String(substring[substring.startIndex ... endIndex])
if menuTitle.count > 0 { if menuTitle.isEmpty == false {
menuTitle.append(" \(substring.capitalized)") menuTitle.append(" \(substring.capitalized)")
} else { } else {
menuTitle.append(substring.capitalized) menuTitle.append(substring.capitalized)
@ -88,14 +88,14 @@ extension TimezoneDataOperations {
if shouldDateBeShown { if shouldDateBeShown {
let date = Date().formatter(with: "MMM d", timeZone: dataObject.timezone()) let date = Date().formatter(with: "MMM d", timeZone: dataObject.timezone())
if menuTitle.count > 0 { if menuTitle.isEmpty == false {
menuTitle.append(" \(date)") menuTitle.append(" \(date)")
} else { } else {
menuTitle.append("\(date)") menuTitle.append("\(date)")
} }
} }
menuTitle.count > 0 ? menuTitle.append(" \(time(with: 0))") : menuTitle.append(time(with: 0)) menuTitle.isEmpty == false ? menuTitle.append(" \(time(with: 0))") : menuTitle.append(time(with: 0))
return menuTitle return menuTitle
} }

2
Clocker/Panel/Notes Popover/NotesPopover.swift

@ -244,7 +244,7 @@ class NotesPopover: NSViewController {
let remindersScript = NSAppleScript(source: source) let remindersScript = NSAppleScript(source: source)
let eventDescriptor = remindersScript?.executeAndReturnError(&scriptExecutionErrors) let eventDescriptor = remindersScript?.executeAndReturnError(&scriptExecutionErrors)
if let errors = scriptExecutionErrors, errors.allKeys.count > 0 { if let errors = scriptExecutionErrors, errors.allKeys.isEmpty == false {
if let convertedType = errors as? [String: Any] { if let convertedType = errors as? [String: Any] {
Logger.log(object: convertedType, for: "Script Execution Errors") Logger.log(object: convertedType, for: "Script Execution Errors")
} }

4
Clocker/Panel/ParentPanelController.swift

@ -353,7 +353,7 @@ class ParentPanelController: NSWindowController {
if height >= 68.0 { if height >= 68.0 {
height = 75.0 height = 75.0
if let note = currentObject?.note, note.count > 0 { if let note = currentObject?.note, note.isEmpty == false {
height += 30 height += 30
} }
} }
@ -700,7 +700,7 @@ class ParentPanelController: NSWindowController {
let eventCenter = EventCenter.sharedCenter() let eventCenter = EventCenter.sharedCenter()
let now = Date() let now = Date()
if let events = eventCenter.eventsForDate[NSCalendar.autoupdatingCurrent.startOfDay(for: now)], events.count > 0 { if let events = eventCenter.eventsForDate[NSCalendar.autoupdatingCurrent.startOfDay(for: now)], events.isEmpty == false {
OperationQueue.main.addOperation { OperationQueue.main.addOperation {
guard let upcomingEvent = eventCenter.nextOccuring(events) else { guard let upcomingEvent = eventCenter.nextOccuring(events) else {
self.setPlaceholdersForUpcomingCalendarView() self.setPlaceholdersForUpcomingCalendarView()

10
Clocker/Panel/UI/TimezoneDataSource.swift

@ -35,7 +35,7 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate {
} }
func tableView(_ tableView: NSTableView, viewFor _: NSTableColumn?, row: Int) -> NSView? { func tableView(_ tableView: NSTableView, viewFor _: NSTableColumn?, row: Int) -> NSView? {
guard timezones.count > 0 else { guard !timezones.isEmpty else {
if let addCellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "addCell"), owner: self) as? AddTableViewCell { if let addCellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "addCell"), owner: self) as? AddTableViewCell {
return addCellView return addCellView
} }
@ -71,14 +71,14 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate {
} }
func tableView(_: NSTableView, heightOfRow row: Int) -> CGFloat { func tableView(_: NSTableView, heightOfRow row: Int) -> CGFloat {
guard timezones.count > 0 else { guard !timezones.isEmpty else {
return 100 return 100
} }
if let userFontSize = DataStore.shared().retrieve(key: CLUserFontSizePreference) as? NSNumber, timezones.count > row { if let userFontSize = DataStore.shared().retrieve(key: CLUserFontSizePreference) as? NSNumber, timezones.count > row {
let model = timezones[row] let model = timezones[row]
if let note = model.note, note.count > 0 { if let note = model.note, !note.isEmpty {
return CGFloat(65 + userFontSize.floatValue + 30) return CGFloat(65 + userFontSize.floatValue + 30)
} }
@ -89,7 +89,7 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate {
} }
func tableView(_ tableView: NSTableView, rowActionsForRow row: Int, edge: NSTableView.RowActionEdge) -> [NSTableViewRowAction] { func tableView(_ tableView: NSTableView, rowActionsForRow row: Int, edge: NSTableView.RowActionEdge) -> [NSTableViewRowAction] {
guard timezones.count > 0 else { guard !timezones.isEmpty else {
return [] return []
} }
@ -171,7 +171,7 @@ extension TimezoneDataSource: PanelTableViewDelegate {
extension TimezoneCellView { extension TimezoneCellView {
func layout(with model: TimezoneData) { func layout(with model: TimezoneData) {
let shouldDisplay = DataStore.shared().shouldDisplay(.sunrise) && sunriseSetTime.stringValue.count > 0 let shouldDisplay = DataStore.shared().shouldDisplay(.sunrise) && !sunriseSetTime.stringValue.isEmpty
sunriseSetTime.isHidden = !shouldDisplay sunriseSetTime.isHidden = !shouldDisplay
sunriseImage.isHidden = !shouldDisplay sunriseImage.isHidden = !shouldDisplay

14
Clocker/Preferences/General/PreferencesViewController.swift

@ -154,7 +154,7 @@ class PreferencesViewController: ParentViewController {
return return
} }
if selectedTimeZones.count > 0 { if selectedTimeZones.isEmpty == false {
headerView.isHidden = false headerView.isHidden = false
if tableview.subviews.count > 1, let zeroView = notimezoneView, tableview.subviews.contains(zeroView) { if tableview.subviews.count > 1, let zeroView = notimezoneView, tableview.subviews.contains(zeroView) {
@ -340,7 +340,7 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
return nil return nil
} }
if let address = model.formattedAddress, address.count > 0 { if let address = model.formattedAddress, address.isEmpty == false {
return model.formattedAddress return model.formattedAddress
} }
@ -355,7 +355,7 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
return dataSource?.formattedAddress return dataSource?.formattedAddress
} }
} else { } else {
if searchField.stringValue.count > 0 && row < timezoneFilteredArray.count { if searchField.stringValue.isEmpty == false && row < timezoneFilteredArray.count {
return timezoneFilteredArray[row] return timezoneFilteredArray[row]
} }
return timezoneArray[row] return timezoneArray[row]
@ -371,7 +371,7 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
} }
if tableColumn?.identifier.rawValue == "abbreviation" { if tableColumn?.identifier.rawValue == "abbreviation" {
if searchField.stringValue.count > 0 && (row < timezoneFilteredArray.count) { if searchField.stringValue.isEmpty == false && (row < timezoneFilteredArray.count) {
let currentSelection = timezoneFilteredArray[row] let currentSelection = timezoneFilteredArray[row]
if currentSelection == "UTC" { if currentSelection == "UTC" {
return "UTC" return "UTC"
@ -945,7 +945,7 @@ extension PreferencesViewController {
let data = TimezoneData() let data = TimezoneData()
data.setLabel(CLEmptyString) data.setLabel(CLEmptyString)
if searchField.stringValue.count > 0 { if searchField.stringValue.isEmpty == false {
if timezoneFilteredArray.count <= availableTimezoneTableView.selectedRow { if timezoneFilteredArray.count <= availableTimezoneTableView.selectedRow {
return return
} }
@ -1141,7 +1141,7 @@ extension PreferencesViewController {
return return
} }
if searchField.stringValue.count > 0 { if searchField.stringValue.isEmpty == false {
dataTask?.cancel() dataTask?.cancel()
NSObject.cancelPreviousPerformRequests(withTarget: self) NSObject.cancelPreviousPerformRequests(withTarget: self)
perform(#selector(search), with: nil, afterDelay: 0.5) perform(#selector(search), with: nil, afterDelay: 0.5)
@ -1279,7 +1279,7 @@ extension PreferencesViewController {
return filteredArray.count return filteredArray.count
} }
if searchField.stringValue.count > 0 { if searchField.stringValue.isEmpty == false {
return timezoneFilteredArray.count return timezoneFilteredArray.count
} }

Loading…
Cancel
Save