cstrings: add NSStringToString#447
Merged
Merged
Conversation
hajimehoshi
reviewed
May 9, 2026
hajimehoshi
reviewed
May 9, 2026
Member
I understand why we need a separate package. Do we have a plan to put other things than objc helpers? If we need helpers for the |
Member
|
Another safer bet is |
hajimehoshi
reviewed
May 9, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a Darwin-only helper to convert Objective-C NSString objects (passed as objc.ID) into Go string, addressing the common footgun around UTF-8 vs UTF-16 length handling (Issue #438).
Changes:
- Introduces new
cstringspackage withNSStringToString(objc.ID) stringon Darwin. - Loads Foundation at init-time to ensure
NSString/related classes are available. - Adds Darwin-only tests for nil input, empty string, normal string, and non-NSString panic behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| cstrings/nsstrings_darwin.go | Adds NSStringToString implementation and init-time Foundation/selector/class setup. |
| cstrings/nsstrings_darwin_test.go | Adds unit tests validating conversion behavior and panic on non-NSString input. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
|
Still LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What issue is this addressing?
Closes #438
What type of issue is this addressing?
feature
What this PR does | solves
Add function NSStringToString to convert an NSString ID to a Go string.
I put this in a new package
cstringsso as to not create a dependency on Foundation framework in theobjcpackage. This package would also be a good spot to export the internalstrings.GoStringfunction.