nsarray

How get objects from one array with same properties of other?

落爺英雄遲暮 提交于 2019-12-06 14:36:28
For example: I have two NSMutableArray . One @[1,2,3,4,5,6,7] . Other have objects like @[ @{@idObjectToSearch":1, @"name":@"aaaaa", @"surname": @"bbbbb"}, @{@idObjectToSearch":2, @"name":@"aaaaa", @"surname": @"ccccc"}, ... @{@idObjectToSearch":100, @"name":@"aaaaa", @"surname": @"cccdcd"} ]; So how I could extract needed objects from second array more effective way? You need to use NSPredicate with your second array. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"idObjectToSearch IN %@", firstArray]; //In above predicate instead of passing `1` you need to pass object from first

how to add new elements in array at the top of the table view

巧了我就是萌 提交于 2019-12-06 13:32:28
问题 i am displaying array of elements in a tableview. Now i need to display some other new elements on table view. For this i try by adding new elements to array which is datasource of table view and reloading the table. Then It displaying the newly added elements but the problem is it is adding at last element of array so it displaying at the bottom of the table view. But i need to display that new value at the top of the table view. How can i done this can any one please help me. Thank u in

finding NSDate's in an NSArray that have a time of day after a given time (e.g. 8pm)?

强颜欢笑 提交于 2019-12-06 13:29:55
Is there a quick way in Objective-C of identifying NSDate's in an NSArray that have a time of day after a given time (e.g. 8pm)? I can't quite see anyway other than manually walking through each NSDate in the array and then using NSDateComponents to break out the hour/minute/second...Not even sure if there is a simple way to get the time from an NSDate in a fashion that represents a fraction of 24hours, as this might help a little. (e.g. 6pm would be 18/24 = 0.75 in this case) There is no need to break in NSDateComponents . NSTimeInterval interval = [date1 timeIntervalSinceDate:date2]; if

How to compare the elements of NSArray in NSMutableDictionary?

為{幸葍}努か 提交于 2019-12-06 12:54:38
问题 My NSMutableDictionary contains four NSArray s with their respective keys. These NSArray s are of size 2 and contain 2D coordinates. I want to get the most common coordinate among them. For example, If a coordinate is common to three arrays, it would be my first choice. How can I find that any coordinate is common to at least two arrays? 回答1: Basically you want to find the pair of coordinates that has max occurences. So you can create an array of all coordinates and find its mode.

iCloud NSMetadata query results are blank

徘徊边缘 提交于 2019-12-06 12:26:47
问题 I've been working on adding icloud to my project (which is quite a pain in the buns) and I'm able to save and remove files, but I can't get a list of the files stored in iCloud. I've tried solutions from about 10 different websites (including the Apple documentation). Whenever I call [self.query startQuery]; everything seems to be working: The correct methods get called, the methods execute exactly as they should. Then when I ask for an nsarray of the files in my app's iCloud Documents

how to edit a plist programmatically in xcode 5 iOS 7?

不打扰是莪最后的温柔 提交于 2019-12-06 12:25:19
how can I edit or change a value string from: in this plist I need change or Set "NO" in Enabled Value from Item 2, I see a lot examples, but not working, or are deprecated, or don't use ARC, any idea or example code? please help guys EDIT#1: I try this (not work) NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; path = [path stringByAppendingPathComponent:@"List.plist"]; NSFileManager *fileManager = [NSFileManager defaultManager]; if (![fileManager fileExistsAtPath:path]) { NSString *sourcePath = [[NSBundle mainBundle]

selecting a random objectAtIndex from NSArray

烂漫一生 提交于 2019-12-06 12:09:11
问题 I have an NSArray which contains 10 objects from index 0 - 9. Each entry in the array is a quotation. When my user selects the 'random quote' option I want to be able to select a random entry from the array and display the text that is contained in that entry. Can anyone point me in the right direction on how to achieve this? 回答1: I'd recommend you use this instead of hardcoding the 10; that way, if you add more quotations, it will work it out automatically, without you needing to change that

How to randomize an NSArray? [duplicate]

情到浓时终转凉″ 提交于 2019-12-06 08:45:55
This question already has answers here : What's the Best Way to Shuffle an NSMutableArray? (12 answers) Closed 4 years ago . Let's say I have a NSArray with 50-100 objects inside. How can I put the array in a random order? There are a lot of ways to do it, but most will involve simply generating random numbers. Perhaps you could use this technique using an NSMutableArray: Generate a random number between 0 and 49 (assuming 50 elements) Swap elements 0 and whatever number you generate Generate a random number between 1 and 49 Swap elements 1 and whatever number you generate Etc. That would

NSArray Loop to grab Objects

纵饮孤独 提交于 2019-12-06 07:58:04
I'm currently in the development process of an application which needs to be able to grab two objects from an NSArray and then store it in another object. I've currently got this fast enumeration loop going on, NSUInteger count = 0; NSUInteger i = count + 1; for (id item in [section items]) { item1 = [section.items objectAtIndex:count]; item2 = [section.items objectAtIndex:i]; count++; } Now, what I want to do is grab the object in the first position and store in item1, and then the second position will be stored in item2. The next time it goes through the loop, I want it to store the object

Sort NSArray of NSDictionaries using comparator

为君一笑 提交于 2019-12-06 05:46:12
I've been trying to sort an NSArray of NSDictionaries using a comparator, but I cannot seem to get the output I desire. The output I'm trying to achieve is that A-Z usernames should come first in the sorted array, then usernames that start with a digit should come second in the sorted array, and lastly usernames that start with an underscore should be last in the sorted array. Any help is truly appreciated! EDIT: It should be sorted so it looks consistent through the whole NSArray so that: _Anna comes before _Bob and _11Bob comes before _12Cary but after _09Bob Example of desired output I'm