nsmutablearray

NSMutableArray becoming nil after reloadData

别等时光非礼了梦想. 提交于 2019-12-10 23:39:24
问题 In an iPhone app I'm developing, I grab a set of data from a web service, store it in a mutable array for showing in a table, and also store it in core data as backup when there is no network. My array is initialized in application:didFinishLaunchingWithOptions: as follows tableArray = [[NSMutableArray alloc] initWithCapacity:100]; the array is then filled after viewDidLoad gets called, meaning the UITableView exists (verified by checking debugger), and just before reloadData is called, I

NSMutableArray Instance Variable Memory Management

。_饼干妹妹 提交于 2019-12-10 23:22:27
问题 I'm doing my last bit of memory management tidying and there's something I don't understand. I've checked all the documentation, Stack Overflow, etc. but still don't get it. I suspect it's to do with arrays. I have an NSMutableArray as an instance variable which I use to hold objects created from objects in another array. -viewDidLoad initialises the array as follows: self.photoAlbum = [[NSMutableArray alloc] initWithCapacity:100]; It then calls a method which populates them. int i = 0; for

Row Count Is Returning the incorrect number using RaptureXML

允我心安 提交于 2019-12-10 22:53:09
问题 I'm currently using RaptureXML to pull in data from a url tio display inside a table view. I've managed to grab every string I need and add it to my array, as you can see below: - (void)loadURL { RXMLElement *rootXML = [RXMLElement elementFromURL:[NSURL URLWithString:@"http://api.somexml.com/xml"]]; NSLog(@"%@ %@", rootXML.tag, [rootXML attribute:@"totalEntries"]); [rootXML iterateWithRootXPath:@"//event" usingBlock:^(RXMLElement *event) { // NSLog(@"Event - URI: %@", [event attribute:@"uri"]

Split an NSMutableArray into other NSMutableArrays

喜欢而已 提交于 2019-12-10 21:23:34
问题 I have an NSMutableArray with 50 entries - is there any easy way to split this into 5 NSMutableArrays each with 10 entries each. 回答1: I wrote a short function to do this a while ago. The gist of it is to loop an array filling an arbitrary array at the loop index modulo the number of subarrays you want until you run out of items. 回答2: Yes To divide the NSMutableArray you can use the NSArray method - (NSArray *)subarrayWithRange:(NSRange)range NSRange is a struct that is a start location and

How to create a 2D NSArray or NSMutableArray in objective C?

独自空忆成欢 提交于 2019-12-10 18:20:17
问题 I want to ask about the objective C question. I want to create a 2D NSArray or NSMutableArray in objective C. What should I do? The object stored in the array is NSString *. Thank you very mcuh. 回答1: This is certainly possible, but i think it's worthy to note that NSArrays can only hold objects , not primitive types. The way to get around this is to use the primitive wrapper type NSNumber . NSMutableArray *outer = [[NSMutableArray alloc] init]; NSMutableArray *inner = [[NSMutableArray alloc]

Speed: iOS Using NSPredicate filterUsingPredicate vs. for loop

假如想象 提交于 2019-12-10 18:14:58
问题 I need to filter an NSMutableArray of custom objects and was wondering about whether or not one of the following is BETTER than the other in terms of speed/runtime, or if they are virtually the same: (1) Using [array filterUsingPredicate:predicate], or (2) Using a for loop to iterate through all elements and check if they satisfy the criteria or not myself. I only ask this because I think the criteria each object must satisfy could vary so making the predicate could be tricky. Thanks in

Fast way to store and retrieve pairs of numbers in Objective-C

☆樱花仙子☆ 提交于 2019-12-10 16:08:02
问题 I am implementing queued flood fill algorithm and need to store and retrieve pairs of numbers in NSMutableArray . Basically, I am creating an array m_queue = [NSMutableArray array]; then at some time I populate the array [m_queue addObject:[NSValue valueWithCGPoint:CGPointMake(x + 1, y)]]; then I retrieve data for the next iteration and remove the value at the beginning of the array NSValue* value = [m_queue objectAtIndex:0]; [m_queue removeObjectAtIndex:0]; CGPoint nextPoint = [value

NSDictionary / NSMutableDictionary 及 NSArray / ...

你。 提交于 2019-12-10 15:49:13
NSDictionary 常用方法总结 +(id)dictionaryWithObjectsAndKeys:obj1,key1,obj2,key2,......nil 顺序添加对象和键值来创建一个字典,注意结尾是nil -(id)initWithObjectsAndKeys::obj1,key1,obj2,key2,......nil 初始化一个新分配的字典,顺序添加对象和值,结尾是nil -(unsigned int)count 返回字典中的记录数 -(NSEnumerator*)keyNSEnumerator 返回字典中的所有键到一个 NSEnumerator 对象 -(NSArray*)keysSortedByValueUsingSelector:(SEL)selector 将字典中所有键按照selector 指定的方法进行排序,并将结果返回 -(NSEnumerator*)objectEnumerator 返回字典中所有的值到一个 NSEnumetator 类型对象 -(id)objectForKey:key 返回指定key 值的对象 NSMutableDictionary 常用方法总结 +(id)dictionaryWithCapacity:size 创建一个size大小的可变字典 -(id)initWithCapacity:size 初始化一个size 大小的可变字典

解决NSMutableArray使用NSSortDescriptor排序返回NSArray

好久不见. 提交于 2019-12-10 15:33:50
NSMutableArray使用NSSortDescriptor排序,如果将排序后的结果直接返回给NSMutableArray mArray本身,则会导致如果 mArray使用removeAllObject 则会出现错误:[__NSArrayI removeObject:]: unrecognized selector sent to instance 这个错误表示NSArray无法进行删除其中的对象的操作。说明 meetingsTodayArray=[meetingsTodayArray sortedArrayUsingDescriptors:sortDescriptors]; sortedArrayUsingDescriptors:sortDescriptors 返回的是NSArray 所以需要重新申明一个NSArray对象,来指向排序后的Array.这样再将这个Array通过 [mutablemeetingsArray addObjectsFromArray:nsarray];添加到另外一个NSMutableArray中去就行了 来源: oschina 链接: https://my.oschina.net/u/1167726/blog/144788

如何使用自定义对象对NSMutableArray进行排序?

空扰寡人 提交于 2019-12-10 15:19:03
我想做的事情似乎很简单,但我在网上找不到任何答案。 我有一个 NSMutableArray 对象,让我们说它们是'Person'对象。 我想通过Person.birthDate对 NSMutableArray 进行排序,这是一个 NSDate 。 我认为这与这个方法有关: NSArray *sortedArray = [drinkDetails sortedArrayUsingSelector:@selector(???)]; 在Java中,我会使我的对象实现Comparable,或者使用带有内联自定义比较器的Collections.sort ...你到底如何在Objective-C中执行此操作? #1楼 如果您只是对 NSNumbers 数组进行排序,可以使用1次调用对它们进行排序: [arrayToSort sortUsingSelector: @selector(compare:)]; 这是有效的,因为数组中的对象( NSNumber 对象)实现了compare方法。 您可以为 NSString 对象执行相同的操作,甚至可以对实现比较方法的自定义数据对象数组执行相同的操作。 这是使用比较器块的一些示例代码。 它对一组字典进行排序,其中每个字典在一个键“sort_key”中包含一个数字。 #define SORT_KEY @\"sort_key\" [anArray