天道酬勤,学无止境

nsstring

stringByAppendingFormat not working

I have an NSString and fail to apply the following statement: NSString *myString = @"some text"; [myString stringByAppendingFormat:@"some text = %d", 3]; no log or error, the string just doesn't get changed. I already tried with NSString (as documented) and NSMutableString. any clues most welcome.

2021-06-13 13:53:42    分类:问答    objective-c   nsstring   string-concatenation

Confused by NSStringDrawingOptions item meaning

iOS7 and later, we can use - (void)drawWithRect:(CGRect)rect options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context to calculate the string size, but I'm confused with the comments on NSStringDrawingOptions enum. NSStringDrawingUsesLineFragmentOrigin It means specified origin is the line fragment origin, not the base line origin. But what mean of line fragment origin and baseline origin. Just like the WWDC 2013 Session 220 (Advanced Text Layouts and Effects with Text Kit) PDF on Page 95. If line fragment origin mean the blue dot

2021-06-13 12:37:58    分类:问答    ios   nsstring   nsattributedstring   textkit

Why is this program faster in Python than Objective-C?

I got interested in this small example of an algorithm in Python for looping through a large word list. I am writing a few "tools" that will allow my to slice a Objective-C string or array in a similar fashion as Python. Specifically, this elegant solution caught my attention for executing very quickly and it uses a string slice as a key element of the algorithm. Try and solve this without a slice! I have reproduced my local version using the Moby word list below. You can use /usr/share/dict/words if you do not feel like downloading Moby. The source is just a large dictionary-like list of

2021-06-13 05:59:51    分类:问答    python   objective-c   nsstring

how to convert this string to json or dictionary in ios

I tired with links but those are not working in my case. Can anyone suggest me on how to convert this string to json or dictionary. This string is having a dictionary with an array of strings. NSString *temp=@"{\n name = {\n dob = \"\";\n age = \"61\";\n family = (\n {\n location = location;\n mobile = mobile;\n }\n );\n };\n}"; Here family is an array.

2021-06-13 02:30:45    分类:问答    ios   objective-c   json   nsstring

iPhone dev: Replace uppercase characters in NSString with space and downcase

I have: NSString *promise = @"thereAreOtherWorldsThanThese"; which I'm trying to transform into the string: @"There are other worlds than these" I'm guessing this is a regex job, but I'm very new to Objective C, and have so far had no luck. I would greatly appreciate any help!

2021-06-12 19:58:17    分类:问答    iphone   regex   string   replace   nsstring

我如何通过苹果实现集群模式中的行为(NSString 和 NSCFString)(How can i implement the behaviour as in cluster pattern by apple (NSString and NSCFString))

问题 我只是为了测试目的编写以下代码: NSString *aStr = [[NSString alloc] initWithFormat:@"Foo"]; aStr = [aStr initWithFormat:@"Bar"];//Crashed here 我收到以下错误: *** initialization method -initWithFormat:locale:arguments: cannot be sent to an abstract object of class __NSCFString: Create a concrete instance! 如果我写下面的代码同样的事情发生 NSString *aStr = [NSString alloc]; aStr = [aStr initWithFormat:@"Foo"]; aStr = [aStr initWithFormat:@"Bar"]; //Crashed here 通过谷歌我开始知道initWithFormat将返回NSCFString对象。 我的问题是,如果NSCFString是NSString派生类,那么为什么我不能在NSCFString上调用initWithFormat方法。 如果可以停止可见性,我该如何在代码中实现。 回答1 让我们调查一下NSString类集群内部是如何工作的:

2021-06-12 17:22:14    分类:技术分享    ios   objective-c   nsstring

Passing NSString from one view to another view

I have 2 views that are sharing the same class files (.h and .m). In the first view, I have a UIPicker with a list of items and a button. If the user clicks the button, I want my second view to come up with the appropriate Picture (based on the item that was selected in the UIPicker). My thinking was to set an NSString in the first view based on the selected item. Then when the user clicks the button to push the second view onto the screen, i could pass that string with the new view. I've been "googling" for awhile but I can't seem to wrap my finger around it. If it matters, I am using a

2021-06-12 16:11:48    分类:问答    iphone   variables   uinavigationcontroller   nsstring

Superscripted ordinal suffix in NSString

Is there a way in NSString to output the st, nd, and rd but in a superscripted format? Any known unicode perhaps?

2021-06-12 15:37:39    分类:问答    cocoa-touch   ios   unicode   nsstring

Autocompletion using UITextView should change text in range

I followed Ray Wenderlich's tutorial on text autocompletion here: http://www.raywenderlich.com/336/how-to-auto-complete-with-custom-values And it works great, but it only allows searching for a string that is contained in the textView. I need it to search for multiple strings in the same view. For example: Hi @user, how's @steve Should search for both occurrences of the @. Here is the original code: - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { autocompleteTableView.hidden = NO; NSString *substring = [NSString

2021-06-12 12:21:39    分类:问答    objective-c   cocoa-touch   nsstring

将 NSDecimalNumber 转换为 NSString(Converting NSDecimalNumber to NSString)

问题 我正在从如下所示的对象中检索密钥: po obj { TypeID = 3; TypeName = Asset; } 正在检索键值,如下所示: NSString *typeId = (NSString*)[obj objectForKey:@"TypeID"]; typeId 不是 NSString,而是 NSDecimalNumber。 这是为什么? 如何将其转换为 NSString? 回答1 您需要使用stringWithFormat函数: NSString *typeId = [NSString stringWithFormat:@"%@", [obj objectForKey:@"TypeID"]]; 或stringValue : NSString *typeId = [[obj objectForKey:@"TypeID"] stringValue]; 回答2 这应该有效: NSString *typeId = [[obj objectForKey:@"TypeID"] stringValue]; 回答3 如果您想获取字符串值,只需使用“描述”。 即使返回类型是 NSDecimalNumber、NSString 或其他类型,它也能正常工作: NSString *typeId = [[obj objectForKey:@"TypeID"] description]

2021-06-12 11:29:38    分类:技术分享    objective-c   ios   cocoa-touch   nsstring   nsdecimalnumber