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

Conversation

mokagio
Copy link
Contributor

@mokagio mokagio commented Mar 12, 2025

Problem Some of the files we are moving out of the WordPress/Jetpack target to WordPressData access the keychain via SFHFKeychainUtils, but we cannot move out the utility itself because other files unrelated to storage use it, too.

Solution Move SFHFKeychainUtils to a shared location.

Given the object is implemented in Objective-C, I initially tried to move it to WordPressSharedObjC, but this failed because SFHFKeychainUtils is so old it does not use ARC.

Side note: Talk about good code.
It might not look pretty, but this code from back in 2008 is still working fine (or fine enough that we haven't notice errors) and will continue to do so till we'll get to modify it.

I decided not to go down the rabbit hole of rewriting it to support ARC (maybe I should have) and instead moved it into a dedicated package with the -fno-objc-arc compiler flag.

Testing

I run the WordPress app on my iPhone and smoke tested it checking all tabs.


Part of #24165

All those Swift files compile without importing UIKit because
`SFHFKeychainUtils.h` did that for them and they got access to it via
the bridging header.

Next, we'll move SFHFKeychainUtils into the modules, and UIKit will no
longer be available through it.

Side note: UIKit should not have been available via SFHFKeychainUtils in
the first place. On top of that, SFHFKeychainUtils does not need UIKit
either.
@mokagio mokagio self-assigned this Mar 12, 2025
@mokagio mokagio changed the title # Extract SFHFKeychainUtils to dedicated Swift package Extract SFHFKeychainUtils to dedicated Swift package Mar 12, 2025
@mokagio mokagio added this to the 25.9 milestone Mar 12, 2025
@mokagio mokagio added the Core Data Issues related to Core Data label Mar 12, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented Mar 12, 2025

1 Warning
⚠️ Modules/Package.swift was changed without updating its corresponding Package.resolved. Please resolve the Swift packages as appropriate to your project setup (e.g. in Xcode or by running swift package resolve).

Generated by 🚫 Danger

#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.

@@ -1,6 +1,7 @@
// TODO: Port to yet to create SFHFKeychainUtils test package
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Waiting for feedback on this PR. Then, if the setup remains the same, I'll open an issue to remember to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 12, 2025

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr24192-45a98f7
Version25.8
Bundle IDorg.wordpress.alpha
Commit45a98f7
App Center BuildWPiOS - One-Offs #11643
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

We need it in a dedicated package because the Objective-C implementation
does not use ARC. Therefore, we need to use the `-fno-objc-arc` compiler
setting. But such a setting should be applied sparingly so instead of
blanket using it in an existing Objective-C package like
WordPressSharedObjC, we use it surgically just for this file.
@mokagio mokagio force-pushed the mokagio/SFHFKeychainUtils-wordpressshared branch from 95580ff to 45a98f7 Compare March 12, 2025 07:47
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 12, 2025

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr24192-45a98f7
Version25.8
Bundle IDcom.jetpack.alpha
Commit45a98f7
App Center Buildjetpack-installable-builds #10672
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@mokagio mokagio marked this pull request as ready for review March 12, 2025 10:42
@mokagio mokagio requested review from crazytonyli and kean and removed request for crazytonyli March 12, 2025 10:42
Copy link
Contributor

@kean kean left a comment

Choose a reason for hiding this comment

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

This is very nice.

@kean
Copy link
Contributor

kean commented Mar 12, 2025

And I need this too for my work on app extensions – merging 🙇

@kean kean added this pull request to the merge queue Mar 12, 2025
Merged via the queue into trunk with commit 5f09992 Mar 12, 2025
25 checks passed
@kean kean deleted the mokagio/SFHFKeychainUtils-wordpressshared branch March 12, 2025 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Data Issues related to Core Data
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants