nsmutablearray

Write an NSMutableArray to a file and load it back

落花浮王杯 提交于 2019-12-01 22:05:23
问题 I'm doing some exercises about writing to and loading from a file. I've created an NSString , then written it to a file, and then loaded an NSString again. Simple. How can I do this with an NSMutableArray of NSStrings , or better an NSMutableArray of my own class? #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... //write a NSString to a file NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,

Send NSMutableArray as JSON using JSON-Framework

☆樱花仙子☆ 提交于 2019-12-01 22:04:46
问题 I'm using JSON-Framework in my project successfully to decode JSON send from a server. Now I need to do it the other way around and I'm facing problems as the data to be sent is a NSMutableArray fetched from CoreData. When using NSString* jsonString = [menuItems JSONRepresentation] I get the message "JSON serialisation not supported for MenuItems". Do I need to convert the NSMutableArray to some other format so the JSON-Framework can serialize it? Thanks for any help, Miguel 回答1: Allow me to

Write an NSMutableArray to a file and load it back

风流意气都作罢 提交于 2019-12-01 19:44:22
I'm doing some exercises about writing to and loading from a file. I've created an NSString , then written it to a file, and then loaded an NSString again. Simple. How can I do this with an NSMutableArray of NSStrings , or better an NSMutableArray of my own class? #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... //write a NSString to a file NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *filePath =

深入理解iPhone数据持久化

泄露秘密 提交于 2019-12-01 19:18:51
在所有的移动开发平台数据持久化都是很重要的部分:在j2me中是rms或保存在应用程序的目录中,在symbian中可以保存在相应的磁盘目录中和数据库中。symbian中因为权限认证的原因,在3rd上大多数只能访问应用程序的private目录或其它系统共享目录。在iphone中,apple博采众长,提供了多种数据持久化的方法,下面笔者会逐个进行详细的讲解。 iphone提供的数据持久化的方法,从数据保存的方式上讲可以分为三大部分:属性列表、对象归档、嵌入式数据库(SQLite3)、其他方法。 一、属性列表NSUserDefaults NSUserDefaults类的使用和NSKeyedArchiver有很多类似之处,但是查看NSUserDefaults的定义可以看出,NSUserDefaults直接继承自NSObject而NSKeyedArchiver 继承自NSCoder。这意味着NSKeyedArchiver实际上是个归档持久化的类,也就可以使用NSCoder类的[encodeObject: (id)objv forKey:(NSString *)key]方法来对数据进行持久化存储。 - (void)applicationDidFinishLaunching:(UIApplication *)application { NSString *strOne = @"Persistent

Send NSMutableArray as JSON using JSON-Framework

梦想与她 提交于 2019-12-01 18:30:54
I'm using JSON-Framework in my project successfully to decode JSON send from a server. Now I need to do it the other way around and I'm facing problems as the data to be sent is a NSMutableArray fetched from CoreData. When using NSString* jsonString = [menuItems JSONRepresentation] I get the message "JSON serialisation not supported for MenuItems". Do I need to convert the NSMutableArray to some other format so the JSON-Framework can serialize it? Thanks for any help, Miguel Stig Brautaset Allow me to suggest a somewhat nicer solution: In your MenuItems class, implement the -proxyForJson

Remove elements from one NSMutableArray which are contained in another array

狂风中的少年 提交于 2019-12-01 16:22:05
I have two arrays, A and B. How can I remove elements from A, if those elements exist in B? e.g. Array A:{1,2,3,4,5}, array B:{1,3} I would like to remove 1 and 3 from array A such that array A only contains 2,4,5 after the operation. Besides looping, is there any more efficient approach to doing it? You have the removeObjectsInArray: method from NSMutableArray . It does what you want. 来源: https://stackoverflow.com/questions/4365323/remove-elements-from-one-nsmutablearray-which-are-contained-in-another-array

一个崩溃分析

让人想犯罪 __ 提交于 2019-12-01 16:02:53
崩溃的分析 最近修复了一些iOS项目的崩溃,想分析总结一下这些崩溃的原因,以及预防。崩溃的原因一般有下面几种: 内存访问错误(这个出现的比较多,原因多种多样) 非法指令的执行(超出权限范围内的指令) 非法的IO访问 系统调用参数出错 指令条用参数错误(除以0之类) 想分析用户崩溃,收集崩溃的日志非常重要,我们项目中用的是Twitter的Crashlytics,现在叫fabric, 能够收集到比较详细的崩溃信息:各线程的崩溃栈和设备的一些信息。有一个小问题就是没有收集到各个 寄存器里面的值(看是不是我没有找到地方)。 选了出现次数最多的一个崩溃进行分析: # OS Version: 13.1.2 (17A860) # Device: iPhone 8 # RAM Free: 1.9% # Disk Free: 15.7% #24. Crashed: NSOperationQueue 0x107964a70 (QOS: UNSPECIFIED) 0 libobjc.A.dylib 0x1b394f150 objc_release + 16 1 _appstore 0x10184b694 -[YNP_VRHomeCoreViewModel voiceRoomDidChangeSpeakingUser:] + 373 (YNP_VRHomeCoreViewModel.m:373) 2

Remove elements from one NSMutableArray which are contained in another array

你。 提交于 2019-12-01 15:57:50
问题 I have two arrays, A and B. How can I remove elements from A, if those elements exist in B? e.g. Array A:{1,2,3,4,5}, array B:{1,3} I would like to remove 1 and 3 from array A such that array A only contains 2,4,5 after the operation. Besides looping, is there any more efficient approach to doing it? 回答1: You have the removeObjectsInArray: method from NSMutableArray . It does what you want. 来源: https://stackoverflow.com/questions/4365323/remove-elements-from-one-nsmutablearray-which-are

how to change order of NSMutable array in same way another mutable arrays get changed

泄露秘密 提交于 2019-12-01 14:53:13
I have three arrays . They are name , birthdates and remaining days like below: name birthdate remaining "Abhi Shah", "01/14", 300 "Akash Parikh", "12/09/1989", 264 "Anand Kapadiya", "12/01", 256 "Annabella Faith Perez", "03/02", 347 "Aysu Can", "04/14/1992", 25 "Chirag Pandya" "10/07/1987" 201 I want to rearrange the remaining days array into ascending order, but at the same time name and birthdate should also get reordered in the same way. See this example below: name birthdate remaining "Aysu Can", "04/14/1992", 25 "Chirag Pandya" "10/07/1987" 201 "etc..." self.arrayForRows = [

how to sort an NSArray of nested NSArrays by array count?

泪湿孤枕 提交于 2019-12-01 12:47:42
I have an NSArray that contains nested NSArrays. Im looking for a way to sort the parent array according to the object count of the nested arrays in ascending order. so if [array1 count] is 4, [array2 count] is 2 and [array3 count] is 9, i would get : array2, array1, array3... There are a few solutions, one of which is: NSSortDescriptor *sd = [NSSortDescriptor sortDescriptorWithKey:@"@count" ascending:YES]; NSArray *sds = [NSArray arrayWithObject:sd]; NSArray *sortedArray = [array sortedArrayUsingDescriptors:sds]; static NSInteger MONSortObjectsAscendingByCount(id lhs, id rhs, void* ignored) {