nsstring

经营你的iOS应用日志(一):开始编写日志组件

余生颓废 提交于 2019-12-18 03:36:26
如果你去4S店修车,给小工说你的车哪天怎么样怎么样了,小工有可能会立即搬出一台电脑,插上行车电脑把日志打出来,然后告诉你你的车发生过什么故障。汽车尚且如此,何况移动互联网应用呢。 本文第一篇: 经营你的iOS应用日志(一):开始编写日志组件 言归正传。开发iOS应用,解决Crash问题始终是一个难题。Crash分为两种,一种是由EXC_BAD_ACCESS引起的,原因是访问了不属于本进程的内存地址,有可能是访问已被释放的内存;另一种是未被捕获的Objective-C异常(NSException),导致程序向自身发送了SIGABRT信号而崩溃。其实对于未捕获的Objective-C异常,我们是有办法将它记录下来的,如果日志记录得当,能够解决绝大部分崩溃的问题。这里对于UI线程与后台线程分别说明。 先看UI线程。iOS SDK提供了NSSetUncaughtExceptionHandler函数,用法如: NSSetUncaughtExceptionHandler( handleRootException ); 这样在UI线程发生未捕获异常后,进程崩溃之前,handleRootException会被执行。这个函数实现如下 static void handleRootException( NSException* exception ){ NSString* name = [

How to remove the last unicode symbol from NSString

痞子三分冷 提交于 2019-12-18 02:54:25
问题 I have implemented a custom keyboard associated with a text field, so when the user presses the delete button, I remove the last character from the string, and manually update the current text field text. NSRange range = NSMakeRange(currentTextFieldString.length-1, 1); [currentTextFieldString replaceCharactersInRange:range withString:@""]; So far so good. Now, the problem is, that the user has the option to enter some special unicode symbols, these are not 1 byte, they can be 2 bytes too, now

AFNetworking速成教程

馋奶兔 提交于 2019-12-18 01:23:43
转:http://palmsky.net/?p=4138 本文是由 iOS Tutorial 小组成员 Scott Sherwood 撰写,他是一个基于位置 动态加载( Dynamically Loaded )的 软件公司(专业的混合定位)的共同创办人。 网络 — 你的程序离开了它就不能生存下去!苹果的Foundation framework中的NSURLConnection又非常难以理解, 不过这里有一个可以使用的替代品: AFNetworking . AFNetworking 非常受开发者欢迎 – 它赢得了我们读者的青睐:2012年最佳的iOS Library奖( 2012 Best iOS Library Award .) 所以现在我就写这篇文章来向你介绍如何在程序中有效的使用它。 AFNetworking 包括了所有你需要与在线资源交互的内容,从web services到文件下载。当你的程序在下载一个大文件期间,AFNetworking还能确保你的UI是可以响应的。 本文将介绍AFNetworking框架主要的组成部分。一路上,你将使用 World Weather Online 提供的咨询(Feeds)来创建一个天气(Weather)程序。刚开始使用的天气数据是静态的,不过在学完本文内容之后,程序将连接到实时的天气咨询。 今日预计

Append string with variable

拥有回忆 提交于 2019-12-17 23:39:34
问题 I'm a java guy coming over to Objective-C. In java, to add a variable to a string you'd have to do something along the lines of: someString = "This string is equal to " + someNumber + "."; I can't figure out how to do it in Objective-C though. I have an NSMutableString that I'd like to add to the middle of a string. How do I go about doing this? I've tried: NSString *someText = @"Lorem ipsum " + someMutableString; NSString *someText = @"Lorem ipsum " + [someMutableString stringForm]; and a

What is the difference between “copy” and “retain”?

こ雲淡風輕ζ 提交于 2019-12-17 23:20:34
问题 What is the difference between copy and retain for NSString ? - (void)setString:(NSString*)newString { string = [newString copy]; } 回答1: In a general setting, retaining an object will increase its retain count by one. This will help keep the object in memory and prevent it from being blown away. What this means is that if you only hold a retained version of it, you share that copy with whomever passed it to you. Copying an object, however you do it, should create another object with duplicate

Converting int into NSString [duplicate]

心不动则不痛 提交于 2019-12-17 22:38:31
问题 This question already has answers here : How can I convert an int to an NSString? (4 answers) Closed 5 years ago . I want to convert a random int number in the NSString and then assign the NSString to another NSString but it crashes the app I am doing the following int mynumber =(arc4random() % 1000 ); unique = [NSString stringWithFormat:@"%d",mynumber]; NSLog(unique) NSString*test=unique; it gives crash when i write last line; It also prints values when I nslog the unique string. 回答1: If you

String search in string array in objective c

独自空忆成欢 提交于 2019-12-17 21:43:40
问题 I want to search a specific string in the array of strings in objective c. Can somebody help me in this regard? 回答1: BOOL isTheObjectThere = [myArray containsObject: @"my string"]; or if you need to know where it is NSUInteger indexOfTheObject = [myArray indexOfObject: @"my string"]; I strongly recommend you read the documentation on NSArray. It's best to do that before posting your question :-) 回答2: You can use NSPredicate class for searching strings in array of strings. See the below sample

Passing NSString value between classes

╄→гoц情女王★ 提交于 2019-12-17 21:23:37
问题 I have been looking long for a solution how to pass the value from one class to another. Basically I create a NSString via @property in a Settings class, which is displayed modally. I then set the NSString to a certain value depending on the settings chosen, and I want to have the value shown also in a class where the settings are supposed to make change. I also declare a string via @property in the second class, and I use the code myController *controller = [[myController alloc] init];

i have NSString value in addViewController and i want to display this value in UILabel of DetailsViewController

谁说胖子不能爱 提交于 2019-12-17 21:23:17
问题 I am newbie to programming. Any help could be greatly appreciated. It's in AddViewController. NSLog(@"Am Currently at %@",locatedAt); DetailsOfPeopleViewController *details=[DetailsOfPeopleViewController alloc]; details.testAddressStr=[NSString stringWithFormat:@"%@",locatedAt]; details.testAddressStr is displaying the value here, but it's not passing this value to DetailsViewController. The value of locatedAt is displaying in the AddViewController. When I try to display this value in UILabel

Pros and Cons of using [NSString stringWithString:@“some string”] versus @“some string”

爷,独闯天下 提交于 2019-12-17 21:13:30
问题 I want to compare the following simple assignments: ... @property(nonatomic,retain) UITextField *textField; ... self.textField.text = @"some string"; self.textField.text = [NSString stringWithString:@"some string"]; self.textField.text = [NSString stringWithFormat:@"some string"]; Where textField is an UITextField and the text property a NSString . Of course all of them work. I know the difference of the last two when using parameters. But lets say we are only interested in this usage.