nsarray

Sorting an NSArray by an NSDictionary value

梦想的初衷 提交于 2019-12-04 09:39:46
问题 I'm trying to sort an array that would look something like this: (please ignore the fact these people are well past any living age! I just needed large numbers) NSDictionary *person1 = [NSDictionary dictionaryWithObjectsAndKeys:@"sam",@"name",@"28.00",@"age",nil]; NSDictionary *person2 = [NSDictionary dictionaryWithObjectsAndKeys:@"cody",@"name",@"100.00",@"age",nil]; NSDictionary *person3 = [NSDictionary dictionaryWithObjectsAndKeys:@"marvin",@"name",@"299.00",@"age",nil]; NSDictionary

NSArray find object or objects - best practices [closed]

霸气de小男生 提交于 2019-12-04 09:10:31
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . Solution: I have marked @BlackRider's answer as correct as it is the most versatile especially for complex comparisons however there are other very good answers and comments. I would encourage anyone with the same or similar question to review them and evaluate the best course

Copy NSMutablearray to another

流过昼夜 提交于 2019-12-04 08:58:38
I am trying to copy NSMutableArray to another but it does not show me anything at the UITableView : NSMutableArray *objectsToAdd= [[NSMutableArray alloc] initWithObjects:@"one",@"two"]; NSMutableArray *myArray = [[NSMutableArray alloc] initWithObjects:objectsToAdd,nil]; NSMutableArray *list = [[NSMutableArray alloc] init]; [self.list addObjectsFromArray:myArray]; Nothing show up! What is wrong? It crashes my app because I do not have nil at my NSMutableArray how can I add nil to it? addobject:nil does not work it crashes the app: static NSString * DisclosureButtonCellIdentifier = @

NSDictionary Vs. NSArray

你。 提交于 2019-12-04 08:53:56
I am reading on objective-c (a nerd ranch book), and I can't help thinking about this question: How do I decide which collection type, NSArray or NSDictionary (both with or w/o their mutable subclasses), to use when reading content from URL? Let's say am reading JSON data from a PHP script (a scenario am dealing with), which to use? I know it is stated in many references that it depends on structure of data (i.e. JSON), but could a clear outline of the two structures be outlined? Thank you all for helping :) Florian NSArray is basically just an ordered collection of objects, which can be

How do I add a CGPoint to NSMutableArray?

房东的猫 提交于 2019-12-04 07:56:17
问题 I want to store my CGPoint to the NSMutable Array, so , I have method like this: [self.points addObject:CGPointMake(x, y)]; But I got the error, it said that : Incompatible type for argument 1 of "addObject". So, I check out the API, - (void)addObject:(id)anObject anObject The object to add to the end of the receiver's content. This value must not be nil. So, I think the " CGPointMake " can make a Object, but it can't be assigned. What happens? 回答1: The problem is that CGPoint is actually

How to generate all of the numbers of pi in Objective-C [closed]

牧云@^-^@ 提交于 2019-12-04 07:16:48
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I want to create an iPad application named "Am I in Pi?" to check birthday numbers with Pi numbers and show the numbers. My question is how can I generate all of the million numbers of pi 3.1415.... etc. Is there

NSArray Tokenize on base of a key

早过忘川 提交于 2019-12-04 07:11:07
问题 I have already fetched data from server and passing the data is also populated with NSMutableArray after NSJSONSerialization . Output of array is as follow's: NSArray *jsonArray = (NSArray *)json; NSLog(@"Array - %@",jsonArray); I want to create a new array which will contain all the data of newsletter. Array - ( { error = 0; newsletter = ( { date = "2015-11-23"; description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\\'s

convert NSArray of NSString(s) to NSArray of NSMutableString(s)

和自甴很熟 提交于 2019-12-04 06:10:00
问题 How to do that without having to "scroll" the entire given array with a "for" loop? 回答1: Since nobody seems to agree with my comment that this is a duplicate of Better way to convert NSArray of NSNumbers to array of NSStrings, here's the same answer again: NSArray * arrayOfMutableStrings = [arrayOfStrings valueForKey:@"mutableCopy"]; From the docs: valueForKey: Returns an array containing the results of invoking valueForKey: using key on each of the array's objects. - (id)valueForKey:

NSMutableArray Not showing actual values when NSLog in iphone application

会有一股神秘感。 提交于 2019-12-04 05:50:47
问题 I am doing an NSLog of an array but instead of data it shows the following values. I do not know how to fix this issue and get the values from the array if(!surveyQuestions){ surveyQuestions=[[NSMutableArray alloc]init]; } Total Survey Questions 3 2012-07-31 08:54:53.555 SQL[442:9203] SurveyQuestions ( "<QuestionData: 0x4da10f0>", "<QuestionData: 0x4b9f120>", "<QuestionData: 0x4ba42e0>" ) 回答1: I'm not sure what you're trying to do but: it's certain that the poor array object has no idea what

Searching a NSArray for the nearest number(s)

∥☆過路亽.° 提交于 2019-12-04 05:22:43
Is there an easy way to search an NSArray of numbers to find the nearest (or exact if it exists) matches to a user-input number? Say I have an array like this: 7, 23, 4, 11, 18, 2 , and the user enters 5 . The program returns the three nearest values in descending order of closeness: 4, 7, 2 , and most importantly gives the NSArray index of the three objects: 2, 0, 5 . Update: see below for a better solution than my first one. Here's a solution using NSDictionary wrappers for each number and its index, with sorting using a comparator block. It probably doesn't scale very well, but it gets the