Skip to content

Commit

Permalink
- swiftlint: disable large_tuple warning
Browse files Browse the repository at this point in the history
- ios-sdk: use branch fix/warnings that fixes OpenSSL warnings
- replace associated keys using structs or strings with static malloc results as suggested by Apple Engineer Quinn (https://forums.swift.org/t/handling-the-new-forming-unsaferawpointer-warning/65523/7)
- remove unneeded/unused overrides
- reformat spacing in parts of the code and remove superfluous spaces to remove SwiftLint warnings
- replace calls to CLLocationManager.authorizationStatus() with CLLocationManager.authorizationStatus
- remove deprecated OpenSSL ERR_load_* calls, since OpenSSL loads these automatically (https://www.openssl.org/docs/man3.3/man7/migration_guide.html)
- LAContext+Extension: add cases for Optic ID
- remove unused variables and calls
- remove unused, non-existent "gear.png" image from asset catalog
  • Loading branch information
felix-schwarz committed May 15, 2024
1 parent 1862e4f commit 7dd774b
Show file tree
Hide file tree
Showing 26 changed files with 32 additions and 94 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ disabled_rules:
- control_statement
- nesting
- comma
- large_tuple
custom_rules:
empty_line_after_guard_statement:
included: ".*\\.swift"
Expand Down
2 changes: 1 addition & 1 deletion ios-sdk
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ class UploadFileAction: UploadBaseAction {
override class var keyCommand : String? { return "+" }
override class var keyModifierFlags: UIKeyModifierFlags? { return [.command] }

private struct AssociatedKeys {
static var actionKey = "action"
}
private static let associatedKeyAction = malloc(1)!

// MARK: - Action implementation
override func run() {
Expand All @@ -47,7 +45,7 @@ class UploadFileAction: UploadBaseAction {
documentPickerViewController.allowsMultipleSelection = true

// The action is only held weakly as delegate. This makes sure the Action object sticks around as long as UIDocumentPickerViewController, so that UIDocumentPickerViewController can call the UIDocumentPickerDelegate method.
objc_setAssociatedObject(documentPickerViewController, &AssociatedKeys.actionKey, self, .OBJC_ASSOCIATION_RETAIN)
objc_setAssociatedObject(documentPickerViewController, UploadFileAction.associatedKeyAction, self, .OBJC_ASSOCIATION_RETAIN)

viewController.present(documentPickerViewController, animated: true)
}
Expand Down
4 changes: 2 additions & 2 deletions ownCloud/Client/Actions/EditDocumentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class EditDocumentViewController: QLPreviewController, Themeable {
}
}
}

func disableEditingMode() {
if #available(iOS 17.0, *) {
if let rightBarButtonItems = self.navigationItem.rightBarButtonItems, rightBarButtonItems.count > 0 {
Expand All @@ -171,7 +171,7 @@ class EditDocumentViewController: QLPreviewController, Themeable {

@objc func dismissAnimated() {
disableEditingMode()

if savingMode == nil {
requestsavingMode { (savingMode) in
self.dismiss(animated: true) {
Expand Down
4 changes: 0 additions & 4 deletions ownCloud/Client/PhotoAlbumTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ class PhotoAlbumTableViewController : UITableViewController, Themeable {
fetchAlbums()
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
}

// MARK: - Theme support

func applyThemeCollection(theme: Theme, collection: ThemeCollection, event: ThemeEvent) {
Expand Down
5 changes: 0 additions & 5 deletions ownCloud/Client/Viewer/PDF/PDFSearchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ class PDFSearchViewController: UITableViewController, PDFDocumentDelegate, Theme
NotificationCenter.default.removeObserver(self)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

@objc func dismissSearch() {
typeDelayTimer?.invalidate()
self.dismiss(animated: true) {
Expand Down
4 changes: 0 additions & 4 deletions ownCloud/Client/Viewer/PDF/PDFTocTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ class PDFTocTableViewController: UITableViewController, Themeable {
Theme.shared.unregister(client: self)
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
// These lines mitigates the issue with incorrect layout of child view controller
Expand Down
4 changes: 0 additions & 4 deletions ownCloud/Client/Viewer/PDF/PDFViewerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,6 @@ class PDFViewerViewController: DisplayViewController, DisplayExtension, UIPopove
self.fullScreen.toggle()
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
pdfView.scaleFactor = pdfView.scaleFactorForSizeToFit
Expand Down
21 changes: 0 additions & 21 deletions ownCloud/Resources/Assets.xcassets/gear.imageset/Contents.json

This file was deleted.

2 changes: 1 addition & 1 deletion ownCloud/Settings/BackgroundUploadsSettingsSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class BackgroundUploadsSettingsSection: SettingsSection {
locationServicesRowSubtitle += " "
locationServicesRowSubtitle += "Otherwise background media uploads using background refresh technology would depend on how frequently you use the app.".localized

let currentAuthStatus = CLLocationManager.authorizationStatus() == .authorizedAlways
let currentAuthStatus = CLLocationManager().authorizationStatus == .authorizedAlways
backgroundLocationRow = StaticTableViewRow(switchWithAction: { (_, sender) in
if let enableSwitch = sender as? UISwitch {
if enableSwitch.isOn {
Expand Down
2 changes: 1 addition & 1 deletion ownCloud/Shortcut Files/INIFile+ShortcutResolution.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public extension INIFile {
}
})
} else {
var effectiveError: Error? = nil
var effectiveError: Error?

switch OpenShortcutFileAction.openShortcutMode {
case .itemsOnly, .none:
Expand Down
6 changes: 3 additions & 3 deletions ownCloud/Tasks/ScheduledTaskManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ extension ScheduledTaskManager : CLLocationManagerDelegate {
@discardableResult func startLocationMonitoringIfAuthorized() -> Bool {
guard let userDefaults = OCAppIdentity.shared.userDefaults else { return false }

if CLLocationManager.authorizationStatus() == .authorizedAlways && userDefaults.backgroundMediaUploadsLocationUpdatesEnabled {
if locationManager.authorizationStatus == .authorizedAlways && userDefaults.backgroundMediaUploadsLocationUpdatesEnabled {
Log.debug(tagged: ["TASK_MANAGER", "MEDIA_UPLOAD"], "Significant location monitoring has started")
startLocationTracking()
return true
Expand All @@ -424,13 +424,13 @@ extension ScheduledTaskManager : CLLocationManagerDelegate {
}

func stopLocationMonitoring() {
if CLLocationManager.authorizationStatus() == .authorizedAlways || CLLocationManager.authorizationStatus() == .authorizedWhenInUse {
if locationManager.authorizationStatus == .authorizedAlways || locationManager.authorizationStatus == .authorizedWhenInUse {
stopLocationTracking()
}
}

func requestLocationAuthorization() -> Bool {
let currentStatus = CLLocationManager.authorizationStatus()
let currentStatus = locationManager.authorizationStatus
switch currentStatus {
case .notDetermined, .authorizedWhenInUse:
self.locationManager.requestAlwaysAuthorization()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ - (OCLicenseAppStoreReceiptParseError)parse
}

// OpenSSL setup
ERR_load_X509_strings();
ERR_load_PKCS7_strings();
OpenSSL_add_all_digests();

// Parse receipt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ - (void)updateSavedSearch:(OCSavedSearch *)savedSearch

[self.keyValueStore updateObjectForKey:OCKeyValueStoreKeySavedSearches usingModifier:^id _Nullable(id _Nullable existingObject, BOOL * _Nonnull outDidModify) {
NSMutableArray<OCSavedSearch *> *savedSearches = OCTypedCast(existingObject, NSMutableArray);
NSUInteger countBefore;

if (savedSearches != nil)
{
Expand Down
1 change: 0 additions & 1 deletion ownCloudAppFramework/Sidebar Items/OCVault+SidebarItems.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ - (void)updateSidebarItem:(OCSidebarItem *)sidebarItem

[self.keyValueStore updateObjectForKey:OCKeyValueStoreKeySidebarItems usingModifier:^id _Nullable(id _Nullable existingObject, BOOL * _Nonnull outDidModify) {
NSMutableArray<OCSidebarItem *> *sidebarItems = OCTypedCast(existingObject, NSMutableArray);
NSUInteger countBefore;

if (sidebarItems != nil)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public class AccountController: NSObject, OCDataItem, OCDataItemVersioning, Acco
// Other sidebar items
var otherItems: [OCDataItem & OCDataItemVersioning] = []

func addSidebarItem(_ itemID: SpecialItem, _ generate: ()->OCDataItem&OCDataItemVersioning) {
func addSidebarItem(_ itemID: SpecialItem, _ generate: () -> OCDataItem & OCDataItemVersioning) {
var item = specialItems[itemID]

if item == nil {
Expand Down Expand Up @@ -649,7 +649,7 @@ extension AccountController: DataItemSelectionInteraction {
if let personalSpaceDataItemRef = self.personalSpaceDataItemRef,
let sectionID = section?.identifier,
let personalFolderItemRef = section?.collectionViewController?.wrap(references: [personalSpaceDataItemRef], forSection: sectionID).first,
let /* spacesFolderItemRef */ _ = section?.collectionViewController?.wrap(references: [specialItemsDataReferences[.spacesFolder]!], forSection: sectionID).first {
section?.collectionViewController?.wrap(references: [specialItemsDataReferences[.spacesFolder]!], forSection: sectionID).first != nil {
section?.collectionViewController?.addActions([
CollectionViewAction(kind: .select(animated: false, scrollPosition: .centeredVertically), itemReference: personalFolderItemRef)
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,15 @@ class SeparatorLayoutGuideCustomizer : NSObject {
}

extension UIView {
private struct AssociatedKeys {
static var separatorLayoutGuideCustomizerKey = "separatorLayoutGuideCustomizerKey"
}
private static let associatedKeySeparatorLayoutGuideCustomizer = malloc(1)!

var separatorLayoutGuideCustomizer: SeparatorLayoutGuideCustomizer? {
get {
return objc_getAssociatedObject(self, &AssociatedKeys.separatorLayoutGuideCustomizerKey) as? SeparatorLayoutGuideCustomizer
return objc_getAssociatedObject(self, UIView.associatedKeySeparatorLayoutGuideCustomizer) as? SeparatorLayoutGuideCustomizer
}

set {
objc_setAssociatedObject(self, &AssociatedKeys.separatorLayoutGuideCustomizerKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
objc_setAssociatedObject(self, UIView.associatedKeySeparatorLayoutGuideCustomizer, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,15 @@ public class CollectionViewCellConfiguration: NSObject {
}

public extension NSObject {
private struct AssociatedKeys {
static var cellConfiguration = "cellConfiguration"
}
private static let associatedKeyCellConfiguration = malloc(1)!

var ocCellConfiguration : CollectionViewCellConfiguration? {
set {
objc_setAssociatedObject(self, &AssociatedKeys.cellConfiguration, newValue, .OBJC_ASSOCIATION_RETAIN)
objc_setAssociatedObject(self, NSObject.associatedKeyCellConfiguration, newValue, .OBJC_ASSOCIATION_RETAIN)
}

get {
return objc_getAssociatedObject(self, &AssociatedKeys.cellConfiguration) as? CollectionViewCellConfiguration
return objc_getAssociatedObject(self, NSObject.associatedKeyCellConfiguration) as? CollectionViewCellConfiguration
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1315,11 +1315,6 @@ open class ClientItemViewController: CollectionViewController, SortBarDelegate,
}
}
}

// MARK: - Themeing
public override func applyThemeCollection(theme: Theme, collection: ThemeCollection, event: ThemeEvent) {
super.applyThemeCollection(theme: theme, collection: collection, event: event)
}
}

extension ThemeCSSSelector {
Expand Down
4 changes: 4 additions & 0 deletions ownCloudAppShared/UIKit Extension/LAContext+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extension LAContext {
switch self.biometryType {
case .faceID : return "Face ID".localized
case .touchID: return "Touch ID".localized
case .opticID: return "Optic ID".localized
case .none: return nil
@unknown default: return nil
}
Expand All @@ -41,6 +42,9 @@ extension LAContext {
case .touchID:
return UIImage(systemName: "touchid")

case .opticID:
return UIImage(systemName: "opticid")

case .none: return nil
@unknown default: return nil
}
Expand Down
8 changes: 3 additions & 5 deletions ownCloudAppShared/UIKit Extension/UIButton+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ import UIKit
import ownCloudSDK

public extension UIButton {
private struct AssociatedKeys {
static var actionKey = "actionKey"
}
private static let associatedActionKey = malloc(1)!

var actionIdentifier: OCExtensionIdentifier? {
get {
return objc_getAssociatedObject(self, &AssociatedKeys.actionKey) as? OCExtensionIdentifier
return objc_getAssociatedObject(self, UIButton.associatedActionKey) as? OCExtensionIdentifier
}

set {
if newValue != nil {
objc_setAssociatedObject(self, &AssociatedKeys.actionKey, newValue!, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
objc_setAssociatedObject(self, UIButton.associatedActionKey, newValue!, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions ownCloudAppShared/UIKit Extension/UIView+OCDataItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ import UIKit
import ownCloudSDK

extension UIView : OCDataItem, OCDataItemVersioning {
static var viewUUIDKey = "_ocViewUUIDKey"
private static let associatedKeyViewUUID = malloc(1)!

public var dataItemType: OCDataItemType {
return .view
}

public var dataItemReference: OCDataItemReference {
if let uuid = objc_getAssociatedObject(self, &UIView.viewUUIDKey) as? NSString {
if let uuid = objc_getAssociatedObject(self, UIView.associatedKeyViewUUID) as? NSString {
return uuid
} else {
let uuid = UUID().uuidString as NSString
objc_setAssociatedObject(self, &UIView.viewUUIDKey, uuid, .OBJC_ASSOCIATION_RETAIN)
objc_setAssociatedObject(self, UIView.associatedKeyViewUUID, uuid, .OBJC_ASSOCIATION_RETAIN)
return uuid
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ open class MoreStaticTableViewController: StaticTableViewController {
open override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return nil
}

open override func applyThemeCollection(theme: Theme, collection: ThemeCollection, event: ThemeEvent) {
super.applyThemeCollection(theme: theme, collection: collection, event: event)
}
}

open class MoreStaticTableViewSection : StaticTableViewSection {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ public class AppStateActionGoToPersonalFolder: AppStateAction {
super.init(coder: coder)
}

override public func encode(with coder: NSCoder) {
super.encode(with: coder)
}

var drivesSubscription: OCDataSourceSubscription?

override public func perform(in clientContext: ClientContext, completion: @escaping AppStateAction.Completion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ public protocol ThemeCSSChangeObserver {
}

extension NSObject {
private struct AssociatedKeys {
static var cssSelectors = "_cssSelectors"
}
private static let associatedKeyCssSelectors = malloc(1)!

public var activeThemeCSS: ThemeCSS {
return Theme.shared.activeCollection.css
Expand All @@ -42,15 +40,15 @@ extension NSObject {

public var cssSelectors: [ThemeCSSSelector]? {
set {
objc_setAssociatedObject(self, &AssociatedKeys.cssSelectors, newValue, .OBJC_ASSOCIATION_RETAIN)
objc_setAssociatedObject(self, NSObject.associatedKeyCssSelectors, newValue, .OBJC_ASSOCIATION_RETAIN)

if let changeObserver = self as? ThemeCSSChangeObserver {
changeObserver.cssSelectorsChanged()
}
}

get {
var effectiveSelectors: [ThemeCSSSelector] = objc_getAssociatedObject(self, &AssociatedKeys.cssSelectors) as? [ThemeCSSSelector] ?? []
var effectiveSelectors: [ThemeCSSSelector] = objc_getAssociatedObject(self, NSObject.associatedKeyCssSelectors) as? [ThemeCSSSelector] ?? []

if let autoSelector = self as? ThemeCSSAutoSelector {
effectiveSelectors.insert(contentsOf: autoSelector.cssAutoSelectors, at: (effectiveSelectors.count > 0) ? (effectiveSelectors.count-1) : 0)
Expand Down
2 changes: 0 additions & 2 deletions ownCloudAppShared/User Interface/Theme/ThemeCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,6 @@ public class ThemeCollection : NSObject {
cellStateSet = ThemeColorStateSet.from(colorSet: cellSet, for: interfaceStyle)
collectionBackgroundColor = darkBrandColor.darker(0.1)

cellSet.backgroundColor

groupedCellSet = ThemeColorSet.from(backgroundColor: darkBrandColor, tintColor: lightBrandColor, for: interfaceStyle)
groupedCellStateSet = ThemeColorStateSet.from(colorSet: groupedCellSet, for: interfaceStyle)
groupedCollectionBackgroundColor = useSystemColors ? .systemGroupedBackground.resolvedColor(with: styleTraitCollection) : navigationBarSet.backgroundColor.darker(0.3)
Expand Down

0 comments on commit 7dd774b

Please sign in to comment.