nsmutablearray

NSMutableArray addobject with malloc'd struct

て烟熏妆下的殇ゞ 提交于 2019-12-05 06:18:08
问题 I'm having trouble with a snippet of code. I'm trying to add an instance of CLLocationCoordinate2D to a NSMutable array using the addObject method, but whenever the line is executed, my app crashes. Is there anything obvious wrong with this code? The crash is on this line: [points addObject:(id)new_coordinate]; Polygon.m: #import "Polygon.h" @implementation Polygon @synthesize points; - (id)init { self = [super init]; if(self) { points = [[NSMutableArray alloc] init]; } return self; } -(void

Nested arrays in Objective-C ( NSMutableArray )

半腔热情 提交于 2019-12-05 02:07:38
问题 I'm trying to build a nested array: First, I make a "PlayerItems" array which will contain 10 arrays, each containing item objects, corresponding to the inventories of each player in the game. On the indicated line, I get the following error: error: void valued not ignored as it ought to be What is the void value here? If I used [[PlayerItems objectAtIndex:i] addObject:myitem] instead, the program compiles but crashes. If I comment that line out, it compiles and runs OK. Thank you for your

ios sort array with dictionaries

你。 提交于 2019-12-05 02:05:29
问题 I have an NSMutablearray, populated by dictionaries [from a JSON request] i need to organize the array depending to a key in the dictionaries the dictionary IdReward = 198; Name = "Online R d"; RewardImageUrl = "/FileStorimage=1206"; WinRewardPoints = 250; so the array is composed by different dictionaries with the above form, and I need to organize by maximum to minimum WinRewardPoints I have seen this answer in SO, but dont understand yet how to adopt it for my case, thanks a lot! 回答1:

How to create an NSMutableArray and assign a specific object to it?

左心房为你撑大大i 提交于 2019-12-05 01:45:32
I am just getting into Obj C, and I am looking to create an array of MKAnnotations. I have already created the MKAnnotation class called TruckLocation that contains the name, description, latitude, and longitude. Here is what I have so far for the array: NSMutableArray* trucksArray =[NSMutableArray arrayWithObjects: @[<#objects, ...#>] nil]; Wain Yore trying to combine 2 different syntaxes for similar but different things. You also don't seem to have any instances of your annotations. Create some instances TruckLocation *a1 = ...; TruckLocation *a2 = ...; Then we can add them NSMutableArray

iOS中数组的倒序、升序、降序

ぐ巨炮叔叔 提交于 2019-12-05 00:08:49
1 NSMutableArray *array = [NSMutableArray arrayWithObjects:@"5",@"3",@"4",@"2",nil]; 2 3 // 倒序 4 5 NSMutableArray *resultArr = (NSMutableArray *)[[array reverseObjectEnumerator] allObjects]; 6 7 NSLog(@"倒序:%@",resultArr); // 倒序的结果为:2,4,3,5 8 9 10 // 升序 11 12 [array sortUsingSelector:@selector(compare:)]; 13 14 NSLog(@"升序:%@",array); // 升序的结果为:2,3,4,5 15 16 // 降序 17 18 NSEnumerator *enumerator = [array reverseObjectEnumerator]; 19 20 NSMutableArray *jxArr = (NSMutableArray *)[enumerator allObjects]; 21 22 NSLog(@"降序:%@",jxArr); // 降序的结果为:5,4,3,2 来源: https://www.cnblogs.com/liuzhi20101016/p

Loading the UITableView with different NSMutableArrays

大兔子大兔子 提交于 2019-12-04 20:35:05
I have, in my view 4 tab buttons. Upon clicking them i have 4 arrays getting populated. Now i need to display these array into the same table. depending on the button click the contents in the table should change. How can this be done? add UITabBarControllerDelegate - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { switch (tabBarController.selectedIndex) { case 1: table_mutableArray=nil; [table_mutableArray addObjectsFromArray:tab1_array]; break; case 2: table_mutableArray=nil; [table_mutableArray addObjectsFromArray

crashes my app [NSMutableArray1 removeAllObjects] iphone sdk

旧街凉风 提交于 2019-12-04 19:51:27
i use this code to check if any objects exist in my NSMutableArray if yes i remove them all but it crashes although there are objects why? if([NSMutableArray1 count]==1) { [poemoptionslist removeAllObjects]; } if ([NSMutableArray1 count]==0) { [poemoptionslist addObject: final1]; } CONSOLE OUTPUT 2010-10-18 03:42:13.166 app1[33398:207] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object' * Call stack at first throw: ( 0 CoreFoundation 0x02e55b99 exceptionPreprocess + 185 1 libobjc

NSMutableArray Difficulty

爱⌒轻易说出口 提交于 2019-12-04 19:22:28
If you wanna see the code Im having problem with, here is the link: Code My question is connected with my past question . I'm really having problem with my NSMutableArray , I'm currently using iCarousel for my slotMachine object(slot1 and slot2). My app works this way: From PhotoViewController I made a view that has thumbnail images, then assign its frame with button. So if 1 image was pressed, it will save that integer via NSUserDefaults . Then I will retrieve it in my carouselViewController Im thinking of adjusting the array but I can't. I also have tried my question here: Comparing with

NSMutableArray - Get Arrays Index Integer By Searching With A String

泄露秘密 提交于 2019-12-04 18:55:33
问题 I have been working with NSMutableArray and have had no problems retrieving an object from an array by using objectAtIndex:int . Rather then pulling an object out of the array by an integer is their a way to get the index position by searching the array with a string. animalOptions = [[NSMutableArray alloc] init]; //Add items [animalOptions addObject:@"Fish"]; [animalOptions addObject:@"Bear"]; [animalOptions addObject:@"Bird"]; [animalOptions addObject:@"Cow"]; [animalOptions addObject:@

is it possible to swizzle addObject: in NSMutableArray?

假如想象 提交于 2019-12-04 18:13:00
Is it possible to swizzle the addObject: method of NSMutableArray? Here is what I am trying. #import <Foundation/Foundation.h> #import <objc/runtime.h> @implementation NSMutableArray (LoggingAddObject) + (void)load { Method addObject = class_getInstanceMethod(self, @selector(addObject:)); Method logAddObject = class_getInstanceMethod(self, @selector(logAddObject:)); method_exchangeImplementations(addObject, logAddObject); Method original = class_getInstanceMethod(self, @selector(setObject:atIndexedSubscript:)); Method swizzled = class_getInstanceMethod(self, @selector(swizzled_setObject