nsmutablearray

NSMutableArray addObject in for loop - memory leak

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 07:39:06
问题 i'm putting strings (which are filenames of files in a certain directory) into an NSMutableArray with a for loop: h-file: #import <Three20/Three20.h> @interface AlbumController : TTThumbsViewController { NSMutableArray *images; } @property (nonatomic, retain) NSMutableArray *images; @end m-file: #import "AlbumController.h" #import "PhotoSource.h" #import "Photo.h" @implementation AlbumController @synthesize images; -(void)createPhotos { NSString *bundleRoot = [[NSBundle mainBundle] bundlePath

Storing pointers to objects in array in Objective c

南楼画角 提交于 2019-12-13 06:17:35
问题 I'm using this code to create some objects and then store them in an array for (int iy=0; iy<5; iy++) { for (int ix=0; ix<5; ix++) { TerrainHex *myObject = [[TerrainHex alloc] initWithName:(@"grassHex instance 10000") width:mGameWidth height:mGameHeight indexX:ix indexY:iy]; myObject.myImage.y += 100; [TerrainHexArray addObject:myObject]; [self addChild:(id)myObject.myImage]; } } NSLog(@"%lu", sizeof(TerrainHexArray)); Few questions. The log is only displaying 4, which makes no sense, shouldn

How to check repetition of numbers in an array?

穿精又带淫゛_ 提交于 2019-12-13 05:46:51
问题 I generate random numbers and store them in an array: int RandomNumber = arc4random() % 12; [NSMutablearray *Number addObject:[NSNumber numberWithInt:RandomNumber]]; Now I want to make sure the same number is not created randomly again. Can any one please tell me how to do it with sample code. 回答1: You can use an NSMutableSet instead of an array while generating the numbers. The following code will create an array of 10 unique random numbers: NSMutableSet *aSet = [NSMutableSet setWithCapacity

Retrieving Class Object from NSArray and adding to self

家住魔仙堡 提交于 2019-12-13 05:40:45
问题 Hi im trying to retrieve an object of a specific class from an NSMutableArray, and then add it to self: eg: - (void) init{ _Objects = [[NSMutableArray alloc]init]; Psychicing *psy = [[Psychicing alloc]init]; [psy startPsychic]; [_Objects addObject: psy]; [psy release]; } This creates an object of class Psychicing, then runs the [psy startPsychic] method to create the internals of the class object. Then I add the psy object to _Objects NSMutableArray. -(void)startPsychic{ id psychicParticle =

NSXMLParser how to pass the NSMutableDictionary to a NSMutableArray

社会主义新天地 提交于 2019-12-13 05:38:33
问题 I would like to pass the nsdictionary I am creating into an nsmutablearray but I'm not sure when or how to do it in the nsxmlparser delegates. this is what I have done so far #pragma mark - Parsing lifecycle - (void)startTheParsingProcess:(NSData *)parserData { NSXMLParser *parser = [[NSXMLParser alloc] initWithData:parserData]; //parserData passed to NSXMLParser delegate which starts the parsing process [parser setDelegate:self]; [parser parse]; // starts the event-driven parsing operation.

iPhone SDK: NSMutableArray unrecognized selector

独自空忆成欢 提交于 2019-12-13 04:41:37
问题 I have an NSMutableArray which gets objects added to it from an NSDictionary. These objects are values of either 1 or 0. I am trying to loop through this NSMutableArray, to check each value. If it is 1, I set add a green tick image to an array, if it is zero, I add a red cross image to an array. However I am getting the following error on checking the values of the NSMutableArray: [__NSArrayI isEqualToString:]: unrecognized selector sent to instance Here is my code: facilitiesAvailable =

Return the count of an NSMutableArray from an XML id number in Objective-C?

荒凉一梦 提交于 2019-12-13 04:29:13
问题 I am building an NSMutableArray out of an XML file and need to return the count of each resident id in the XML file. Is it possible to do this? <residents> <resident id="1"> <name> <first>Daffy</first> <last>Duck</last> </name> </resident> <resident id="2"> <name> <first>Mickey</first> <last>Mouse</last> </name> </resident> etc... I will be returning the count using code similar to this: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSLog(@"Count =

iOS - Storing groups of UILabels into a NSMutableArray

有些话、适合烂在心里 提交于 2019-12-13 04:26:12
问题 I'm creating UILabel s dynamically in a for each loop. Every loop that is run creates 1-4 UILabels. What I want is that I put these UILabels into my NSMutableArray and being able later to easy retrieve the data. My original thought was to put these UILabels into a NSDictionary and use [dictGroupLabels setValue:uiLabel1 forKey:@"uiLabel1"] and then [dictGroupLabels setValue:uiLabel2 forKey:@"uiLabel2"] and so on. And then put this dictionary into my NSMutableArray for each loop. Later on I

Pass an NSMutableArray to a NSWindowController

南笙酒味 提交于 2019-12-13 04:06:14
问题 So I am creating a NSWindowController like so: if ( summaryWindow ) { [summaryWindow release]; } // end if summaryWindow = [[SummaryWindowController alloc] init]; I am then passing this object an array that I will be using for a NSTableView [ summaryWindow setGlobalStatusArray:globalStatusArray]; Once that object is created, I realize I have don't know how to do something fundamental which is to link the newly created object actions and outlets. If I create a object in the xib, and link up

How to form static data with the structure like array of objects in swift 4?

╄→гoц情女王★ 提交于 2019-12-13 04:04:32
问题 Currently, I'm building an app using the Swift platform. I need to show static data like an array of objects structure because I need to load data on UITableView section and rows. Below is the example array of objects structure in objective C. I need to replicate the same thing in Swift. NSArray *dummyArray = [[NSArray alloc] initWithObjects: [[NSDictionary alloc] initWithObjectsAndKeys:@"India",@"team",@"280",@"score",@"5",@"wickets", nil], [[NSDictionary alloc] initWithObjectsAndKeys:@