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

Extract SFHFKeychainUtils to dedicated Swift package #24192

Merged
merged 2 commits into from
Mar 12, 2025
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
12 changes: 12 additions & 0 deletions Modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let package = Package(
.library(name: "AsyncImageKit", targets: ["AsyncImageKit"]),
.library(name: "DesignSystem", targets: ["DesignSystem"]),
.library(name: "JetpackStatsWidgetsCore", targets: ["JetpackStatsWidgetsCore"]),
.library(name: "SFHFKeychainUtils", targets: ["SFHFKeychainUtils"]),
.library(name: "WordPressData", targets: ["WordPressData"]),
.library(name: "WordPressFlux", targets: ["WordPressFlux"]),
.library(name: "WordPressShared", targets: ["WordPressShared"]),
Expand Down Expand Up @@ -60,6 +61,12 @@ let package = Package(
]),
.target(name: "DesignSystem", swiftSettings: [.swiftLanguageMode(.v5)]),
.target(name: "JetpackStatsWidgetsCore", swiftSettings: [.swiftLanguageMode(.v5)]),
// SFHFKeychainUtils is an old Objective-C keychain wrapper.
// The implementatoin predates ARC, hence the dedicated target with ARC disabled, for the time being.
.target(
name: "SFHFKeychainUtils",
cSettings: [.unsafeFlags(["-fno-objc-arc"])]
),
.target(name: "UITestsFoundation", dependencies: [
.product(name: "ScreenObject", package: "ScreenObject"),
.product(name: "XCUITestHelpers", package: "ScreenObject"),
Expand Down Expand Up @@ -146,6 +153,7 @@ enum XcodeSupport {
]

let shareAndDraftExtensionsDependencies: [Target.Dependency] = [
"SFHFKeychainUtils",
"WordPressShared",
"WordPressUI",
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
Expand All @@ -168,6 +176,7 @@ enum XcodeSupport {
.xcodeTarget("XcodeTarget_App", dependencies: [
"DesignSystem",
"JetpackStatsWidgetsCore",
"SFHFKeychainUtils",
"WordPressData",
"WordPressFlux",
"WordPressShared",
Expand Down Expand Up @@ -206,6 +215,7 @@ enum XcodeSupport {
.product(name: "WordPressEditor", package: "AztecEditor-iOS"),
]),
.xcodeTarget("XcodeTarget_WordPressTests", dependencies: testDependencies + [
"SFHFKeychainUtils",
"WordPressShared",
.product(name: "Gravatar", package: "Gravatar-SDK-iOS"),
.product(name: "Nimble", package: "Nimble"),
Expand All @@ -216,10 +226,12 @@ enum XcodeSupport {
.xcodeTarget("XcodeTarget_ShareExtension", dependencies: shareAndDraftExtensionsDependencies),
.xcodeTarget("XcodeTarget_DraftActionExtension", dependencies: shareAndDraftExtensionsDependencies),
.xcodeTarget("XcodeTarget_NotificationServiceExtension", dependencies: [
"SFHFKeychainUtils",
"WordPressShared",
]),
.xcodeTarget("XcodeTarget_StatsWidget", dependencies: [
"JetpackStatsWidgetsCore",
"SFHFKeychainUtils",
"WordPressShared",
"WordPressUI",
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UIKit was not needed.

Also, you'll see many import UIKit in the diff. All those Swift files compiled before without importing UIKit because SFHFKeychainUtils.h did that for them and they got access to it via the bridging header.

I find it quite interesting that a seldom visited file had such an impact on unrelate files that did not even use its functionality.



@interface SFHFKeychainUtils : NSObject {
Expand Down Expand Up @@ -68,4 +68,4 @@
+ (NSArray<NSDictionary<NSString *, NSString *> *> *)getAllPasswordsForAccessGroup:(NSString *)accessGroup
error:(NSError **)error;

@end
@end
1 change: 1 addition & 0 deletions WordPress/Classes/Models/Blog/Blog.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "Constants.h"
#import "WPUserAgent.h"
#import "WordPress-Swift.h"
@import SFHFKeychainUtils;

@import NSObject_SafeExpectations;
@import NSURL_IDN;
Expand Down
1 change: 1 addition & 0 deletions WordPress/Classes/Models/WPAccount.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import SFHFKeychainUtils;
#import "WPAccount.h"
#import "WordPress-Swift.h"

Expand Down
2 changes: 2 additions & 0 deletions WordPress/Classes/Services/CredentialsService.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import SFHFKeychainUtils

protocol CredentialsProvider {
func getPassword(username: String, service: String) -> String?
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import SFHFKeychainUtils

@objc
open class NotificationSupportService: NSObject {
Expand Down
1 change: 1 addition & 0 deletions WordPress/Classes/Services/ShareExtensionService.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import SFHFKeychainUtils

@objc
open class ShareExtensionService: NSObject {
Expand Down
1 change: 1 addition & 0 deletions WordPress/Classes/Stores/StatsWidgetsStore.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import JetpackStatsWidgetsCore
import SFHFKeychainUtils
import WidgetKit

class StatsWidgetsStore {
Expand Down
3 changes: 0 additions & 3 deletions WordPress/Classes/System/WordPress-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#import "SFHFKeychainUtils.h"

// WordPress Module

#import "ActivityLogViewController.h"
Expand Down Expand Up @@ -55,7 +53,6 @@
#import "SettingTableViewCell.h"
#import "SettingsTextViewController.h"
#import "SharingViewController.h"
#import "SFHFKeychainUtils.h"
#import "SiteSettingsViewController.h"
#import "SourcePostAttribution.h"
#import "StatsViewController.h"
Expand Down
1 change: 1 addition & 0 deletions WordPress/Classes/System/WordPressAppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import SFHFKeychainUtils
import UIKit
import CocoaLumberjackSwift
import Reachability
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import UIKit

/// Abstracts the logic behind contextual actions that can be applied to FormattableContent.
///
protocol FormattableContentActionCommand: CustomStringConvertible {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import UIKit

/// Styles definition to be applied to a single FormattableContent entity.
public protocol FormattableContentStyles {
Expand Down
2 changes: 2 additions & 0 deletions WordPress/Classes/Utility/KeychainUtils.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import SFHFKeychainUtils

@objcMembers
class KeychainUtils: NSObject {

Expand Down
1 change: 1 addition & 0 deletions WordPress/Classes/Utility/Migrations/10-11/BlogToAccount.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

@import NSObject_SafeExpectations;
@import NSURL_IDN;
@import SFHFKeychainUtils;

@implementation BlogToAccount {
NSString *_defaultWpcomUsername;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#import "WordPress-Swift.h"

@import NSObject_SafeExpectations;
@import SFHFKeychainUtils;

static NSString * const BlogJetpackKeychainPrefix = @"jetpackblog-";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import SFHFKeychainUtils
import UIKit

class BlogToBlog32to33: NSEntityMigrationPolicy {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
import Gridicons
import Aztec
import UIKit

protocol FormatBarItemProvider {
var iconImage: UIImage { get }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import Aztec
import UIKit

// MARK: - TextList.Style
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import SFHFKeychainUtils
import WordPressAuthenticator
import Gridicons
import UIKit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import Foundation
import UIKit

extension FormattableContentKind {
static let image = FormattableContentKind("image")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import SFHFKeychainUtils
import WordPressKit
import JetpackStatsWidgetsCore
import WordPressShared
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
#import "SFHFKeychainUtils.h"
#import "Constants.h"
1 change: 1 addition & 0 deletions WordPress/Shared/SharePost.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import UIKit
import MobileCoreServices

/// A simple shared model to represent a Site
Expand Down
38 changes: 0 additions & 38 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3297,9 +3297,6 @@
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
24CE68AE2CD3375300C7B37D /* Exceptions for "Classes" folder in "WordPress" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
additionalCompilerFlagsByRelativePath = {
Utility/SFHFKeychainUtils.m = "-fno-objc-arc";
};
membershipExceptions = (
"Utility/Migrations/20-21/SafeReaderTopicToReaderTopic.m",
"ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift",
Expand All @@ -3314,9 +3311,6 @@
};
24CE68AF2CD3375300C7B37D /* Exceptions for "Classes" folder in "WordPressShareExtension" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
additionalCompilerFlagsByRelativePath = {
Utility/SFHFKeychainUtils.m = "-fno-objc-arc";
};
membershipExceptions = (
"Extensions/Colors and Styles/WPStyleGuide+ApplicationStyles.swift",
"Extensions/Colors and Styles/WPStyleGuide+Gridicon.swift",
Expand All @@ -3337,7 +3331,6 @@
Utility/BuildInformation/FeatureFlagRolloutStore.swift,
Utility/KeychainUtils.swift,
Utility/Logging/CocoaLumberjack.swift,
Utility/SFHFKeychainUtils.m,
ViewRelated/Aztec/Extensions/FormatBarItemProviders.swift,
"ViewRelated/Aztec/Extensions/Header+WordPress.swift",
"ViewRelated/Aztec/Extensions/TextList+WordPress.swift",
Expand All @@ -3351,9 +3344,6 @@
};
24CE68B02CD3375300C7B37D /* Exceptions for "Classes" folder in "WordPressDraftActionExtension" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
additionalCompilerFlagsByRelativePath = {
Utility/SFHFKeychainUtils.m = "-fno-objc-arc";
};
membershipExceptions = (
"Extensions/Colors and Styles/WPStyleGuide+ApplicationStyles.swift",
"Extensions/Colors and Styles/WPStyleGuide+Gridicon.swift",
Expand All @@ -3374,7 +3364,6 @@
Utility/BuildInformation/FeatureFlagRolloutStore.swift,
Utility/KeychainUtils.swift,
Utility/Logging/CocoaLumberjack.swift,
Utility/SFHFKeychainUtils.m,
ViewRelated/Aztec/Extensions/FormatBarItemProviders.swift,
"ViewRelated/Aztec/Extensions/Header+WordPress.swift",
"ViewRelated/Aztec/Extensions/TextList+WordPress.swift",
Expand All @@ -3388,9 +3377,6 @@
};
24CE68B22CD3375300C7B37D /* Exceptions for "Classes" folder in "WordPressNotificationServiceExtension" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
additionalCompilerFlagsByRelativePath = {
Utility/SFHFKeychainUtils.m = "-fno-objc-arc";
};
membershipExceptions = (
"Extensions/String+Helpers.swift",
"Extensions/UIImage+Extensions.swift",
Expand All @@ -3416,7 +3402,6 @@
Utility/FormattableContent/FormattableRangesFactory.swift,
Utility/FormattableContent/FormattableTextContent.swift,
Utility/KeychainUtils.swift,
Utility/SFHFKeychainUtils.m,
ViewRelated/Notifications/FormattableContent/FormattableCommentContent.swift,
ViewRelated/Notifications/FormattableContent/FormattableUserContent.swift,
ViewRelated/Notifications/FormattableContent/Notifiable.swift,
Expand Down Expand Up @@ -3446,9 +3431,6 @@
};
24CE68B52CD3375300C7B37D /* Exceptions for "Classes" folder in "Jetpack" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
additionalCompilerFlagsByRelativePath = {
Utility/SFHFKeychainUtils.m = "-fno-objc-arc";
};
membershipExceptions = (
"Utility/App Configuration/AppConfiguration.swift",
"Utility/App Configuration/AppConstants.swift",
Expand All @@ -3460,9 +3442,6 @@
};
24CE68B62CD3375300C7B37D /* Exceptions for "Classes" folder in "JetpackShareExtension" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
additionalCompilerFlagsByRelativePath = {
Utility/SFHFKeychainUtils.m = "-fno-objc-arc";
};
membershipExceptions = (
"Extensions/Colors and Styles/WPStyleGuide+ApplicationStyles.swift",
"Extensions/Colors and Styles/WPStyleGuide+Gridicon.swift",
Expand All @@ -3481,7 +3460,6 @@
Utility/BuildInformation/FeatureFlagRolloutStore.swift,
Utility/KeychainUtils.swift,
Utility/Logging/CocoaLumberjack.swift,
Utility/SFHFKeychainUtils.m,
ViewRelated/Aztec/Extensions/FormatBarItemProviders.swift,
"ViewRelated/Aztec/Extensions/Header+WordPress.swift",
"ViewRelated/Aztec/Extensions/TextList+WordPress.swift",
Expand All @@ -3495,9 +3473,6 @@
};
24CE68B72CD3375300C7B37D /* Exceptions for "Classes" folder in "JetpackDraftActionExtension" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
additionalCompilerFlagsByRelativePath = {
Utility/SFHFKeychainUtils.m = "-fno-objc-arc";
};
membershipExceptions = (
"Extensions/Colors and Styles/WPStyleGuide+ApplicationStyles.swift",
"Extensions/Colors and Styles/WPStyleGuide+Gridicon.swift",
Expand All @@ -3516,7 +3491,6 @@
Utility/BuildInformation/FeatureFlagRolloutStore.swift,
Utility/KeychainUtils.swift,
Utility/Logging/CocoaLumberjack.swift,
Utility/SFHFKeychainUtils.m,
ViewRelated/Aztec/Extensions/FormatBarItemProviders.swift,
"ViewRelated/Aztec/Extensions/Header+WordPress.swift",
"ViewRelated/Aztec/Extensions/TextList+WordPress.swift",
Expand All @@ -3530,9 +3504,6 @@
};
24CE68B82CD3375300C7B37D /* Exceptions for "Classes" folder in "JetpackNotificationServiceExtension" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
additionalCompilerFlagsByRelativePath = {
Utility/SFHFKeychainUtils.m = "-fno-objc-arc";
};
membershipExceptions = (
"Extensions/String+Helpers.swift",
"Extensions/UIImage+Extensions.swift",
Expand All @@ -3556,7 +3527,6 @@
Utility/FormattableContent/FormattableRangesFactory.swift,
Utility/FormattableContent/FormattableTextContent.swift,
Utility/KeychainUtils.swift,
Utility/SFHFKeychainUtils.m,
ViewRelated/Notifications/FormattableContent/FormattableCommentContent.swift,
ViewRelated/Notifications/FormattableContent/FormattableUserContent.swift,
ViewRelated/Notifications/FormattableContent/Notifiable.swift,
Expand All @@ -3571,9 +3541,6 @@
};
24CE68B92CD3375300C7B37D /* Exceptions for "Classes" folder in "JetpackStatsWidgets" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
additionalCompilerFlagsByRelativePath = {
Utility/SFHFKeychainUtils.m = "-fno-objc-arc";
};
membershipExceptions = (
Services/KeyValueDatabase.swift,
System/Constants/Constants.m,
Expand All @@ -3586,21 +3553,16 @@
Utility/BuildInformation/FeatureFlagRolloutStore.swift,
Utility/KeychainUtils.swift,
Utility/Logging/CocoaLumberjack.swift,
Utility/SFHFKeychainUtils.m,
"ViewRelated/Stats/Extensions/Double+Stats.swift",
"ViewRelated/Stats/Extensions/NumberFormatter+Stats.swift",
);
target = 0107E0B128F97D5000DE87DB /* JetpackStatsWidgets */;
};
24CE68BA2CD3375300C7B37D /* Exceptions for "Classes" folder in "JetpackIntents" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
additionalCompilerFlagsByRelativePath = {
Utility/SFHFKeychainUtils.m = "-fno-objc-arc";
};
membershipExceptions = (
System/Constants/Constants.m,
Utility/Logging/CocoaLumberjack.swift,
Utility/SFHFKeychainUtils.m,
);
target = 0107E13828FE9DB200DE87DB /* JetpackIntents */;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
#import "Constants.h"

// Shared Helpers
#import "SFHFKeychainUtils.h"
#import "TextBundleWrapper.h"
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import SFHFKeychainUtils
import UserNotifications

import WordPressKit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
// Main App Helpers
#import "Constants.h"

// Shared Helpers
#import "SFHFKeychainUtils.h"
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import UIKit

/// Encapsulates UINavigationController Helper Methods.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
#import "Constants.h"

// Shared Helpers
#import "SFHFKeychainUtils.h"
#import "TextBundleWrapper.h"
Loading