nsstring

Objective C NSString problem

六眼飞鱼酱① 提交于 2019-12-04 17:13:53
I have a NSString that I need to examine character by character and: examine char perform calculation loop (until string ends) Any thoughts on the best way to do this? Do I need to convert the NSString to a NSArray or C string? The simplest way to go about it is using NSString 's characterAtIndex: method: int charIndex; for (charIndex = 0; charIndex < [myString length]; charIndex++) { unichar testChar = [myString characterAtIndex:charIndex]; //... your code here } -characterAtIndex: is the simplest approach, but the best is to drop down to CFString and use a CFStringInlineBuffer, as in this

How does localizedStringWithFormat work?

◇◆丶佛笑我妖孽 提交于 2019-12-04 17:12:11
问题 Please note I am not asking about NSLocalizedString() the macro. I am asking about the NSString class function + (instancetype)localizedStringWithFormat:(NSString *)format, ... . These are two separate things. Question I'm trying to use the NSString class method localizedStringWithFormat but I just can't work out how I'm supposed to use it. Whatever I try I don't seem to get the words to appear in the translation file using Xcode 6 export for localization . I've tried the top two variations

Remove all duplicate characters from NSString

十年热恋 提交于 2019-12-04 16:44:01
How to do this using standard methods (without manual iteration through source string)? PS: At final I want to get sorted characters of source string. I tried to use NSCharacterSet , but can't find a method to convert character set to string (without iterating the set). There is no built-in method for this, but it's pretty easy to iterate over the characters of the string and build a new string without duplicates: NSString *input = @"addbcddaa"; NSMutableSet *seenCharacters = [NSMutableSet set]; NSMutableString *result = [NSMutableString string]; [input enumerateSubstringsInRange:NSMakeRange(0

How to validate the empty string in Objective C?

倾然丶 夕夏残阳落幕 提交于 2019-12-04 16:42:56
I want to validate the string value after getting in the below parser delegate method I have tried like [string length]>0 ,(string !=NULL) in if condition still blank string is printed in the NSlog.So what is the efficient method to validate the sting.I have used the below code. - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if ([elemName isEqualToString:@"productName"]) { if (!prodStringValue) { prodStringValue = [[NSMutableString alloc] initWithCapacity:50]; } [prodStringValue appendString:string]; if(prodStringValue && [prodStringValue length]>0 &&

NSLog outputs unicode characters as garbage when debugging on the iPhone

落花浮王杯 提交于 2019-12-04 16:25:51
问题 EDIT: NSLog output works well in the simulator, but doesn't work when connected to a real device. And it seems that it is a bug — http://openradar.appspot.com/11148883. Also it happens that it is related to the LLDB, switching Xcode to GDB resolves the problem. Either it's possible to JetBrain's AppCode, which works well with the LLDB. I have a bunch of unicode strings in the application, and if I try to output any of those strings using something like NSLog(@"%@", aString) then all the ASCII

Hybrid App: 对比UIWebView和WebKit实现JavaScript与Native交互

こ雲淡風輕ζ 提交于 2019-12-04 16:06:01
一、简介 在前面一篇文章中讲到过实现JavaScript与Native交互的方式有一种就是使用原生内嵌webView。在iOS8之前,开发者只能使用苹果提供的UIWebView类来加载URL或者HTML网页视图,然后通过设置代理,在回调函数中拦截并处理自定义交互事件,功能十分有限,通常只是作为一个辅助视图使用。在iOS8之后,苹果对这方面的技术进行了重构和优化,推出了一个新的框架WebKit。WebKit提供了Native与JavaScript交互的方法,整个框架的结构很清晰,对外暴露的接口友好实用,极大地方便了开发者实现网页视图和的Native交互。并且,WebKit框架采用导航堆栈的模式来管理网页视图的跳转,对于网页视图的管理和渲染,开发者更加容易管控。慢慢地,咱来比较这两种webView的使用区别。 二、UIWebView 1、UIWebView的详细构成 UIWebView的类构成之:属性 //id类型,遵守UIWebViewDelegate协议 @property (nullable, nonatomic, assign) id <UIWebViewDelegate> delegate //只读属性,webView内部的滚动视图 @property (nonatomic, readonly, strong) UIScrollView *scrollView //只读属性

How to strip special characters out of string?

家住魔仙堡 提交于 2019-12-04 15:27:10
I have a set with the characters I allow in my string: var characterSet:NSCharacterSet = NSCharacterSet(charactersInString: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ") I want to strip any other characters from a string so two unformatted data can be considered equal, like this: "American Samoa".lowercaseString == "american_samoa1".lowercaseString the lowercase version of these transformed strings would be "americansamoa" mustafa Let's write a function for that (in swift 1.2). func stripOutUnwantedCharactersFromText(text: String, set characterSet: Set<Character>) -> String { return

iOS开发一些细节

和自甴很熟 提交于 2019-12-04 15:25:46
block 的注意事项 使用 copy 修饰属性 想不循环应用,那么在 block 外面这样声明 __weak __typeof(self)weakSelf = self; 接着,在 block 里面这样 __strong __typeof(weakSelf)strongSelf = weakSelf; 这样既防止循环应用,又避免 block 内部 self 会无效的可能 AFNetworking 里面这样使用的很多 UITableView 的优化 最基本的,cell 重用机制,如果这个都不知道的话,那可以去撞墙了。。。 异步加载数据,这个也是很基本的 自动载入更新数据,比如每次载入20条信息,然后在滚动到最后5条信息,就加载更多的信息 图片下载完成以后,判断 cell 如果是可见的,那么就需要更新图像 GCD 异步请求,我只认准 GCD | GCD异步,你值得拥有 (广告先走一波) 网络请求放在子线程,UI 只能在主线程更新 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { // 处理各种耗时间的事情,比如网络请求数据,天知道要什么时候才能结束 dispatch_async(dispatch_get_main_queue(), ^(void) { //

Limiting NSString to numbers as well as # if chars entered. (code included)

走远了吗. 提交于 2019-12-04 15:22:09
I have searched the site for my answer, however I think it is also how I got myself into this problem. I'm trying to limit my 1 and only text field to 10 characters and only numbers. Below is code mostly off other questions on this site. What I am trying to do is mash this code together for my limits - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:LEGAL] invertedSet]; NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]

iPhone: find one string in another with case insensetive

£可爱£侵袭症+ 提交于 2019-12-04 15:14:44
问题 My question is similar to How do I check if a string contains another string in Objective-C? How can I check if a string (NSString) contains another smaller string but with ignoring case? NSString *string = @"hello bla bla"; I was hoping for something like: NSLog(@"%d",[string containsSubstring:@"BLA"]); Anyway is there any way to find if a string contains another string with ignore case ? But please do not convert both strings to UpperCase or to LowerCase. 回答1: As similar to the answer