Search Results

Search found 1009 results on 41 pages for 'nsarray'.

Page 1/41 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • NSArray in NSArray do not return the image I want

    - by Tibi
    Hi there, I've got a code snippet here that I can't make working. NSUInteger i; //NSMutableArray *textures = [[NSMutableArray alloc] initWithCapacity:kNumTextures]; //NSMutableArray *texturesHighlighted = [[NSMutableArray alloc] initWithCapacity:kNumTextures]; NSMutableArray *textures= [[NSMutableArray alloc] init]; for (i = 1; i <= kNumTextures; i++) { NSString *imageName = [NSString stringWithFormat:@"texture%d.png", i]; NSString *imageNameHighlighted = [NSString stringWithFormat:@"texture%d_select.png", i]; UIImage *image = [UIImage imageNamed:imageName]; UIImage *imageHighlighted = [UIImage imageNamed:imageNameHighlighted]; //NSArray *pics = [[NSArray alloc] initWithObjects:(UIImage)image,(UIImage)imageHighlighted,nil]; NSArray *pics = [NSArray arrayWithObjects:image,imageHighlighted,nil]; [textures addObject:pics]; [pics release]; } //select randomly the position of the picture that will be represented twice on the board NSInteger randomTexture = arc4random()%([textures count]+1); //extract image corresponding to the randomly selected index //remove corresponding pictures from textures array NSArray *coupleTexture = [textures objectAtIndex:randomTexture]; [textures removeObjectAtIndex:randomTexture]; //create the image array containing 1 couple + all other pictures NSMutableArray *texturesBoard = [[NSMutableArray alloc] initWithCapacity:kNumPotatoes]; [texturesBoard addObject:coupleTexture]; [texturesBoard addObject:coupleTexture]; [coupleTexture release]; NSArray *pics = [[NSArray alloc] init]; for (pics in textures) { [texturesBoard addObject:pics]; } [pics release]; //shuffle the textures //[texturesBoard shuffledMutableArray]; //Array with masks NSMutableArray *masks= [[NSMutableArray alloc] init]; for (i = 1; i <= kNumMasks; i++) { NSString *maskName = [NSString stringWithFormat:@"mask%d.png", i]; UIImage *mask = [UIImage imageNamed:maskName]; //NSArray *pics = [[NSArray alloc] initWithObjects:mask,nil]; [masks addObject:mask]; //[pics release]; [maskName release]; [mask release]; } //Now mask all images in texturesBoard NSMutableArray *list = [[NSMutableArray alloc] init]; for (i = 0; i <= kNumMasks-1; i++) { //take on image couple from textures NSArray *imgArray = [texturesBoard objectAtIndex:i]; UIImage *mask = [masks objectAtIndex:i]; //mask it with the mask un the array at corresponding index UIImage *img1 =(UIImage *) [imgArray objectAtIndex:0]; UIImage *img2 =(UIImage *) [imgArray objectAtIndex:1]; UIImage *picsMasked = [self maskImage:(UIImage *)img1 withMask:(UIImage *)mask]; UIImage *picsHighlightedMasked = [self maskImage:(UIImage *)img2 withMask:(UIImage *)mask]; //Init image with highlighted status TapDetectingImageView *imageView = [[TapDetectingImageView alloc] initWithImage:picsMasked imageHighlighted:picsHighlightedMasked]; [list addObject:imageView]; } The problem here is that : img1 and img2, are not images but rather NSArray with multiple entries. Ican't figure why... dos any fresh spirit here could provide me with some clue to fix. maaany thanks.

    Read the article

  • Sort NSArray of custom objects based on sorting of another NSArray of strings

    - by Nic Hubbard
    I have two NSArray objects that I would like to be sorted the same. One contains NSString objects, the other custom Attribute objects. Here is what my "key" NSArray looks like: // The master order NSArray *stringOrder = [NSArray arrayWithObjects:@"12", @"10", @"2", nil]; The NSArray with custom objects: // The array of custom Attribute objects that I want sorted by the stringOrder array NSMutableArray *items = [[NSMutableArray alloc] init]; Attribute *attribute = nil; attribute = [[Attribute alloc] init]; attribute.assetID = @"10"; [items addObject:attribute]; attribute = [[Attribute alloc] init]; attribute.assetID = @"12"; [items addObject:attribute]; attribute = [[Attribute alloc] init]; attribute.assetID = @"2"; [items addObject:attribute]; So, what I would like to do is use the stringOrder array to determine the sorting of the items array of custom objects. How can I do this?

    Read the article

  • populating an nsarray

    - by MoKaM
    I intend to make a program that does the following: Create an NSArray populated with numbers from 1 to 100,000. Loop over some code that deletes certain elements of the NSArray when certain conditions are met. Store the resultant NSArray. However the above steps will also be looped over many times and so I need a fast way of making this NSArray that has 100,000 number elements. So what is the fastest way of doing it? Is there an alternative to iteratively populating an Array using a for loop? Such as an NSArray method that could do this quickly for me? Or perhaps I could make the NSArray with the 100,000 numbers by any means the first time. And then create every new NSArray (for step 1) by using method arraywithArray? (is it quicker way of doing it?) Or perhaps you have something completely different in mind that will achieve what I want. edit: Replace NSArray with NSMutableArray in this post.

    Read the article

  • NSPredicate 'OR' filtering based on an NSArray of keys

    - by So Over It
    Consider the following NSArray: NSArray *dataSet = [[NSArray alloc] initWithObjects: [NSDictionary dictionaryWithObjectsAndKeys:@"abc", @"key1", @"def", @"key2", @"hij", @"key3", nil], [NSDictionary dictionaryWithObjectsAndKeys:@"klm", @"key1", @"nop", @"key2", nil], [NSDictionary dictionaryWithObjectsAndKeys:@"qrs", @"key2", @"tuv", @"key3", nil], [NSDictionary dictionaryWithObjectsAndKeys:@"wxy", @"key3", nil], nil]; I am able to filter this array to find dictionary objects that contain the key key1 // Filter our dataSet to only contain dictionary objects with a key of 'key1' NSString *key = @"key1"; NSPredicate *key1Predicate = [NSPredicate predicateWithFormat:@"%@ IN self.@allKeys", key]; NSArray *filteretSet1 = [dataSet filteredArrayUsingPredicate:key1Predicate]; NSLog(@"filteretSet1: %@",filteretSet1); Which appropriately returns: filteretSet1: ( { key1 = abc; key2 = def; key3 = hij; }, { key1 = klm; key2 = nop; } ) Now, I am wanting to filter the dataSet for dictionary objects containing ANY of the keys in an NSArray. For example, using the array: NSArray *keySet = [NSArray arrayWithObjects:@"key1", @"key3", nil]; I want to create a predicate that returns and array of any dictionary objects that contain either 'key1' or 'key3' (ie. in this example all dictionary objects would be returned except for the third object - as it does not contain either 'key1' or 'key3'). Any ideas on how I would achieve this? Would I have to use a compound predicate?

    Read the article

  • Passing a NSArray between classes

    - by Althane
    So, my second question based off of this application I'm teaching myself Objective C with. I have a Data Source class, which for now looks mostly like: - (id) init { if (self = [super init]){ listNames = [[NSArray alloc] initWithObjects: @"Grocery", @"Wedding", @"History class",@"CS Class",@"Robotics",@"Nuclear Sciences", @"Video",@"Library",@"Funeral", nil]; NSLog(@"%@",listNames); } return self; } The .h looks as follows: @interface MainViewDataSource : NSObject { NSArray *listNames; } @property (nonatomic, retain) NSArray *listNames; -(NSArray *)getListNames; So that's where I make it. Now the problem is that when I try to get the array listNames, it returns nothing. The following piece: NSArray* data = [listData listNames]; Is supposed to put the information in listNames in data, but... isn't. Since I'm rather used to JAva, I'm betting this is an Objective C quirk that I don't know how to fix. Which is why I'd be here asking for help. What's the proper way to pass around NSArrays like this?

    Read the article

  • Check if NSString exists in custom object in NSArray

    - by Paul Peelen
    I have an NSArray with Store objects. Each Store object has two NSString objects; StoreID and Name. I would like to check quickly if an ID exists in this NSArray with Store objects. Example: Store *s1 = [[Store alloc] init]; s1.name = @"Some Name"; s1.id = @"123ABC"; Store *s2 = [[Store alloc] init]; s2.name = @"Some Other Name"; s2.id = @"ABC123"; NSArray *array = [[NSArray alloc] initWithObjects:s1, s2, nil]; NSString *myIdOne = @"ABCDEF"; NSString *myIdTwo = @"123ABC"; BOOL myIdOneExists = ...? BOOL myIdTwoExists = ...? Its the ...? I need to figure out. I know I can do this using a for loop and break when found... but this seems to me like an nasty approach since the NSArray could contain thousands of objects,... theoretically. So I would like to know about a better solution.

    Read the article

  • How to add objects to NSArray from a different class with ARC

    - by Space Dust
    I needed to convert my code to ARC. I have an NSArray that I use to draw a path. I fill the objects of NSArray values from a different class. Problem is after converting to ARC, NSArray returns always null I can not see what I am doing wrong. bug.h @interface Ladybug : CCSprite <CCTargetedTouchDelegate>{ CCArray *linePathPosition; } @property (nonatomic, strong) CCArray *linePathPosition; @end bug.m @synthesize linePathPosition; -(id) init { if( (self=[super init] )) { self.linePathPosition = [[CCArray alloc] init]; } return self; } -(void) updatePosition:(CGPoint) position { [self.linePathPosition addObject:[NSValue valueWithCGPoint:position]]; NSLog(@"line path %@",linePathPosition); } -(void) breakMoveLadyBug { [self.linePathPosition removeAllObjects]; } In main .m - (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event { Ladybug *ladybug1 = (Ladybug *)[self getChildByTag:99]; CCMotionStreak* streak = (CCMotionStreak *)[self getChildByTag:999]; CGPoint touchLocation = [touch locationInView: [touch view]]; CGPoint curPosition = [[CCDirector sharedDirector] convertToGL:touchLocation]; if (ladybug1.isSelected) { streak.position = curPosition; [ladybug1 updatePosition:curPosition]; NSLog(@"Cur position %@",NSStringFromCGPoint(curPosition)); if (!ladybug1.isMoving) { [ladybug1 startMoveLadyBug]; } } } Log: Cur position {331, 110} line path (null) What am I doing wrong? What is the proper way to define and init NSArray with ARC?

    Read the article

  • NSArray safeguards

    - by Spider-Paddy
    If there is a chance that an NSArray is empty, is it better to check it and set equal to nil if it's empty when it is assigned or to rather do the check when it is used? e.g. NSArray *myArray; if ([anotherArray count] > 0) <-- Check when assigned myArray = [anotherArray copy]; else myArray = nil; something = [myArray objectAtIndex:x]; or NSArray *myArray; myArray = [anotherArray copy]; if ([myArray count] > 0) <-- Check when used something = [myArray objectAtIndex:x]; Which is better?

    Read the article

  • iPhone / NSArray : How do I format a text file to be read in using arrayWithContentsOfFile

    - by nickthedude
    I have several large word lists and I had been loading them in place in the code as follows: NSArray *dict3 = [[NSArray alloc] initWithObjects:@"abled",@"about",@"above",@"absurd",@"absurdity", ... but now it is actually causing an exc_bad_access error weirdly, i know it seems implausible but for some reason IT IS causing it. (trust me on this I just spend the better part of a day debugging this crap) Anyway, I'm looking to get these humongous lines of code out of my files but I'm not sure what the best approach is. I guess I could do a plist but I need to figure out how to automate the process. it be easiest if I could just use the text files I've been compiling so if anyone knows how I can format the text file so that the myArray = [NSArray arrayWithContentsOfFile: @"myTextFile.txt"]; will be read in correctly as one word per element in the array it would really be appreciated. Thanks, Nick

    Read the article

  • Using NSArray for C-type int comparisons

    - by Andrew Barinov
    I would like to iterate through an NSArray of ints and compare each one to a specific int. All ints are C type ints. The code I am using is as follows: -(int)ladderCalc: (NSArray*)amounts: (int)amount { int result; for (NSUInteger i=0; i< [amounts count]; i++) { if (amount < [amounts objectAtIndex:i]); { // do something } // do something } } However I get an error when comparing the int amount to the result of [amounts objectAtIndex:i] because you cannot compare id to int. Why is the id involved in this case? Shouldn't objectAtIndex just return the object at the index specified? Is it possible to cast the object returned to an C int and then do the comparison? Or should I just dispense with NSArray and do this type of thing in C?

    Read the article

  • Compare NSArray with NSMutableArray adding delta objects to NSMutableArray

    - by Hooligancat
    I have an NSMutableArray that is populated with objects of strings. For simplicity sake we'll say that the objects are a person and each person object contains information about that person. Thus I would have an NSMutableArray that is populated with person objects: person.firstName person.lastName person.age person.height And so on. The initial source of data comes from a web server and is populated when my application loads and completes it's initialization with the server. Periodically my application polls the server for the latest list of names. Currently I am creating an NSArray of the result set, emptying the NSMutableArray and then re-populating the NSMutableArray with NSArray results before destroying the NSArray object. This seems inefficient to me on a few levels and also presents me with a problem losing table row references which I can work around, but might be creating more work for myself in doing so. The inefficiency seems to be that I should be able to compare the two arrays and end up with a filtered NSArray. I could then add the filtered set to the NSMutableArray. This would mean that I can simply append new data to the NSMutableArray instead of throwing everything out and re-populating. Conversely I would need to do the same filter in reverse to see if there are records that need removing from the NSMutableArray. Is there any method to do this in a more efficient manner? Have I overlooked something in the docs some place that refers to a simpler technique? I have a problem when I empty the NSMutableArray and re-populate in that any referencing tables lose their selected row state. I can track it and re-select it, but my theory is that using some form of compare and adding objects and removing objects instead of dealing with the whole array in one block might mean I keep my row reference (assuming the item isn't deleted of course). Any suggestions or help much appreciated. Update Would it be just as fast to do a fast enumeration over each comparing each line item as I go? It seems like an expensive operation, but with the last fast enumeration code it might be pretty efficient...

    Read the article

  • Difference of 2 NSArray's for animated insert/delete in UITableView

    - by Alexander Cohen
    At some point in my Application, I have an NSArray whose contents change. Those contents are shown in a UITableView. I'm trying to find a way to find the diff between the contents of before and after of the NSArray so i can pass the correct indexPaths to insertRowsAtIndexPaths:withRowAnimation: and deleteRowsAtIndexPaths:withRowAnimation: in order to have the changes nicely animated. Any ideas? thx

    Read the article

  • Store NSArray In Core Data Sample Code?

    - by Stunner
    Ey guys, I have been searching for some sample code on how to store an NSArray in Core Data for awhile now, but haven't had any luck. Would anyone mind pointing me to some tutorial or example, or better yet write a simple sample as an answer to this question? I have read this but it doesn't show an example of how to go about implementing a transformable attribute that is an NSArray. Thanks in advance!

    Read the article

  • Displaying indexed png- files out of NSArray on the iphone screen

    - by Thomas Hülsmann
    Hi, i like to create an artwork counter- display on an iphone, diplaying 0 to 9. The 10 digits are 10 png- files with the numbers 0 to 9 as their artwork content. The 10 png- files are implemented by using NSArray. Following you'll find the implementation- code: zahlenArray = [NSArray arrayWithObjects: [UIImage imageNamed:@"ziffer-0.png"], [UIImage imageNamed:@"ziffer-1.png"], [UIImage imageNamed:@"ziffer-2.png"], [UIImage imageNamed:@"ziffer-3.png"], [UIImage imageNamed:@"ziffer-4.png"], [UIImage imageNamed:@"ziffer-5.png"], [UIImage imageNamed:@"ziffer-6.png"], [UIImage imageNamed:@"ziffer-7.png"], [UIImage imageNamed:@"ziffer-8.png"], [UIImage imageNamed:@"ziffer-9.png"], nil]; As an index for the 10 digitis I use an integer variable, initializing with 0: int counter = 0; Furthermore I declare an UIImageview programmaticaly: UIImageView *zahlenEinsBisNeun; The implementation code for the UIImageview is: zahlenEinsBisNeun = [UIImage alloc] initWithFrame:CGRectMake(240, 50, 200, 200)]; ???????????????????????????????????????? [self.view addSubview:zahlenEinsBisNeun]; [zahlenEinsBisNeun release]; There, where you see the questionmarks, I don't know how to write the code, to retrieve my content artworks 0 to 9 from NSArray with the index "counter" and make it visible on my iphone screen by using .... addSubview:zahlenEinsBisNeun ... Can anybody help??? My thanks for your support in advance Thomas Hülsmann

    Read the article

  • How to select one object from a NSArray?

    - by 0SX
    First of all Merry Christmas to everyone!!! Currently I have a NSArray that has parsed content in it. When I do a NSLog of the array it prints out 20 objects with the parsed content that I needed. Like so: 2010-12-24 20:27:32.170 TestProject[48914:298] SomeContent 2010-12-24 20:27:32.172 TestProject[48914:298] SomeContent1 2010-12-24 20:27:32.172 TestProject[48914:298] SomeContent2 2010-12-24 20:27:32.173 TestProject[48914:298] SomeContent3 2010-12-24 20:27:32.173 TestProject[48914:298] SomeContent4 2010-12-24 20:27:32.173 TestProject[48914:298] SomeContent5 2010-12-24 20:27:32.174 TestProject[48914:298] SomeContent6 2010-12-24 20:27:32.175 TestProject[48914:298] SomeContent7 2010-12-24 20:27:32.176 TestProject[48914:298] SomeContent8 2010-12-24 20:27:32.176 TestProject[48914:298] SomeContent9 2010-12-24 20:27:32.177 TestProject[48914:298] SomeContent10 2010-12-24 20:27:32.177 TestProject[48914:298] SomeContent11 2010-12-24 20:27:32.177 TestProject[48914:298] SomeContent12 2010-12-24 20:27:32.179 TestProject[48914:298] SomeContent13 2010-12-24 20:27:32.179 TestProject[48914:298] SomeContent14 2010-12-24 20:27:32.180 TestProject[48914:298] SomeContent15 2010-12-24 20:27:32.180 TestProject[48914:298] SomeContent16 2010-12-24 20:27:32.181 TestProject[48914:298] SomeContent17 2010-12-24 20:27:32.181 TestProject[48914:298] SomeContent18 2010-12-24 20:27:32.190 TestProject[48914:298] SomeContent19 However, I don't need every object at once. I need to be able to pick out one object at a time so I can put each object into a string of it's own. If anyone knows a easier way to do this then what I'm trying to please let me know. Anyways, I need to be able to choose just one object depending on what object I need. For example, let's say I only need object #5 and not all the array, how can this be done so I can put it into a string? I'm thinking I might have to use the index feature but I'm not sure how to set it up properly. Here is my NSArray that I'm working with: NSArray* myArray = [document selectElements: @"div.someContent"]; NSMutableArray* results = [NSMutableArray array]; for (Element* element in myArray){ NSString* snipet = [element contentsSource]; [results addObject: snipet]; NSLog(@"%@", snipet); } NSLog(@"%i",myArray.count); I've already spent several hours trying to achieve this but my knowledge with array's is limited even with me reading the documentation. :-( Any help is much appreciated. Thanks

    Read the article

  • Array of pointers in Objective-C using NSArray

    - by Amir
    Hello, I am writting program for my iphone and have a qestion. lets say i have class named my_obj class my_obj { NSString *name; NSinteger *id; NSinteger *foo; NSString *boo; } now i allocate 100 objects from type my_obj and insert them to array from type NSArray. then i want to sort the Array in two different ways. one by the name and the second by the id. i want to allocate another two arrays from type NSArray *arraySortByName *arraySortById what i need to do if i just want the sorted arrays to be referenced to the original array so i will get two sorted arrays that point to the original array (that didnt changed!) i other word i dont want to allocate another 100 objects to each sorted array.

    Read the article

  • Altering ManagedObjects In NSArray

    - by Garry
    I have an entity called 'Job' with two boolean attributes named 'completed' and 'logged'. I am trying to retrieve all completed jobs that have not been logged at app start-up and change them to logged. I'm able to get all the completed but unlogged jobs with this fetchRequest: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(completed == %@ && logged == %@)", [NSNumber numberWithBool:YES], [NSNumber numberWithBool:NO]]; I'm then assigning this predicate to a fetchRequest and calling the [managedObjectContext executeFetchRequest:fetchRequest] method to get an array of all Job entities that meet this criteria. This seems to work fine and is returning the correct number of jobs. What I've been trying to do is loop through the NSArray returned, set the logged attribute to YES and then save. This seems to complete and doesn't return any errors but the changes are not persisted when the application quits. Where am I going wrong? [fetchRequest setPredicate:predicate]; NSError error; NSArray jobsToLog = [managedObjectContext executeFetchRequest:fetchRequest error:&error]; if ([jobsToLog count] > 0) { for (int i = 0; i < [jobsToLog count] - 1; i++) { [[jobsToLog objectAtIndex:i] setLogged:[NSNumber numberWithBool:YES]]; // Commit the changes made to disk error = nil; if (![managedObjectContext save:&error]) { // An error occurred } } } Thanks in anticipation,

    Read the article

  • iPhone - Merge keys in a NSArray (Objective-C)

    - by ncohen
    Hi everyone, I'm having troubles with arrays and keys... I have an array from my database: NSArray *elementArray = [[[menuArray valueForKey:@"meals"] valueForKey:@"recipe"] valueForKey:@"elements"] The problem here is that I would like all my elements of all my meals of all my menus in an array such that: [elementArray objectAtIndex:0] = my first element etc... In the example above, the elements are separated by the keys. How can I get that? Hope it's clear enough... Thanks

    Read the article

  • Fastest way to iterate through an NSArray with objects and keys

    - by AppGolfer
    Hello, I have an NSArray called 'objects' below with arrayCount = 1000. It takes about 10 secs to iterate through this array. Does anyone have a faster method of iterating through this array? Thanks! for (int i = 0; i <= arrayCount; i++) { event.latitude = [[[objects valueForKey:@"CLatitude"] objectAtIndex:i] floatValue]; event.longitude = [[[objects valueForKey:@"CLongitude"] objectAtIndex:i] floatValue]; }

    Read the article

  • Objective-C: Loop through NSDictionary to create seperate NSArray's

    - by Nic Hubbard
    I have a large NSDictionary structure that I need to loop through and create seperate NSArray's. Here is the structure: ( { id = { text = ""; }; sub = { text = " , "; }; text = ""; "thumb_url" = { text = ""; }; title = { text = "2010-2011"; }; type = { text = "title"; }; }, { id = { text = "76773"; }; sub = { text = "December 13, 2010"; }; text = ""; "thumb_url" = { text = "http://www.puc.edu/__data/assets/image/0004/76774/varieties/thumb.jpg"; }; title = { text = "College Days - Fall 2010"; }; type = { text = "gallery"; }; }, { id = { text = ""; }; sub = { text = ""; }; text = ""; "thumb_url" = { text = ""; }; title = { text = "2009-2010"; }; type = { text = "title"; }; }, { id = { text = "76302"; }; sub = { text = "December 3, 2010"; }; text = ""; "thumb_url" = { text = "http://www.puc.edu/__data/assets/image/0019/76303/varieties/thumb.jpg"; }; title = { text = "Christmas Colloquy"; }; type = { text = "gallery"; }; } ) Each section has a type key, which I need to check. When it finds the "title" key, I need to add those to an array. Then the next sections that would use the "gallery" key needs to be in its own array until it finds another "title" key. Then the "gallery" keys after that into their own array. I am using this a UITableView section titles and content. So, the NSDictionary above should have one NSArray *titles; array, and two other arrays each containing the galleries that came after the title. I have tried using a for loop but I just can't seem to get it right. And ideas would be appreciated.

    Read the article

  • Sorting a NSArray

    - by Yoot
    Hi, I have a NSArray of objects. Those objects have an int attribute called "distance". I would like to sort my array by distance. Could someone please tell me how to do that ? I can't understand how the sortUsingSelector or sortUsingDescriptor methods are working... Thanks

    Read the article

  • Loading an NSArray on iPhone from a dynamic data base url in PHP or ASP

    - by Brad
    I have a database online that I would like to be able to load into an NSArray in my app. I can use arrayWithContentsOfURL with a static file, but I really need to go to a url that generates a plist file from the database and loading it into the array. I can use ASP or PHP. I tried setting the response type to "text/xml", but that doesn't help. Any thoughts?

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >