nsarray

Int does not conform to protocol 'StringLiteralConvertible'

六月ゝ 毕业季﹏ 提交于 2019-12-10 20:46:38
问题 Im trying to parse json in weather app, but have hit a snag that i cannot get past. I do get an error, "Type 'int' does not conform to Protocol 'StringLiteralConvertible'" in the following code. Ive tried casting the jsonResult["main"] but that does instead give the error "Operand of postfix should have optional type, type is AnyObject". Do i need to downcast the Array in some way and how, if so, should i do that? I´ve searched so much for this but could not find any help in other posts. Code

All possible combinations without repetition from an NSArray

梦想的初衷 提交于 2019-12-10 19:29:40
问题 Let say that I have an array with 3 numbers: NSArray *array = @[@1, @2, @3]; And I want to make all combinations without repetition. So what I need is this: ( 1 ) ( 2 ) ( 3 ) ( 1, 2 ) ( 2, 3 ) ( 1, 3 ) ( 1, 2, 3 ) The current code that I have is this: NSArray *array = @[@1, @2, @3]; int numberOfCardsOTable = [array count]; //NSLog(@"array = %@", array); for (int lenghtOfArray = 1; lenghtOfArray <= numberOfCardsOTable; lenghtOfArray++) { for (int i = 0; i < numberOfCardsOTable; i++) { // array

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]

Objective-c: find the last index of an element in a NSArray

巧了我就是萌 提交于 2019-12-10 18:05:04
问题 I have a NSArray, and I want to find the last occurrence of an element. For example: [apple, oranges, pears, apple, bananas]; int i = lastIndexOf("apple"); out: i == 3; I'm struggling to find a simple solution looking an the APIS, but there aren't example so it's pretty hard to understand which function I should use. 回答1: NSUInteger index = [array indexOfObjectWithOptions:NSEnumerationReverse passingTest:^(id obj, NSUInteger i, BOOL *stop) { return [@"apples" isEqualToString:obj]; }]; If the

Sorting an NSArray using another NSArray as a guide

≡放荡痞女 提交于 2019-12-10 17:44:02
问题 So, imagine you have a couple of arrays, Colors and Shapes, like this: Colors: { Yellow, Blue, Red } Shapes: { Square, Circle, Diamond } Now, if I want to sort Colors into alphabetical order I can do something like this: NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:nil ascending:YES selector:@selector(localizedCompare:)]; NSArray *sortedColors = [colors sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]; [sortDescriptor release]; But how would I

Filter Array of Objects with NSPredicate based on NSInteger property in super class

流过昼夜 提交于 2019-12-10 16:49:13
问题 I've got the following setup: @interface Item : NSObject { NSInteger *item_id; NSString *title; UIImage *item_icon; } @property (nonatomic, copy) NSString *title; @property (nonatomic, assign) NSInteger *item_id; @property (nonatomic, strong) UIImage *item_icon; - (NSString *)path; - (id)initWithDictionary:(NSDictionary *)dictionairy; @end And #import <Foundation/Foundation.h> #import "Item.h" @interface Category : Item { } - (NSString *)path; @end I've got an array with Category instances

NSPredicate not working with array of dictionaries

雨燕双飞 提交于 2019-12-10 16:46:45
问题 I have an NSPredication with format like this: @"Status CONTAINS[cd] shipped" I have an array of dictionary, here's an example: { { Category = "Category 4"; Comp = "Category 4"; Depth = 02; Grade = New; Length = 02; Location = "Thousand Oaks, CA"; Name = "3ply Mat"; Owner = "Owner 3"; PUP = 2; Status = Shipped; "Unit Number" = 20110507113852351; Width = 02; }, { Category = "Category 4"; Comp = "Category 4"; Depth = 02; Grade = New; Length = 02; Location = "Thousand Oaks, CA"; Name = "3ply Mat

Cocoa Webkit bug?

走远了吗. 提交于 2019-12-10 16:35:46
问题 I have some code that gets the URL from an array and stores it as a string then uses that string to load up the URL. NSString *first = [urls objectAtIndex:[sender clickedRow]]; NSLog(@"%@", first); [[webview mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:first]]]; However, when I run this I get this error: -[NSURL length]: unrecognized selector sent to instance 0x164dc0 The link in this case is http://www.digg.com I know that the bug is in the line NSString *first =

Add and extract struct from NSMutableArray [duplicate]

回眸只為那壹抹淺笑 提交于 2019-12-10 15:38:47
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: What’s the best way to put a c-struct in an NSArray? I need to create an array of structures, such as: typedef struct { int fill; BOOL busy; } MapCellST; How can I add instances of this structure in NSMutableArray and how I can extract copies of the structure and work with its properties later? 回答1: Wrap the struct in an NSValue : MapCellSt x; NSValue* value = [NSValue value:&x withObjCType:@encode(MapCellSt)];

Subclass NSArray in Objective-C

我怕爱的太早我们不能终老 提交于 2019-12-10 14:49:24
问题 I need to have a class, which has all methods of NSArray, which behave the same way, but 2 methods are modified. I want to override these 2 methods in my custom class: 1) countByEnumeratingWithState:objects:count: 2) objectAtIndex: After hours of research I don't see any reasonable way to do that, because: I don't want to use category, because not all NSArray instances should have the modified behaviour. (Plus that throws warnings) I don't want to re-write all initializers plus all arrayWith.