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

Update deprecated method usage in encryption example #8623

Conversation

funsiyuan
Copy link
Contributor

Hello, this is just a small PR for update README example code.

Goals

Update the code example in the documentation to replace the deprecated withUnsafeMutableBytes method with a more modern and safe approach.

Expected results

The documentation should now include an example that does not use any deprecated methods, ensuring it remains current and free of warnings.

Actual results

The documentation previously included an example that used the deprecated withUnsafeMutableBytes method, which could lead to warnings or potential issues in future Swift versions.

Steps to reproduce

  1. Open the Realm Swift documentation.
  2. Locate the example code that generates a random encryption key.
  3. Observe the use of the deprecated withUnsafeMutableBytes method.

Code sample that highlights the issue

// Generate a random encryption key
var key = Data(count: 64)
_ = key.withUnsafeMutableBytes { bytes in
    SecRandomCopyBytes(kSecRandomDefault, 64, bytes)
}

// Add the encryption key to the config and open the realm
let config = Realm.Configuration(encryptionKey: key)
let realm = try Realm(configuration: config)

// Use the Realm as normal
let dogs = realm.objects(Dog.self).filter("name contains 'Fido'")

- Replaced the usage of `withUnsafeMutableBytes` with a more modern and safe approach in the example code that generates a random encryption key.
- This update ensures compatibility with modern Swift versions and prevents potential warnings.
@funsiyuan
Copy link
Contributor Author

funsiyuan commented Jun 25, 2024

@tgoyne Hi,
this is a small PR. Hope someone review this. Thx.

@funsiyuan
Copy link
Contributor Author

Hello @dacharyc,

It looks like the CI check has failed.
Maybe adding the no-jira-ticket and no-changelog labels will fix this.

@dianaafanador3 dianaafanador3 added no-changelog no-jira-ticket Skip checking the PR title for Jira reference labels Jul 1, 2024
Copy link
Contributor

@dacharyc dacharyc left a comment

Choose a reason for hiding this comment

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

Hey @funsiyuan - thank you for this contribution! This looks like a reasonable change. It's similar to our official documentation at: Encrypt a Realm - Swift SDK

I'm checking with the team about the Contributor License Agreement that we require folks to sign in order to contribute. Normally, there's a bot that runs on PRs to check the CLA, but it looks like the bot hasn't done that check for this PR. Once we get that sorted, I believe this will be fine to merge.

@funsiyuan
Copy link
Contributor Author

Hello @dacharyc.
Thank you for the update! I have already submitted the CLA when I filed the Pull Request.
I'm excited about the potential merge of my first OSS contribution. Looking forward to it!

@dacharyc
Copy link
Contributor

dacharyc commented Jul 9, 2024

Got it - I was able to verify the CLA without the bot.

This looks good - thank you for your contribution, @funsiyuan!

@dacharyc dacharyc merged commit 235d003 into realm:master Jul 9, 2024
5 of 7 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2024
@funsiyuan funsiyuan deleted the update-README-for-deprecated-encryption-example branch August 26, 2024 07:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
no-changelog no-jira-ticket Skip checking the PR title for Jira reference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants