nsstring

Swift: Parsing Json string and populating information into a dictionary

ⅰ亾dé卋堺 提交于 2019-12-13 05:43:31
问题 I'm currently learning about web services in Swift. I have this URL that shows recent earthquakes and other information regarding it. The code at the bottom is what I have so far, once I run it, it NSLogs a string in JSON format from the URL. Here are 3 records I have from the string. How do I parse this JSON string and take out the ID, title, and populate that information into a dictionary? html = [ { "response":1, "message":"OK", "count":50 }, { "id":133813, "title":"M 1.4 - 8km NE of

Replace Emoticons

余生颓废 提交于 2019-12-13 04:38:29
问题 Is it possible to replace a word with emoticons? For example NSString *myString = @"I am sad of him" now i want to check the word whether it contains the word "sad", if it has i want to replace that word with sad emoticons. I am not sure how to have emoticons in the nsstring Please let me know 回答1: yeah, you can do this using this: myString = [NSString stringByReplacingOccurrencesOfString:@"sad" withString:@"\ue058"]; Check this link for emoji codes: (replace the &#x with \u though) http:/

Objective-C: Comparing user input with object's instance variable

断了今生、忘了曾经 提交于 2019-12-13 04:32:07
问题 I have been learning Objective-C for a while, and I decided to try and take on a little bigger project without any real "guidelines" as in the learning books but now I have got stuck. What I'm trying to do is helping a friend digitalising a few documents he have, by creating a searchable commandline-tool for these documents. I think I have gotten pretty far, I have created a custom class for documents with three variable; name of the author, number of the article and the path to the file on

isEqualToString not returning true

╄→尐↘猪︶ㄣ 提交于 2019-12-13 04:25:59
问题 The "Stopping" statement never gets printed even if you type 'stop' when running the program. Is the initWithUTF8String: method introducing extra formatting? int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; char holderText[256]; fgets(holderText, 256, stdin); NSString *words = [[NSString alloc] initWithUTF8String:holderText]; if ([words isEqualToString:@"stop"]) { NSLog(@"STOPPING"); } NSLog(@"This is what you typed: %@", words); [pool

Find all locations of substring in NSString (not just first)

亡梦爱人 提交于 2019-12-13 04:22:23
问题 There is a substring that occurs in a string several times. I use rangeOfString , but it seems that it can only find the first location. How can I find all the locations of the substring? NSString *subString1 = @"</content>"; NSString *subString2 = @"--\n"; NSRange range1 = [newresults rangeOfString:subString1]; NSRange range2 = [newresults rangeOfString:subString2]; int location1 = range1.location; int location2 = range2.location; NSLog(@"%i",location1); NSLog(@"%i",location2); 回答1: You can

score label display value overwrites

筅森魡賤 提交于 2019-12-13 04:00:50
问题 When THE score updates, a new score value label overwrites old one on the display, because of this score is just unreadable, how to update new score? here what i got: SKLabelNode *ScoreLabel; NSInteger score = 0; ----------------------------- -(void)Scoring{ score = score +1; ScoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Arial"]; ScoreLabel.position = CGPointMake(CGRectGetMidX(self.frame), 960); ScoreLabel.text = [NSString stringWithFormat:@"%ld",(long)score]; [self addChild:ScoreLabel];

ios convert NSString with special chars to const char

自作多情 提交于 2019-12-13 03:53:37
问题 i m trying to draw a string with CGContextShowTextAtPoint. CGContextShowTextAtPoint only accepts "const char" as a string input. my problem is that some of the strings have special chars like ä,ö,ü etc in them. if i convert this strings to a "const char" NSString *label = @"Küche"; const char *charLabel = [label UTF8String]; i get a strange output, where the ü is replaced with signs and boxes... what to do? 回答1: You can draw only ASCII characters with CGContextShowTextAtPoint . To draw

stringbyappendingstring different size and font types

泄露秘密 提交于 2019-12-13 03:43:19
问题 I have a NSString that is a letter and another that is their signature. I need to combine both into a single string for display but the signature needs to display in a different font and size. Yes, both fonts and sizes are working on their own. Right now I have it as follows: NSString *letter; NSString *signOff; _paragraph.font = [UIFont fontWithName:@"BeinetCondensed" size:14]; _signature.font = [UIFont fontWithName:@"AnnoyingKettle" size:18]; letter = [_paragraph text]; signOff = [

localizedCaseInsensitiveContainsString not available in Swift

故事扮演 提交于 2019-12-13 01:44:54
问题 I'm trying to use localizedCaseInsensitiveContainsString() method introduced in iOS 8: let match = text.localizedCaseInsensitiveContainsString(searchText) Swift compiler says: 'String' does not have a member named 'localizedCaseInsensitiveContainsString' Documentation says: Swift automatically bridges between the String type and the NSString class. So, what's going on here? I know I can use (title as NSString) . I just want to know why. 回答1: I think you still need to cast it to not confuse

What's the difference between (null) vs <null>?

落花浮王杯 提交于 2019-12-13 01:43:44
问题 I was getting random crashes in my app until I narrowed it down to a particular method. In that method I expect an NSString as a parameter. This NSString can sometimes be nil in which case the method ends and no harm is done. When I run my method's parameter through NSLog(@"%@", myString) I found that I get one of these: The contents of an actual NSString (null) <null> The first two are expected and handled by my method. The third one, <null> , crashes my app with -[NSNull length]: