nsstring

Parsing JSON string to a NSMutableArray

為{幸葍}努か 提交于 2019-12-12 04:53:38
问题 This is my string: [{"id":"1","nome":"Adriatik"},{"id":"2","nome":"Ard"},{"id":"3","nome":"Albana"},{"id":"4","nome":"Adriana"}] I would like to parse all 'name' of the JSON string into a NSMutableArray . Sorry for my english! 回答1: Whenever I have to handle some JSON code, the first thing I like to do is create a class based on the JSON text. So, for example if your JSON is representing a U.S. state, create a "State" class. There's a cool little product that you can use for this. It's called

NSString to NSData conversion to Hex Value [duplicate]

我的未来我决定 提交于 2019-12-12 04:41:35
问题 This question already has answers here : Converting HEX NSString To NSData (4 answers) Closed 5 years ago . I've been trying to convert a user defaults NSString (tried NSData also), into a hex value I can use with char array. the problem is that every time I convert it from the NSString or NSData it takes the hex values and turns them into ASCII values, which isn't what I want at all. how to I tell it to literally take the values that are there and keep them hex? I'm struggling to find a

Swift 3 - NSString.draw(in: rect, withAttributes:) — Text not being drawn at expected point

佐手、 提交于 2019-12-12 04:40:06
问题 Teeing off of this Stackoverflow post, which was very helpful, I've been able to successfully draw text onto a full-screen image (I'm tagging the image with pre-canned, short strings, e.g., "Trash"). However, the text isn't appearing where I want, which is centered at the exact point the user has tapped. Here's my code, based on some code from the above post but updated for Swift3 -- func addTextToImage(text: NSString, inImage: UIImage, atPoint:CGPoint) -> UIImage{ // Setup the font specific

How to replace \xA0 characters in an NSString

烂漫一生 提交于 2019-12-12 04:12:19
问题 The following code doesn't work: NSString *importText = [textView.string stringByReplacingOccurrencesOfString:@"\xA0\xA0" withString:@" "]; Compiler claims: "Input conversion stopped due to an input byte that don't belong to the input code set UTF8" 回答1: Try the Unicode escape sequence \u00a0 . 来源: https://stackoverflow.com/questions/12643955/how-to-replace-xa0-characters-in-an-nsstring

Saving location coordinates to Core data- Swift 3

老子叫甜甜 提交于 2019-12-12 03:54:00
问题 I want to save location coordinates into Core Data- what is the right way of storing these and retrieving them? At the moment I am doing this and getting errors: var newPlaceCoordinate = CLLocationCoordinate2D() var newPlaceLatitude = CLLocationDegrees() var newPlaceLongitude = CLLocationDegrees() I get my coordinates from using Google maps API using the autocomplete widget. let newPlaceCoordinate = place.coordinate self.newPlaceCoordinate = place.coordinate let newPlaceLatitude = place

Check if NSString is only letters

随声附和 提交于 2019-12-12 03:36:30
问题 What's the best way to make sure an NSString contains only the letters a-z and A-Z. I've tried the following code but it's not working for some reason: NSString *myegex = @"[A-Za-z]"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", myregex]; if (![emailTest evaluateWithObject:self.initials.text]) { // print error return; } 回答1: You can do it in a simpler way by creating your own NSCharacterSet then checking the string against that set with rangeOfCharacterFromSet

Pass NSString value to another ViewController in Objective C

℡╲_俬逩灬. 提交于 2019-12-12 03:29:31
问题 I am trying to pass NSString value to another ViewController. But I get null instead of the value. Here is my code. FirstViewController.m: NSString cellID = @"66"; SecondViewController *apiViewController = [[SecondViewController alloc] init]; apiViewController.strMessage=cellID; [self.navigationController pushViewController:apiViewController animated:YES]; SecondViewController.h: @interface SecondViewController : UIViewController{ NSString *strMessage; } @property(nonatomic,retain) NSString

Xcode: “Reference to NSString is ambiguous”

自作多情 提交于 2019-12-12 03:18:22
问题 I don't understand how such a thing can happen: I have created an Xcode project (Xcode 6) and I imported some files from a previous project (a Storyboard, the Images.xcassets file and some .h and .m files) Now when I import some of those headers in my code, each line using a NSString reports the error "Reference to NSString is ambiguous". Is this a known issue, how to solve that? 回答1: Reason: Engineering Index is broken, Rebuild index Workaround: Xcode -> Window -> Organizer -> select the

How do I compare UITextfield input to different strings?

≯℡__Kan透↙ 提交于 2019-12-12 03:04:15
问题 I want to compare the value of the input from a UITextfield to some other strings. Here's my guessing. if ([textfield.text isEqualToString:@"First" || @"Second" || @"Third"]) { // do something } Is there any better approach to this? 回答1: In a situation where you have a series of objects such as your example, you would add then to an array and test its existence in the array: Example NSMutableArray *arr = [[[NSMutableArray alloc] init] autorelease]; [arr addObject:@"First"]; [arr addObject:@

NSString Validation

孤街醉人 提交于 2019-12-12 02:47:34
问题 I need to validate some NSString that user inputs in some UITextField. There are 2 kinds of validation I need. 1st, to judge whether a NSString object is a legal decimal number. For example, @"100", @"10.1",@"0.11", are all legal, but @"100.11.1" is not. 2nd, to judge whether a NSString object is not a space-only string. For example, @"abc", @"ab----c", are all legal, but @"-----", @"", are not. here "-" means a space " ". How can I validate these 2 kinds of NSString? Thanks a lot! 回答1: For