nsarray

How to store an NSArray in an NSDictionary?

独自空忆成欢 提交于 2019-12-23 10:14:19
问题 I'm trying to teach myself but am struggling with how to store something like an NSArray inside an NSDictionary. Let's say hypothetically you had a NSDictionary for recipes: Let's say the NSDictionary had keys like: Spaghetti, Fettucine Alfredo, Grilled Chicken Salad And the NSDictionary had an NSArray which was simply a list of ingredients. I suppose the equivalent PHP code would be something like: $['Spaghetti'] = array('Spaghetti Pasta', 'Spaghetti Sauce', 'Meatballs'); $['Fettucine

IOS App crash: [__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array

我与影子孤独终老i 提交于 2019-12-23 09:38:13
问题 I have a method I pass an 'id' into here: NSString *id = @"4bf58dd8d48988d181941735"; [self getNames:id]; This works fine, but when I use the 'id' from an object passed within the segue: NSString *id = _selectedStore._id; [self getNames:id]; I get the error: 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array' What's going on? Here's where it's getting the error. My attempt (keep in mind i'm new at this) is to take an array of Foursquare id's,

Split NSString by number of whitespaces

我怕爱的太早我们不能终老 提交于 2019-12-23 08:59:29
问题 I have an NSString that contains some values separated by an unknown number of whitespace characters. For example: NSString* line = @"1 2 3"; I would like to split the NSString into an NSArray of values like so: {@"1", @"2", @"3"} . 回答1: Get the components separated by @" " and remove all objects like @"" from the resultant array. NSString* line = @"1 2 3"; NSMutableArray *array = (NSMutableArray *)[line componentsSeparatedByString:@" "]; [array removeObject:@""]; // This removes all objects

Split NSString by number of whitespaces

限于喜欢 提交于 2019-12-23 08:59:18
问题 I have an NSString that contains some values separated by an unknown number of whitespace characters. For example: NSString* line = @"1 2 3"; I would like to split the NSString into an NSArray of values like so: {@"1", @"2", @"3"} . 回答1: Get the components separated by @" " and remove all objects like @"" from the resultant array. NSString* line = @"1 2 3"; NSMutableArray *array = (NSMutableArray *)[line componentsSeparatedByString:@" "]; [array removeObject:@""]; // This removes all objects

Enumerate NSArray starting at givven index searching both ways (no wrap around)

大城市里の小女人 提交于 2019-12-23 08:04:06
问题 Example. I've got an array with 15 objects. I want to start enumerating from a given index. Say start at index 5 and then the index above, the index under, above, under etc... I don't want it to wrap around, but rather stop and continue in unexplored direction. So the order of indexes in my example would be. 5, 6, 4, 7, 3, 8, 2, 9, 1, 10, 0, 11, 12, 13, 14 How can this be done? 回答1: Here's a more compact implementation that doesn't require creating subarrays: @implementation NSArray

"NSArray' does not have a member named 'append'

不打扰是莪最后的温柔 提交于 2019-12-23 07:36:52
问题 I just got into swift coding and I am trying to follow a tutorial. but it seems as if the coder I'm following may have an older version, or I am doing something wrong. I am trying to make a sound object to make a soundboard. but when i try to add the sound file to the array using append, it says that the method append is not a member of the NSArray . can someone tell me what is the right way to do solve this?!]1 回答1: Declare sounds as var sounds: [Sound] = [] 回答2: You should work with Swift

How to Retrive and Store NSArray from sqlite DB in iOS

怎甘沉沦 提交于 2019-12-23 06:03:02
问题 I have an array itemQtyArray which i am storing in SQLITE table As: NSData *toData = [NSKeyedArchiver archivedDataWithRootObject:self.itemQtyArray]; NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO ORDERTABLE(ITEMDESC,ITEMQTY)VALUES( \"%@\",\"%@\");",dataString2,toData]; and then i am retrieving as : const void *itemQty = sqlite3_column_text(statement, 2); NSInteger qtyBytes = sqlite3_column_bytes(statement, 2); NSData *data2 = [NSData dataWithBytes:itemQty length:qtyBytes];

Unable to change NSNumber to Double and do some calculations with it

女生的网名这么多〃 提交于 2019-12-23 05:55:09
问题 my problem is that i have an Array that holds some double values NSArray *level4results = [context executeFetchRequest:request error:&error]; then i sum up all the values in that array NSNumber *l4sum = [level4results valueForKeyPath:@"sum.self"]; The next thing i want to do is to divide by 8 the sum of the array... and this is where i am stuck. I have tried many options and ways of doing it by either way i kept on getting different error. This is what i have currently in my code double

Extracting data from a Parse.com class and into an NSArray

余生长醉 提交于 2019-12-23 04:24:59
问题 I'm using the following query to get some data from a Parse.com class. What I would like to do is extract the Rating object from the NSArray rateObjects. How would I go about doing this? thanks for any help PFQuery *rateQuery = [PFQuery queryWithClassName:@"Rating"]; [rateQuery whereKey:@"photo" equalTo:self.photo]; [rateQuery includeKey:@"photo"]; rateQuery.cachePolicy = kPFCachePolicyNetworkElseCache; rateQuery.limit = 20; [rateQuery findObjectsInBackgroundWithBlock:^(NSArray *rateObjects,

Pick Out Specific Number from Array? [duplicate]

。_饼干妹妹 提交于 2019-12-23 04:13:21
问题 This question already has answers here : Getting Top 10 Highest Numbers From Array? (5 answers) Closed 5 years ago . I have a bunch of NSArrays filled with numbers. Is there anyway that I can somehow grab a specific number, specifically like: Third highest number in array, or 24th highest number in array? But I don't want to just grab the number, I also need a reference to the index it was in the array as well, if that can be retained in the process. Thanks. 回答1: Third highest number in array