nsstring

Convert NSString->NSDate?

微笑、不失礼 提交于 2019-11-28 14:45:06
I need to convert my NSString in the end to an NSDate but I am having problems doing so. How would I achieve the same functionality with this code while making the end result an NSDate? //Date and Format it NSDate *now = [NSDate date]; NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease]; [formatter setDateFormat:@"MM-dd-yyyy"]; NSString *dateString = [formatter stringFromDate:now]; Thanks! Edit: //Date and Format it NSDate *now = [NSDate date]; NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease]; [formatter setDateFormat:@"MM-dd-yyyy"]; NSString

i have NSString value in addViewController and i want to display this value in UILabel of DetailsViewController

好久不见. 提交于 2019-11-28 14:35:17
I am newbie to programming. Any help could be greatly appreciated. It's in AddViewController. NSLog(@"Am Currently at %@",locatedAt); DetailsOfPeopleViewController *details=[DetailsOfPeopleViewController alloc]; details.testAddressStr=[NSString stringWithFormat:@"%@",locatedAt]; details.testAddressStr is displaying the value here, but it's not passing this value to DetailsViewController. The value of locatedAt is displaying in the AddViewController. When I try to display this value in UILabel of DetailsViewController class it's not displaying that value in the label. In DetailsViewController.h

If statement checking for NSString equality using ==

馋奶兔 提交于 2019-11-28 14:29:07
I am making a server call in some Objective-c code. If it returns as a @"yes" , it will do an action. For some reason, the // DO ACTION HERE part is never reached. NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; NSString *returnStringResults = returnString; NSString *yesText = @"yes"; if (returnStringResults == yesText) { testLabel.text = @"Success"; // DO ACTION HERE } W Dyson if ([returnStringResults isEqualToString:yesText]) { testLabel

NSString stringWithFormat swizzled to allow missing format numbered args

拈花ヽ惹草 提交于 2019-11-28 14:23:41
Based on this SO question asked a few hours ago, I have decided to implement a swizzled method that will allow me to take a formatted NSString as the format arg into stringWithFormat , and have it not break when omitting one of the numbered arg references ( %1$@, %2$@ ) I have it working, but this is the first copy, and seeing as this method is going to be potentially called hundreds of thousands of times per app run, I need to bounce this off of some experts to see if this method has any red flags, major performance hits, or optimizations #define NUMARGS(...) (sizeof((int[]){__VA_ARGS__})

Pros and Cons of using [NSString stringWithString:@“some string”] versus @“some string”

随声附和 提交于 2019-11-28 14:11:49
I want to compare the following simple assignments: ... @property(nonatomic,retain) UITextField *textField; ... self.textField.text = @"some string"; self.textField.text = [NSString stringWithString:@"some string"]; self.textField.text = [NSString stringWithFormat:@"some string"]; Where textField is an UITextField and the text property a NSString . Of course all of them work. I know the difference of the last two when using parameters. But lets say we are only interested in this usage. QUESTIONS: For doing this kind of assignment, why shouldn't I always use the first one? Comparing the last

Authoritative description of ObjectiveC string literals? [closed]

て烟熏妆下的殇ゞ 提交于 2019-11-28 14:07:16
The Apple ObjectiveC description implies that NSStrings exist by showing examples, and that NSString literals are written as @ "<string content>" Amazingly, that's all it says, and these only show up in examples without any discussion. Is that document really the only reference document? Digging around, I found this blog which seems to have a lot of useful information. But is it right? Is there an authoritative document describing precisely what one can say (syntax) in an NSString literal, and what it means (semantics)? For instance, is the syntax of the content of a NSString literal identical

determine the maximum number of characters a UILabel can take

走远了吗. 提交于 2019-11-28 13:43:44
Given a UILabel and a NSString, how do I determine how much of the string can fit inside the UILabel? I am using Xcode-5 and iOS-7. I have been trying to see what I can extract from the thread Calculating UILabel Text Size but I am not getting anywhere with the responses there. Well, what I did here works though there may be another, more efficient (yet less straight-forward) way. What I did was just calculate the size of the rect needed for the text, see if it fits in the label's frame, and if not, chop off a character and try again. @interface LTViewController () @property (nonatomic, weak)

Obj-C: [NSString stringWithString:@“string”] vs. @“string”

旧时模样 提交于 2019-11-28 13:17:47
I've seen people do something like [NSString stringWithString:@"some string"] . Why not just do @"some string" ? For an example, look at the facebook-ios-sdk . +[NSString stringWithString:] -- what's the point? is a similar question, but none of the answers address [NSString stringWithString:@"some string"] vs. @"some string" . Actually there is no difference. [NSString stringWithString: str] just does nothing and returns str if str is immutable already. There's no difference other than the extra key strokes needed. In fact, with a constant string as a parameter (or an immutable string) you

Converting string to int changes the value

牧云@^-^@ 提交于 2019-11-28 12:52:59
问题 I'm trying to convert a string value I retrieved from an XML parser into an integer. Unfortunately, I'm finding that the integer value is not reflecting the number in the string, and I can't figure out why. Here is my code: int maxTweetID = [[[_dataArray lastObject]tweetID]intValue]; NSLog(@"String Value of tweet ID: %@",[[_dataArray lastObject]tweetID]); NSLog(@"Int Value of tweet ID: %i",[[[_dataArray lastObject]tweetID]intValue]); and here is what I'm getting from the debugger: 2012-05-15

In Objective C, what's the best way to extract multiple substrings of text around multiple patterns?

南笙酒味 提交于 2019-11-28 12:48:09
问题 For one NSString, I have N pattern strings. I'd like to extract substrings "around" the pattern matches. So, if i have "the quick brown fox jumped over the lazy dog" and my patterns are "brown" and "lazy" i would like to get "quick brown fox" and "the lazy dog." However, the substrings don't necessarily need to be delimited by whitespace. Another example would be if you had multiple paragraphs of text and wanted to find all instances of "red" and "blue" in the text, but you wanted to show the