nsarray

Using NSPredicate to filter array of arrays

我的未来我决定 提交于 2019-12-02 21:07:50
I have the following situation: NSArray( NSArray( string1, string2, string3, string4, string5, ) , NSArray( string6, string7, string8, string9, string10, ) ) Now I need a predicate that returns the array that contains a specific string. e.g. Filter Array that contains string9 -> I should get back the entire second array because I need to process the other strings inside that array. Any ideas? Just for completeness: It can be done using predicateWithFormat: : NSArray *array = @[ @[@"A", @"B", @"C"], @[@"D", @"E", @"F"], ]; NSString *searchTerm = @"E"; NSPredicate *predicate = [NSPredicate

How should I structure my .plist array and dictionary?

心已入冬 提交于 2019-12-02 21:01:16
问题 I have UITableView that will have several child UITableViews which may also have 1 or 2 childs each. I want to create a plist to keep track and structure all the cell names and stuff. Man view -> Child -> Child -> Child -> Detail What is the best way to structure this? Array or Dictionary? 回答1: You will probably want an array of dictionaries, where each array represents a row and the dictionary contains info about the cell, and potentially the child table views. Consider modeling this off the

NSArray adding elements

爷,独闯天下 提交于 2019-12-02 20:05:25
I have to create a dynamic NSArray, that is, I don't know the size of the array or what elements the array is going to have. The elements need to be added to the array dynamically. I looked at the NSArray class reference. There is a method called arrayWithObjects, which should be used at the time of initializing the array itself. But I don't know how to achieve what I need to do. I need to do some thing like the following: NSArray *stringArray = [[NSArray init] alloc] ; for (int i = 0; i < data.size; i++){ stringArray.at(i) = getData(i); } pgb If you create an NSArray you won't be able to add

How do I add a CGPoint to NSMutableArray?

眉间皱痕 提交于 2019-12-02 18:46:14
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? kharrison The problem is that CGPoint is actually just a C structure it is not an object: struct CGPoint { CGFloat x; CGFloat y; }; typedef struct

How to count duplicates values in NSArray?

喜你入骨 提交于 2019-12-02 18:35:47
Value of my NSArray includes the duplicates. I find the duplicates but now how can I find the no. they repeat? You can use NSCountedSet for this. Add all your objects to a counted set, then use the countForObject: method to find out how often each object appears. Example: NSArray *names = [NSArray arrayWithObjects:@"John", @"Jane", @"John", nil]; NSCountedSet *set = [[NSCountedSet alloc] initWithArray:names]; for (id item in set) { NSLog(@"Name=%@, Count=%lu", item, (unsigned long)[set countForObject:item]); } You can try something like this __block NSInteger elementCount = 0; NSArray *array;

What does this Objective-C dictionary code do?

不问归期 提交于 2019-12-02 17:54:16
问题 .h @property (nonatomic, strong) NSMutableDictionary * products; //not synthesized in .m .m - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { NSLog(@"Loaded list of products..."); _productsRequest = nil; NSArray * skProducts = response.products; for (SKProduct * skProduct in skProducts) { IAPProduct * product = _products[skProduct.productIdentifier]; product.skProduct = skProduct; product.availableForPurchase = YES; } for (NSString *

Create index for UITableView from an NSArray

元气小坏坏 提交于 2019-12-02 17:45:36
I've read that the best way of creating an index (the a-z at the side of a uitableview) is to set up an array of nsdictionaries, where each dictionary corresponds to a section, and a rowValue key contains an array of the rows. NSDictionary headerTitle => ‘A’ rowValues => {”Aardvark”, “Ape”, “Aquaman”} NSDictionary headerTitle => ‘B’ rowValues => {”Bat”, “Boot”, “Bubbles”} etc But how can this be created from an array of all the row titles - {”Aardvark”, “Ape”, “Aquaman”, ”Bat”, “Boot”, “Bubbles”, "Cat", "Cabbage" etc} ...? #pragma mark - #pragma mark View lifecycle - (void)viewDidLoad { [super

NSString stringWithFormat and NSArray [duplicate]

牧云@^-^@ 提交于 2019-12-02 17:35:23
问题 This question already has answers here : How to create a NSString from a format string like @“xxx=%@, yyy=%@” and a NSArray of objects? (13 answers) Closed 2 years ago . I need a method for generating string from the format-string and it's arguments inside NSArray but I did't find any working solution on the StackOverflow. They don't build nor throw exceptions (first, second). 回答1: So I write my solution and I want to share it with you. @implementation NSString (AX_NSString) + (instancetype

Testing if NSMutableArray contains a string object

Deadly 提交于 2019-12-02 17:26:07
I have a NSMutableArray which contains a few NSString objects. How can I test if the array contains a particular string literal? I tried [array containsObject:@"teststring"] but that doesn't work. What you're doing should work fine. For example NSArray *a = [NSArray arrayWithObjects:@"Foo", @"Bar", @"Baz", nil]; NSLog(@"At index %i", [a indexOfObject:@"Bar"]); Correctly logs "At index 1" for me. Two possible foibles: indexOfObject sends isEqual messages to do the comparison - you've not replaced this method in a category? Make sure you're testing against NSNotFound for failure to locate, and

Difference between NSArray and NSMutableArray

旧时模样 提交于 2019-12-02 17:24:25
What is the difference b/w NSArray and NSMutableArray ? NSMutableArray (and all other classes with Mutable in the name) can be modified. So, if you create a plain NSArray , you cannot change its contents later (without recreating it). But if you create an NSMutableArray , you can change it — you'll notice it has methods like -addObject: and -insertObject:atIndex: . See the documentation for details. The "mutable" types are classes which can be changed after they've been initialized, like NSMutableString vs NSString . Jagat Dave NSArray : in NSArray we can not change index.... Means fix array.