nsmutablearray

NSMutableArray arrayWithArray: vs. initWithArray:

眉间皱痕 提交于 2019-12-09 18:49:18
问题 These both work in my app without any noticeable difference: 1) theArray = [[NSMutableArray alloc] initWithArray:[NSKeyedUnarchiver unarchiveObjectWithData:theData]]; 2) theArray = [NSMutableArray arrayWithArray:[NSKeyedUnarchiver unarchiveObjectWithData:theData]]; [theArray retain]; However, are they really equivalent? (1) has an alloc statement, whereas (2) does not. Is one preferable over the other? 回答1: The effect is the same. But (2) is less efficient (a convenient method = alloc + init

Differences between [NSArray arrayWithArray:] and [NSArray copy]

我的梦境 提交于 2019-12-09 08:21:40
问题 lately I work much with arrays and I'm wonder.. what's diffrences between those two lines. NSArray *array = [NSArray arrayWithArray:someArray]; and NSArray *array = [someArray copy]; Which of it is faster? What in case we have NSMutableArray and mutableCopy ? 回答1: Which of it is faster? Don't worry about it. Premature optimization. The main difference: the first approach results in an autoreleased "copy" that you don't own and don't have to release, while you do own the object created on the

How to exchange elements in swift array?

邮差的信 提交于 2019-12-09 05:04:22
问题 I have one simple array like: var cellOrder = [1,2,3,4] I want to exchange elements like suppose a second element with first element. And result will be: [2,1,3,4] I know we can use exchangeObjectAtIndex with NSMutableArray But I want to use swift array. Any ways to do same with swift [Int] array? 回答1: Use swap : var cellOrder = [1,2,3,4] swap(&cellOrder[0], &cellOrder[1]) Alternately, you can just assign it as a tuple: (cellOrder[0], cellOrder[1]) = (cellOrder[1], cellOrder[0]) 回答2: Swift 4

Total Size of NSMutableArray object

二次信任 提交于 2019-12-09 05:02:09
问题 I've got an NSMutableArray that holds a bunch of objects, what I'm trying to figure out is how much memory is the array using. After looking at a couple of places I know about the size of call, and when I make it I get 32 bits (which is the size of the NSMutableArray object it self). Example code: NSMutableArray *temp = [[NSMutableArray alloc]init]; [temp addObject:objectxyz]; [temp addObject:objectabc]; [temp addObject:object123]; now I want to know the size :) 回答1: To get the number of

NSMutableArray check if object already exists

倾然丶 夕夏残阳落幕 提交于 2019-12-08 23:06:40
问题 I am not sure how to go about this. I have an NSMutableArray (addList) which holds all the items to be added to my datasource NSMutableArray. I now want to check if the object to be added from the addList array already exists in the datasource array. If it does not exist add the item, if exists ignore. Both the objects have a string variable called iName which i want to compare. Here is my code snippet -(void)doneClicked{ for (Item *item in addList){ /* Here i want to loop through the

Sum duplicate on NSMutableArray

痴心易碎 提交于 2019-12-08 18:35:43
I have a NSMutableArray with objects of type NSMutableDictionary , the NSMutableDictionary contains 2 keys -Airlines (string) -Rating (integer) I have an NSMutableArray with all the objects and what i need is to Sum the rating of all the airline companies repeated objects, an example: Airline Rating A 2 B 3 B 4 C 5 The end result array will be the A = 2, C = 5 and the Sum of B´s that is equal to 7. My code so far: for (int i = 0; i < arrayMealRating.count; ++i) { NSMutableDictionary *item = [arrayMealRating objectAtIndex:i]; NSLog(@"item=%@",item); for (int j = i+1; j < arrayMealRating.count;

How do I access JSON data in an NSMutableArray?

前提是你 提交于 2019-12-08 15:19:09
问题 I'm trying to access JSON data that I have taken from a website and stored in an array. First, however, I want to filter out everything but the "title" information, which I am doing using the valueForKey: method. In order to test this I am writing them to the log using the NSLog method, however when I run this I get "null". Can anyone advise me, as to why I'm getting what I'm getting? Thanks for your help, much appreciated. { NSURL *redditURL = [NSURL URLWithString:@"http://pastebin.com/raw

Objective-C: JSON Unrecognised leading character?

北慕城南 提交于 2019-12-08 13:51:01
问题 when trying to execute little function to get an array using JSON i get the next message: -JSONValue failed. Error trace is: ( "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Unrecognised leading character\" UserInfo=0x5d50e30 {NSLocalizedDescription=Unrecognised leading character}" This is the code NSString * payloadAsString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding]; NSLog(@"%@",payloadAsString); NSMutableArray *jsonArray = [[NSMutableArray alloc]

Thread-safe NSMutableArray question

淺唱寂寞╮ 提交于 2019-12-08 13:46:11
问题 I am developing a RSS reader which uses a NSMutableArray ( _stories ) to store the contents of the RSS Feed. This array is being used by two different threads in the application and may be accessed simultaneously in two occasions, since: It is the data-source of the UITableViewController (which reads it's content and shows the desired information to the user) It is used by the XMLParser (which downloads the content from the Internet, parses the XML Data and adds the contents to it). Some

Using BOOL objects in NSMutableArray to determine cell statuses

帅比萌擦擦* 提交于 2019-12-08 12:39:24
问题 I'm using an NSMutableArray referenced as 'stateArray'. stateArray needs to simply hold the BOOL value for my cells to determine whether or not they are selected. here's my code.. stateArray in my .h: @property (nonatomic, strong) NSMutableArray *stateArray; Then stateArray is not synthesized. It needs to be filled with NO throughout the array, so that when the cell becomes selected, NO can be replaced by YES. Currently this code is printing 0's for stateArray for every cell(the NSLog is in