Skip to content

Commit

Permalink
Add NSString support to numem strings
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTheFoxgirl committed Dec 13, 2024
1 parent 61a60c6 commit f7fc5a5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions source/numem/string.d
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit f7fc5a5

Please sign in to comment.