From f7fc5a57d0bde555bf0e3e6fb2a11e301899e9ea Mon Sep 17 00:00:00 2001 From: LunaTheFoxgirl Date: Fri, 13 Dec 2024 20:04:32 +0100 Subject: [PATCH] Add NSString support to numem strings --- source/numem/string.d | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/source/numem/string.d b/source/numem/string.d index a484d7f..e464fa9 100644 --- a/source/numem/string.d +++ b/source/numem/string.d @@ -12,6 +12,9 @@ import std.traits; import core.stdcpp.string; import std.traits : Unqual, hasFunctionAttributes; +// Objective-C support +version(Have_objective_d) import foundation.nsstring : NSString; + /// Gets whether the provided type is some type of string. enum isSomeString(T) = isSomeSafeString!T || @@ -153,6 +156,17 @@ public: } } + /** + Creates a string from an Objective-C NSString. + + This will release 1 reference from the NSString. + */ + version(Have_objective_d) + this(NSString str) { + this.set_(str.toString()); + str.release(); + } + /** Creates a string from a string with a different encoding. @@ -312,6 +326,14 @@ public: */ alias toString = toDString; + /** + To Objective-C NSString + */ + version(Have_objective_d) + NSString toNSString() { + return NSString.create(ptr); + } + /** Set content of string */