Questions tagged [nsstring]

NSString is the plain-text character-string class in Cocoa and Cocoa Touch. See also NSMutableString, NSData and NSMutableData (for objects that contain bytes rather than human-language characters), and NSAttributedString and NSMutableAttributedString (for rich-text strings).

Filter by
Sorted by
Tagged with
0 votes
1 answer
37 views

Working with NSString manipulating special characters

I want to print an NSString byte by byte: NSString *path = @"/User/user/ǢǨǣ/"; const char *byte_array = [path UTF8String]; for (unsigned char *it = byte_array; *it != 0; ++it) { NSLog(...
0 votes
0 answers
33 views

'NSString initWithFormat' can't print chinese correctly

std::string title = "中文"; NSString* str = [[NSString alloc] initWithFormat: @"test 中文 %s", title.c_str()]; // test 中文 ‰∏≠Êñá I will get messy code. Can't I use %s to insert ...
  • 3
0 votes
2 answers
49 views

Add degree sign to a label with different font sizes - Swift

I am building a weather app. In this app, I am showing the temperature value to the user. In this value, I want to make the temperature value and degree sign different sizes. Because when the degree ...
  • 61
0 votes
1 answer
32 views

How to show JSON response in iPhone using the objective c by dynamically adding " \" to the keys?

I am having a sample code which helps me to print the JSON response. In this I manually added the \ slash symbol before keys and values so it helps me to print the JSON . The code is : NSString *...
  • 789
-2 votes
1 answer
76 views

stringByRemovingPercentEncoding resulting in null string

I've got a file path /Users/alexandra/Downloads/folder%20with%20spaces/ and I want to remove the percent encoding and make it a file URL. Using the method stringByRemovingPercentEncoding makes the ...
-2 votes
1 answer
48 views

What is the difference between String and NSMutableString?

What is the difference between String and NSString?
0 votes
0 answers
67 views

Easiest way to perform a deep copy of a string to pass to a scanner?

I am following the code shown here : Convert hex string to long to read a long from a string. In their example, they have a hard-coded string, but in my own context have another value I am taking the ...
-1 votes
1 answer
44 views

Looking for simple example to write text into a NSImage using Cocoa

NSImage *myNewIconImage=[[NSImage imageNamed:@"FanImage"] copy]; [myNewIconImage lockFocus]; [@"15" drawAtPoint:NSZeroPoint withAttributes:nil]; [myNewIconImage ...
0 votes
2 answers
131 views

How to remove last path of NSURL with special characters

So I'm a little confused. I have an NSURL like this https://something/something/test#4.html I want to remove the last path of this. I tried using URLByDeletingLastPathComponent method but then it ...
  • 13
1 vote
0 answers
59 views

Is there any way to map dictionary of type [NSString: Any] to another [String: Any]

I tried to cast dictionary of type [UIImagePickerController.InfoKey: Any] to [String: Any] type, but it seems it's not possible. The result was nil. I've found straightway to iterate throught original ...
  • 163
0 votes
1 answer
2k views

How to make NSAttributedString link clickable

I have a requirement to display the numbers as clickable link from a string input(contains alphabets and numerals) and on tap of that number it should open an iOS call dialler and should dials that ...
0 votes
0 answers
64 views

How check if output of bash script contains a certain string in Objective-C?

I would like to do something if the output of a shell script contains the string "Caddy 2 serving static files on :2015". This is what I have so far but the beach ball is just spinning. It ...
0 votes
0 answers
261 views

Swift Convert Int to String.Index with and without Emojis to get part of String

I am trying to send a string to an API, which corrects me the text. But the problem is, that text with emoji fails. I have the following string: "Hello hwo are you?" Then I send this string ...
2 votes
1 answer
866 views

Problem in strong tag when Parsing Html in swift 5

Hi i have a problem when im parsing a Html to NSAtributtedString in a UILabel. The problem is in the strong text, the result is too bold (I guess when parsing the font is changed to "GibsonBold&...
1 vote
1 answer
308 views

How to detect if a user typed an ellipsis in a UITextField?

How can you check if you string has an ellipsis in swift? I have noticed some odd behavior when using the swift string functions and learned that ellipsis are to blame. When a user enters ... as ...
0 votes
1 answer
94 views

NSInvocation getArgument NSString/CFString will lead to bad access

I had a requirement, to use NSInvocation's (void)getArgument:(void *)argumentLocation atIndex:(NSInteger)idx; to get the argument. The argument is primarily NSString, So, in my function: - (void)...
  • 9,574
-1 votes
1 answer
40 views

Encoding in Obj C

NSString *s = [NSString stringWithCString:"Long dash symbol \xe2\x80\x94" encoding:(NSUTF8StringEncoding) ]; NSString *t = [NSString stringWithUTF8String:"Long dash symbol \xe2\x80\x94&...
0 votes
1 answer
103 views

How to use String format similar to NSString in Flutter?

How can I use a string format like this with Flutter? static let sampleText = “Stack Overflow is a user-oriented question and answer site about computer programming. Located within the Stack ...
user avatar
-2 votes
1 answer
462 views

Decimal to uint8_t array

uint8_t certificateSerialNumber[] = {0x02, 0x04, 0x24,0xA8,0x16,0x34}; The decimal 614995508 (actual serial number)is converted to hexadecimal 24A81634. The above unit8 array is the representation ...
0 votes
1 answer
212 views

Converting string from C++ to Swift

I am trying to use C++ functions in Swift. To do that, I use an Objective-C wrapper. I am not familiar with Objective-C and C++ so much. My wrapper function takes Swift String as a parameter from ...
0 votes
1 answer
26 views

Dynamically Change Design Element Colors

I am working on trying to make an app that lets the colors of things like navigation bars to be changed server-side. In my app delegate I set up a definition for using Hex codes for UIColors like this:...
-1 votes
1 answer
141 views

What type is NSString and how many bytes?

I am new to objective c. Trying to find out the type of NSString in Objective C. I use the sizeof() method from C and lengthOfBytesUsingEncoding method using UTF8 encoding from NSString. NSString *...
  • 3,212
1 vote
1 answer
70 views

How to discover if a c-string can be encoded to NSString with a given encoding

I am trying to implement code that converts const char * to NSString. I would like to try multiple encodings in a specified order until I find one that works. Unfortunately, all the initWith... ...
  • 382
1 vote
2 answers
53 views

How to extract end code value from given strings

How to get last code value of string Emp-Code-001 //Result 001 Sub-000123 //Result 000123 JOB-ABC-BJ-212-0012 //Result 0012 How to pick out end value of code number from given strings. Here what I ...
  • 4,237
0 votes
1 answer
62 views

NSMutableParagraphStyle is ignored with UIKit's NSString draw method

I'm trying to create a simple text() function for an iOS/iPadOS framework that displays text on screen simply at a coordinate. It honors a global textAlignment state that can be set to either .center, ...
0 votes
1 answer
456 views

Parsing Data Out of Dictionary<String, Any> in Swift

I'm trying to extract data out of a Dictionary<String, Any> in Swift. The dictionary returns the following when I run NSLog("\(terminalDict)"): Optional(["DFEE22": <...
2 votes
1 answer
52 views

How can I individuate the text that encloses some other text in a pattern and edit it with regex

I'm learning about regex and I'm trying to create a program where a certain pattern is substituted. Given the following string: @@@hello@! I want to recognise "@@@" and "@!" and ...
  • 161
0 votes
1 answer
98 views

How can I add a method to NSString in Swift so that it sets the value of Self?

I understand that subclassing NSString is a bad thing, but I'd like to add methods to NSString in Swift so that I can sanitise the string, according to specific rules, before storing its value. I ...
  • 1,142
0 votes
1 answer
129 views

guard let number as NSString and NSNumber

I am getting data from different sources, the variable could be a number or a string of number. How do I make sure that "(number as? NSString)" or "(number as? NSNumber)" always ...
  • 2,798
0 votes
1 answer
424 views

"unknown type name 'NSString'" error when trying to use Metal in a C++ project (vs code, mac m1)

As indicated by the title, I got many "unknown type name 'NSString'" errors from files including NSObjCRuntime.h, NSObject.h, and NSZone.h. Then I added #include <Foundation/NSString.h>...
  • 509
0 votes
1 answer
210 views

A single "|" character in the URL breaks loading contents of URL

I'm trying to load an article in JSON format from the Wikipedia API and I get these errors: nil host used in call to allowsSpecificHTTPSCertificateForHost nil host used in call to ...
  • 996
1 vote
1 answer
85 views

Objective C - Category No Visible selector @removeWhiteSpaceStringWithString

so im trying to add new method for testing using Category from NSString, but some how i must declared like this with following step: Create Category from NSString with name StringExtension so it will ...
  • 73
0 votes
1 answer
49 views

Objective c / How do I call a user-implemented static function into the nsstring class?

+ (NSString *)dictionaryToJson:(NSDictionary *)dic { NSString *result = @""; NSError *err; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:...
  • 25
1 vote
0 answers
242 views

I am getting EXC_BAD_ACCESS in creating NSString using stringWithFormat

Stack trace: 0 libobjc.A.dylib 0x00007fff2021a26e objc_opt_respondsToSelector + 27 1 com.apple.CoreFoundation 0x00007fff20405674 __CFStringAppendFormatCore + 9123 2 com....
0 votes
1 answer
56 views

Draw NSString right justified with NSString.draw(in rect: withAttributes: ) in MacOS?

Cannot draw a String right justified in NSView ( MacOs ) Here is my code, which crashes with : -[__SwiftValue lineBreakMode]: unrecognized selector sent to instance 0x600003408750 let attrs = [...
0 votes
0 answers
62 views

How to convert a keyedArchiver to a string and back again

I want to convert a custom object into a propertyList. Then later I want to retrieve it via NSOutlineView. I use a NSKeyedArchiver/unArchiver to convert my object to and from a NSData. In my custom ...
1 vote
1 answer
126 views

How to convert c++ std::u32string to NSString?

I am developing a bridge between C++ and swift. And I need to convert C++ std::u32string to NSString. Here the code I tried: u32string str = U"some string"; NSLog(@"%@", [[NSString ...
0 votes
1 answer
100 views

NSString initWithBytesNoCopy returns nil while using NSUTF32StringEncoding encoding

I am developing a bridge between C++ and Swift. So I need to convert C++ u32 string into swift String. Here is the problematic code: int count = linesProvider->getDisplayLinesCount(); ...
0 votes
0 answers
104 views

How do I convert AVMetadataItem value to NSDate or NSString?

I am trying to get the date a video was taken and populate a TextView with it in Xcode. I have chosen the video and then gotten the date from the AVMetadataItem creationDate. I can print it out as a ...
-1 votes
2 answers
51 views

Obj-C - Get first X number of characters after a string inside NSString?

I have a string like so: NSString *testing = @"Feb 5 2021 05:00 PM, Feb 6 2021 07:00 PM"; That said, I want my code to be able to grab the 8 characters after "Feb 5, 2021" and ...
  • 1,307
0 votes
0 answers
64 views

NSString String Format Specifiers problem

I wonder what's the problem for these format specifiers which will crash when called with initWithFormat:arguments. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(...
  • 3,266
1 vote
1 answer
108 views

Does this cause leak of NSString?

I am a C programmer, but is pretty new to Objective-C. I've seen NSString-related code like this several times: NSAppleScript* script = [[NSAppleScript alloc] initWithSource: @"<some script ...
  • 167
0 votes
0 answers
96 views

Identify all unicode characters that could use diacritical marks, with macOS APIs

For an optimized search function I'm using, I need to identify any characters in a Unicode string that can potentially be modified with diacritics. For example, the characters "a", "U&...
1 vote
1 answer
574 views

how to convert a NSArray<NSString*> to std::vector<std::string> and pass it to a c++ function in Obejctive-C?

I am new to Objective C and C++, and I have successfully called a C++ function in Objective C following this tutorial. However, the example function in the above turorial has no input parameters, it ...
-1 votes
2 answers
82 views

How to add more strings to the combined string if the length is less than prescribed length?

In iOS I am using two strings to combine and to form a single string. But the combined string must be of 16 characters . So if two strings are small and if we combine both and if it is less than 16 ...
  • 789
1 vote
1 answer
96 views

Replacing Multiple Different Occurences with Multiple Different Replacements - Swift4.2

Trying to find the exact format for doing this. I have a textField user input, I want to take that input and find multiple occurrences and replace each unique occurrence with a different unique ...
2 votes
0 answers
99 views

Why does `NSString` `initWithBytesNoCopy` take `void *` instead of `const void *`

I have a const char * (or const string&), and I would like to append a subsection of it to an NSMutableString. I figured that I could do // s: const char * // start, end: size_t [anNSMutableString ...
  • 6,243
0 votes
1 answer
98 views

How to return string from "for loop"? Objective-C iOS

I'm new in programming in Objective-C language. I need to return this "tabName" from for loop in function. How to compare that app_additional_tab_name_ is equal to tabName? Because now is ...
  • 91
0 votes
1 answer
63 views

Is it redundant to check isKindOfClass in Objective C?

Is it redundant to check isKindOfClass even for non id variables in Objective C? Teammate wrote Swift code. I am reviewing. Do I really need to check with isKindOfClass in the condition or its ...
1 vote
1 answer
209 views

NotificationCenter not always calls observer when specified object is a String

I have been trying to check why my observer is sometimes called and sometimes isn't when specifying a String object to filter out notifications. My original code: NotificationCenter.default....
  • 10.7k

1
2 3 4 5
143