nsstring

App Crash with exc_bad_access code Exception

柔情痞子 提交于 2019-12-11 07:40:38
问题 Let me introduce my functionality of App,I use push notification & addressbook and CoreTelephony Framework. What I am doing in my application is , When i get Push notification, I save the number from the Payload in a Appdelegate Variable(Incoming_NO) , if there is no Such contact with this number , Ill create the new contact and save it. When i receive the Call , the same contact name appears as i added before , Later on I am allowing the user to Edit the Contact if he want to save the

NSString overflows its buffer and app crashed. Debugger doesn't see any stack trace information. But why?

戏子无情 提交于 2019-12-11 07:39:18
问题 I spent a lot of time to find out why my app crashed. My count variable doesn't properly initialized in some cases. NSString overflows its buffer and app crashed. Debugger doesn't see any stack trace information. But why? int count = 2147483647; NSString *lines = @""; for(int i = 0; i < count; i ++) { lines = [NSString stringWithFormat:@"%@%@", lines, @"\n"]; } UPDATE: Why doesn't debugger show any stack trace information? 回答1: You're not only creating long strings, you're creating lots of

Measure size of each char in an NSString

人盡茶涼 提交于 2019-12-11 07:35:38
问题 We have [NSString sizeWithFont:] which returns the size of the entire string. What about getting an array of the sizes of each individual character within the string? How would you do that (besides tokenizing the string and calling sizeWithFont for each)? Best, Vance 回答1: You should be able to get size information about individual glyphs (note though that those don't always map one-to-one with individual characters in a string) by using the Core Graphics function CGFontGetGlyphBBoxes . 来源:

Getting weird characters when going from NSString to bytes and then back to NSString

吃可爱长大的小学妹 提交于 2019-12-11 07:16:40
问题 NSString *message = @"testing"; NSUInteger dataLength = [message lengthOfBytesUsingEncoding:NSUnicodeStringEncoding]; void *byteData = malloc( dataLength ); NSRange range = NSMakeRange(0, [message length]); NSUInteger actualLength = 0; NSRange remain; BOOL result = [message getBytes:byteData maxLength:dataLength usedLength:&actualLength encoding:NSUnicodeStringEncoding options:0 range:range remainingRange:&remain]; NSString *decodedString = [[NSString alloc] initWithBytes:byteData length

SQLite MYSQL character encoding

早过忘川 提交于 2019-12-11 07:02:04
问题 I have a strange situation where the following code works however XCode warns it is deprecated... NSString *col1 = [NSString stringWithCString:(char *)sqlite3_column_text(compiledStatement, 0)]; However as that is the deprecated method if I set an encoding the string comes out wrong! I have tried all the encodings but none work! NSString *col1 = [NSString stringWithCString:(char *)sqlite3_column_text(compiledStatement, 0) encoding:NSASCIIStringEncoding]; 回答1: I would have expected satire's

How can I add leading whitespace in front of the NSString?

时光毁灭记忆、已成空白 提交于 2019-12-11 07:01:03
问题 I need the String always have length 5... for example, if I pass hello" , I get "hello" I pass "xml" , I get " xml" (two spaces before "xml"); I pass "i" , I get " i" (four spaces before "i"). What is the most efficient way to do it? Thank you. 回答1: NSMutableString *yourString;//your string NSMutableString *string; if([string length]<5){ NSInteger length = 5-[string length]; for(int i=0;i<length;i++){ [string appendFormat:@" "]; } [yourString appendString:string]; } //now you can use

how can I convert NSArray into specific String?

不想你离开。 提交于 2019-12-11 06:56:31
问题 I'm using facebook-api to fetch user's friends. The code is as follows: let params = ["fields": "id"] let request = FBSDKGraphRequest(graphPath: "me/friends", parameters: params) request.startWithCompletionHandler { (connection : FBSDKGraphRequestConnection!, result : AnyObject!, error : NSError!) -> Void in if error != nil { let errorMessage = error.localizedDescription print(errorMessage) /* Handle error */ } else if result.isKindOfClass(NSDictionary){ /* handle response */ let defaults =

NSString returns empty from a return method

非 Y 不嫁゛ 提交于 2019-12-11 06:46:52
问题 I have an unusual issue and I can't figure out why: I have the following method: - (NSString*) copyAndReplaceOccurencesForProfileFromString: (NSString*)initialString toString:(NSString*)aString { aString = [NSString stringWithString:initialString]; DLog(@"PROFILE INITIAL HTML STRING: %@", initialString); aString = [aString stringByReplacingOccurrencesOfString:@"//PROFILE_IMAGE//" withString:profileImageForHTML]; aString = [aString stringByReplacingOccurrencesOfString:@"//PROFILE_NAME//"

Why is [NSString hash] device dependent?

纵饮孤独 提交于 2019-12-11 05:08:53
问题 I was not expecting that hash on NSString returns differently depending on the target device. NSLog(@"%lu", (unsigned long)[@"test" hash]); // 38178019076 on my iPad. // 3818280708 on my iPhone and (iPhone/iPad-)Simulator. Apart from the fact that hash on NSString should be used with care (hash is bad with NSString) and this problem can easily be solved using a real hash (e.g. sha), I am interested why different results are returned? 回答1: The NSObject protocol hash method returns an

Can't get russian letters in EXIF

喜你入骨 提交于 2019-12-11 04:56:16
问题 example 1 - it works NSString *first = @"Russian letters(Русские буквы)"; [exifDictionary setValue:first forKey:(NSString*)kCGImagePropertyExifUserComment]; example 2 - doesn't work NSString *rus = @"Русские буквы"; NSString *first; first = [[NSString alloc] initWithFormat:@"Russian letters(%@)",rus]; [exifDictionary setValue:first forKey:(NSString*)kCGImagePropertyExifUserComment]; In second case in EXIF write "Russian letters(??????? ?????)" if NSString contains parameter its happens. how