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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

funsiyuan
Copy link

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
Author

funsiyuan commented Jun 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant