nsstring

iOS - GData解析XML 数据

匿名 (未验证) 提交于 2019-12-02 23:49:02
string数据 NSError *error = nil; GDataXMLDocument *doc = [[GDataXMLDocument alloc]initWithData:[responseObject mj_JSONData] error:&error]; GDataXMLElement *rootElem = [doc rootElement]; NSLog(@" children %@ ",rootElem.children); NSLog(@" childCount %lu ",(unsigned long)rootElem.childCount); /* 打印的数据 children ( "GDataXMLElement 0x600001d3bab0: {type:1 name:string xml:\"<string>1111.pdf</string>\"}", "GDataXMLElement 0x600001d3bae0: {type:1 name:string xml:\"<string2>2222.pdf</string2>\"}" ) */ NSMutableDictionary *mDic = [NSMutableDictionary new]; for (GDataXMLElement *pointElement in rootElem

iOS之对象销毁

匿名 (未验证) 提交于 2019-12-02 23:40:02
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Batac_Lee/article/details/91454051 这是我查看了iOS源码之后,在结合这篇文章 黑幕背后的Autorelease 而总结出来的知识,在此向这位大神学习了。 AutoReleasePool自动释放池,一般理解就是自动帮OC对象添加release操作,一般涉及的问题有AutoRelease实现原理,什么时候释放,以及怎么释放的问题。 写个示例代码触发AutoReleasePool @autoreleasepool{ NSString *strTest = [NSString stringWithFormat:@"test%i", 100]; // 这里必须要拼接字符串,不然系统会编译成常量字符串,那就不受AutoReleasePool操作了 } 那么会编译成: NSAutoReleasePool *pool = [[NSAutoReleasePool alloc] init]; NSString *strTest = [NSString stringWithFormat:@"test%i", 100]; // stringWithFormat里面也会调用autorelease,所以strTest这里不用调用autorelease [pool drain];

Create a Custom Formatted Dictionary Array from CSV File of Data

ぐ巨炮叔叔 提交于 2019-12-02 23:39:29
问题 I've created an iPhone app that has a dictionary array of locations (lat,long,point). I created the array by manually entering each value. myLocationArray = @[ @{ kStation : @"1", kLatitude : @( 41.656467), kLongitude : @(-81.277963) }, @{ kStation : @"2", kLatitude : @(41.657118), kLongitude : @(-81.276545) }, @{ kStation : @"3", kLatitude : @(41.658493), kLongitude : @(-81.273542) }, ... This is good and works but now I want to create this array programmatically by getting the data from a

iOS中几种数据持久化方案:我要永远地记住你!

十年热恋 提交于 2019-12-02 22:13:45
作者: @翁呀伟呀 授权本站转载 概论 所谓的持久化,就是将数据保存到硬盘中,使得在应用程序或机器重启后可以继续访问之前保存的数据。在iOS开发中,有很多数据持久化的方案,接下来我将尝试着介绍一下5种方案: plist文件(属性列表) preference(偏好设置) NSKeyedArchiver(归档) SQLite 3 CoreData 沙盒 在介绍各种存储方法之前,有必要说明以下沙盒机制。iOS程序默认情况下只能访问程序自己的目录,这个目录被称为“沙盒”。 1.结构 既然沙盒就是一个文件夹,那就看看里面有什么吧。沙盒的目录结构如下: 1 2 3 4 5 6 "应用程序包" Documents Library Caches Preferences tmp 2.目录特性 虽然沙盒中有这么多文件夹,但是没有文件夹都不尽相同,都有各自的特性。所以在选择存放目录时,一定要认真选择适合的目录。 "应用程序包": 这里面存放的是应用程序的源文件,包括资源文件和可执行文件。 1 2 NSString *path = [[NSBundle mainBundle] bundlePath]; NSLog(@"%@", path); Documents: 最常用的目录,iTunes同步该应用时会同步此文件夹中的内容,适合存储重要数据。 1 2 NSString *path =

Use NSString variable created in viewDidLoad inside another method

拟墨画扇 提交于 2019-12-02 22:09:17
问题 In my viewDidLoad method, I set the following variables: // Get requested URL and set to variable currentURL NSString *currentURL = self.URL.absoluteString; //NSString *currentURL = mainWebView.request.URL.absoluteString; NSLog(@"Current url:%@", currentURL); //Get PDF file name NSArray *urlArray = [currentURL componentsSeparatedByString:@"/"]; NSString *fullDocumentName = [urlArray lastObject]; NSLog(@"Full doc name:%@", fullDocumentName); //Get PDF file name without ".pdf" NSArray *docName

Replace last comma in string with an “and”. (Objective-C)

主宰稳场 提交于 2019-12-02 22:04:40
I'm looking for a good way in Objective-C to replace the last comma in a string with the word "and". Any suggestions? "Red, Green, Blue, Yellow" becomes "Red, Green, Blue and Yellow" NSString *str = @"...."; NSRange lastComma = [str rangeOfString:@"," options:NSBackwardsSearch]; if(lastComma.location != NSNotFound) { str = [str stringByReplacingCharactersInRange:lastComma withString: @" and"]; } 来源: https://stackoverflow.com/questions/5614588/replace-last-comma-in-string-with-an-and-objective-c

Concatenate number with string in Swift

孤人 提交于 2019-12-02 21:38:05
I need to concatenate a String and Int as below: let myVariable: Int = 8 return "first " + myVariable But it does not compile, with the error: Binary operator '+' cannot be applied to operands of type 'String' and 'Int' What is the proper way to concatenate a String + Int? If you want to put a number inside a string, you can just use String Interpolation : return "first \(myVariable)" H. Mahida You have TWO options; return "first " + String(myVariable) or return "first \(myVariable)" CW0007007 To add an Int to a String you can do: return "first \(myVariable)" If you're doing a lot of it,

Transfer NSString between two devices via bluetooth in iOS

牧云@^-^@ 提交于 2019-12-02 21:22:07
I want to transfer NSString between two iOS device, via bluetooth. Can anybody please help how to do transfer NSString via bluetooth? I searched for specific answer and for sample code, but couldn't find it. Please guide me. Thanks in Advance.!! I'm going to comment more extensively on how you can use MCSession for this sort of simple case since when I was first familiarizing myself with MCSession , I was amazed at how little information was available on how to utilize a simple MCSession without adding the extra layer of an MCBrowserViewController . In your .h, add the following delegates:

NSString property copy or readonly?

不羁的心 提交于 2019-12-02 21:19:31
I see many discussions saying that I should use copy for NSString property because it will prevent others from changing it behind my back. But then why don't we just set readonly property for it? Update Thanks for answering my question. But the thing is that for NSString property, you always don't want others to modify it, right? You may modify it yourself but definitely not others. I guess most of time NSString get its initial value set up (either by you or by others), after that only you will modify it. Then why not just use readonly property Actually I use copy most of time. But then I

Read UTF8 character in specify position from a NSString

拜拜、爱过 提交于 2019-12-02 21:09:20
NSString* str = @"1二3四5"; NSLog(@"%c",[str characterAtIndex:0]); NSLog(@"%c",[str characterAtIndex:1]); NSString - characterAtIndex works well on ASCII chars, but how could I get the UTF8 character at the index of 2? -- updated -- It seems unichar(16bits) can't represent all the UTF8 encoding strings(8bites to 32bites), so are there any method to get the char from NSString? Unfortunately Dave's answer doesn't actually do what you want. The index supplied to rangeOfComposedCharacterSequenceAtIndex is an index of a UTF-16 code unit, 1 or 2 or which make a UTF-16 code point. So 1 is not the