nsstring

iOS - setting text of UITextView throws EXC_BAD_ACCESS

…衆ロ難τιáo~ 提交于 2019-12-11 11:52:33
问题 I have a UITextView which I have created programmatically in the following code: NSLog(@"creating the first blurb"); blurb = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; [blurb setText:total]; blurb.backgroundColor = [UIColor redColor]; where blurb is defined as a UITextView in the @interface . Here's where I'm having the problem: total is an NSString that is defined to get the text from a .txt file from a specified domain. It is mutated as: NSString *url = @"https://sites

Find and Replace all within nsstring

江枫思渺然 提交于 2019-12-11 11:08:38
问题 I am trying to find list of words , if matches i am replacing. the blow code works but it is not replacing if the matching word occurs more than one time. And i think i need to use while instead of if loop here , but i am not able to make it to work. I am struggling Please let me know NSString *mymessage = @"for you for your information at you your at fate"; NSMutableArray *full_text_list = [[NSMutableArray alloc]init]; [full_text_list addObject:@"for"]; [full_text_list addObject:@"for your

IOS-获取Model(设备型号)、Version(设备版本号)、app(程序版本号)等

我怕爱的太早我们不能终老 提交于 2019-12-11 11:08:14
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> // app 名称 NSString *app_Name1 = [[ NSBundle mainBundle ] objectForInfoDictionaryKey : @"CFBundleDisplayName" ]; NSString *app_Name = [ NSString stringWithFormat : @"%@" ,[[ NSBundle mainBundle ] objectForInfoDictionaryKey :( NSString *) kCFBundleNameKey ]]; NSString *app_Name2 = [ NSString stringWithFormat : @"%@" ,[[ NSBundle mainBundle ] objectForInfoDictionaryKey :( NSString *) kCFBundleExecutableKey ]]; NSLog ( @"==============1%@-----%@---%@" ,app_Name1,app_Name,app_Name2); // app 版本 NSString *app_Version1 = [ NSString stringWithFormat : @"v%@" , [[

Replace character in string

南笙酒味 提交于 2019-12-11 11:01:58
问题 I have a NSMutableString @"hello" . I'd like to replace the character at the second position, 'e' with 'a' so that it reads @"hallo" . How do I do that? I have tried this to implement a Shift Cipher, but it throws an IndexOutBoundsException - (NSString*)encode:(NSString*)original withShift:(int)shift { NSMutableString* encoded = [NSMutableString stringWithString:original]; for (int i=0; i < [encoded length]; i++) { char oriChar = [encoded characterAtIndex:i]; if (oriChar == ' ') { continue; }

How to get the name of a UIColor?

淺唱寂寞╮ 提交于 2019-12-11 10:25:49
问题 I have an array of UIColors like [UIColor blueColor]; is it possible to get the name "blue" from that UIColor, to display it in a string? 回答1: There's nothing built in to UIKit, but Erica Sadun's uicolor-utilities library adds similar functionality. 回答2: You can get RGB and Alpha of the UIColor, if you want. 回答3: A list of color names can be obtained using runtime . See my question: How to get all Color methods of UIColor? You can also use string methods to convert 'xxxColor' to 'xxx' if

CFStringRef to NSString ARC leaking. Why?

孤人 提交于 2019-12-11 09:56:50
问题 I have been looking around for the correct way to go from CFStringRef to NSString in ARC to avoid memory leaks and some of the main voted answers suggest: NSString * string = (__bridge NSString *)cfString; I am using that approach here but when profiling the app I still get a memory leak in this small method [see attached image]. So, I am not sure how to fix this. Anybody has the solution to this problem? Thank you So, apparently adding the CFRelease(ext) before the return fixed the leak.

Objective-C gzipped NSData to Python gzipped string?

一曲冷凌霜 提交于 2019-12-11 09:46:51
问题 I'm using +[NSData gtm_dataByGzippingData:] to gzip the UTF-8 encoded data returned by +[NSJSONSerialization dataWithJSONObject:options:error:] . How do I convert this gzipped NSData to a string that I can send as a parameter to a Python server so that the server can decompress it with zlib.decompress()? 回答1: Use a method like -[NSData base64EncodedString] to base64-encode the gzipped NSData before you send it to the Python server. Then, the Python server can base64-decode it and then unzip

NSTextView making bold text using an array

心已入冬 提交于 2019-12-11 09:42:45
问题 I have an array which has the following structure: ( [0] = ( [0] = @"Title string" [1] = @"Some content string" ) [1] = ( [0] = @"Title string" [1] = @"Some content string" ) [2] = ( [0] = @"Title string" [1] = @"Some content string" ) ... ) and so on and so fourth to a variating amount of reoccurrence. My goal is to try and merge it all into one single string to display in an NSTextField, and make every title string bold. So the code above would look something like this if it were outputted.

How Objective-C handles the memory of immutable strings [duplicate]

可紊 提交于 2019-12-11 09:38:53
问题 This question already has answers here : Do I need to release a constant NSString? (2 answers) Closed 6 years ago . In my research I've come across something peculiar. @interface Class { NSString *_string } - (void) Method1 { _string = @"ASDF"; } Intially I thought that _string was part of the autorelease pools and really didn't think about the memory aspect of it. After reading this SO post Objective C NSString* property retain count oddity I've realized that no, this is not the case, and

How to find out when UILabel wordwraps

只谈情不闲聊 提交于 2019-12-11 09:07:02
问题 I have created a couple of different UITableViewCell s for my tableViewController , this is because I have different bits of data I want to display depending what comes back. Because of this each UITableViewCell is of a different height. This is all fine, However one of my UILabel s has to display a large NSString , so large that I have had to word wrap it onto a second line, The only issue here is that it messes up my UITableViewCell formatting. My question is, is it possible to flag or