nsstring

Does NSStringFromClass([MyEntityClass class]) generate a safe Core Data Entity name?

杀马特。学长 韩版系。学妹 提交于 2019-11-30 18:43:02
Most (all I've seen) Core Data tutorials use the following code snippet with @"MyEntityClass" hard-coded in: NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"MyEntityClass"]; Is it safe to use NSStringFromClass() as an Entity Name? NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:NSStringFromClass([MyEntityClass class])]; This seams to be much easer to deal with regarding refactoring and the like. Especially since I am having Xcode create my NSManagedObject subclasses. I ask because I have never seen this before, so perhaps I am missing something. Yes,

Objective-C how to print out leading 0 for a float?

流过昼夜 提交于 2019-11-30 18:20:06
How do you print out leading zeros for a float using the NSString type? Input: 3.14 Desired output: 03.1 Using format @"%02.1f" Output: 3.1 imaginaryboy You want @"04.1f" . The 4 is the total width. As you can see from the documentation , the format strings conform to the IEEE printf specification . The format string you've specified breaks down as follows: 0 -- Pad with zeros. 2 -- The entire resulting formatted value will have a minimum width of 2. .1 -- Precision of 1 digit following the decimal point. For some reason you can't set the pre-decimal width on float numbers (maybe it's a bug

Find coordinates of a substring in UILabel

ε祈祈猫儿з 提交于 2019-11-30 18:17:30
问题 I have a string coming from server which I am displaying on UILabel. It is within that string, I am identifying some particular substring. I want to place a button on that substring(button will be a subview of UILabel). For this I require substring coordinates. I went through this Gist but I am not able to understand it. Suppose my complete string is abc, 567-324-6554, New York . I want 567-324-6554 to be displayed on button, for which I need its coordinates. How can I use above link to find

Include a variable inside a NSString?

怎甘沉沦 提交于 2019-11-30 17:40:47
问题 This works fine, we all know that: NSString *textoutput = @"Hello"; outLabel.text = textoutput; However, what if you want to include a variable inside that NSString statement like the following: NSString *textoutput =@"Hello" Variable; In C++ I know when I cout something and I wanted to include a variable all I did was soemthing like this: cout << "Hello" << variableName << endl; So I'm trying to accomplish that with Objective-C but I don't see how. 回答1: You can do some fancy formatting using

How can i implement the behaviour as in cluster pattern by apple (NSString and NSCFString)

主宰稳场 提交于 2019-11-30 16:39:57
I am simply writing the following code for testing purpose: NSString *aStr = [[NSString alloc] initWithFormat:@"Foo"]; aStr = [aStr initWithFormat:@"Bar"];//Crashed here I am getting the following error: *** initialization method -initWithFormat:locale:arguments: cannot be sent to an abstract object of class __NSCFString: Create a concrete instance! If i write the following code same thing happen NSString *aStr = [NSString alloc]; aStr = [aStr initWithFormat:@"Foo"]; aStr = [aStr initWithFormat:@"Bar"]; //Crashed here By google I come to know that initWithFormat will return the NSCFString

NSString with emoticons/emojis url encode

谁说胖子不能爱 提交于 2019-11-30 16:33:42
I am trying to take the contents of a UITextField that may contain special characters and emojis and turn it into something I can pass in a GET request to a PHP service. If I do not encode the string at all, the emojis show up just fine (I can see them in the DB and they come back to me properly)... but if I add special chars (~!@#$%, etc.) the GET request chokes. So I run the string through the url encoder: [commentText stringByAddingPercentEscapesUsingEncoding:NSNonLossyASCIIStringEncoding]; I am using the NSNonLossyASCIIStringEncoding to get the emojis out properly, which works, but using

How can i convert NSdata to hex string?

╄→尐↘猪︶ㄣ 提交于 2019-11-30 16:30:03
i tried following codes for converting a NSData to hex string values but all are wrong? here "result" is my NSdata i need a hex string as output but iam not getting that NSUInteger dataLength = [result length]; NSLog(@"%d",dataLength); NSMutableString *string = [NSMutableString stringWithCapacity:dataLength*2]; const unsigned char *dataBytes = [result bytes]; for (NSInteger idx = 0; idx < dataLength; ++idx) { [string appendFormat:@"%02x", dataBytes[idx]]; } NSLog(@"%@",string); how can i convert this please UPDATES: the result data contains encrypted string .i want to convert this to hex

Using a String representing the name of a variable to set the variable

心已入冬 提交于 2019-11-30 16:24:26
This is a basic example that I know can be simplified, but for testing sake, I would like to do this in such a way. I want to set a variable based on an appending string (the variables "cam0" and "pos1" are already declared in the class). The appending string would essentially be an index, and i would iterate through a loop to assign cameras (cam0, cam1..) to different positions (pos0, pos1..). cam0 is defined as an UIImageView pos1 is defined as a CGRect This works for a NSString Variable named coverIndex: NSString* text = [[NSString alloc] initWithString:@""]; NSLog(@"%@",(NSString *)[self

__unsafe_unretained NSString struct var

瘦欲@ 提交于 2019-11-30 16:22:24
I am trying to create a structure that has several different variable of different types in it. several of the types are of NSString, but trying to do this was causing an error ARC forbids Objective-C objects in structs or unions so having read about the error I see its sensible to add __unsafe_unretained before the NSString declaration, However I have no idea what the ramifications of this will be, I have had a quick read around and found this detailed post about the differences of __strong __weak __unsafe_unretained however it was still abit vague about whats going on with a NSString thats

UILabel + IRR, KRW and KHR currencies with wrong symbol

↘锁芯ラ 提交于 2019-11-30 15:57:10
I'm experiencing issues when converting decimal to currency for Korean Won, Cambodian Riel and Iranian Rial and showing the result to the UILabel text. Conversion itself passes just fine and I can see correct currency symbol at the debugger, even the NSLog prints the symbol well. If I assign this NSString instance to the UILabel text, the currency symbol is shown as a crossed box instead of the correct symbol. There is no other code between, does not matter what font I use. I tried to print ₩ (Korean Won) using the unicode value (0x20A9) or even using UTF8 representation (\xe2\x82\xa9), but