nsarray

UIBezierPath Multiple Line Colors

喜你入骨 提交于 2019-11-27 14:50:46
My attempt to draw UIBezierPath lines with different colors is failing me. All the lines change to the currently selected color. All my path and information are all stored in an NSMutableArray called pathInfo. In path info I drop in array that contains the Path, Color, Width, and Type of line. This works fine except all the lines turn to whatever color the user has selected. I would appreciate any help greatly! - (void)drawRect:(CGRect)rect { UIBezierPath *drawPath = [UIBezierPath bezierPath]; drawPath.lineCapStyle = kCGLineCapRound; drawPath.miterLimit = 0; for (int i = 0; i < [pathInfo count

removing duplicates from array in objective c

孤人 提交于 2019-11-27 14:24:55
I have an array with custom objects. Each array item has a field named "name". Now I want to remove duplicate entries based on this name value. How should I go about achieving this. Thanks in advance. You might have to actually write this filtering method yourself: @interface NSArray (CustomFiltering) @end @implementation NSArray (CustomFiltering) - (NSArray *) filterObjectsByKey:(NSString *) key { NSMutableSet *tempValues = [[NSMutableSet alloc] init]; NSMutableArray *ret = [NSMutableArray array]; for(id obj in self) { if(! [tempValues containsObject:[obj valueForKey:key]]) { [tempValues

Flatten an NSArray

拟墨画扇 提交于 2019-11-27 14:19:57
I have an array like this: array: ( ( "http://aaa/product/8_1371121323.png", "http://aaa/product/14_1371123271.png" ), ( "http://aaa/product/9_1371121377.png" ) ) and I have to create another array from that one like this array: ( "http://aaa/product/8_1371121323.png", "http://aaa/product/14_1371123271.png", "http://aaa/product/9_1371121377.png" ) How can I do that? Is it possible to combine all the objects and separate them using some string? Sample Code : NSMutableArray *mainArray = [[NSMutableArray alloc] init]; for (int i = 0; i < bigArray.count ; i++) { [mainArray addObjectsFromArray:

Searching NSArray of NSDictionary objects

﹥>﹥吖頭↗ 提交于 2019-11-27 14:03:41
I've contacts array where each contact is a dictionary. Each contact has a key "contact_type" which is an NSNumber. Contact type basically represents whether its a Facebook, LinkedIn or Mail contact etc. I've a search array which holds only NSNumber of contact_type's. What I want is to make a temporary array of contacts which I want to search using my search array. I am facing trouble using NSPredicate to create searched contacts array. Can some one guide me on how to do it? NSArray *contacts = ...; //your array of NSDictionary objects NSPredicate *filter = [NSPredicate predicateWithFormat:@

How to sort NSArray of objects based on one attribute

时间秒杀一切 提交于 2019-11-27 13:54:24
I am trying to sort an array of managed objects alphabetically. The attribue that they need to be sorted by is the name of the object (NSString) with is one of the managed attributes. Currently I am putting all of the names in an array of strings and then using sortedNameArray = [sortedNameArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; and then enumerating them back into an array with the objects. This falls apart when two names are the same so I really need to be able to sort by one attribute. How should I go about doing this? Dancreek Use NSSortDescriptor. Just

Convert NSArray to NSDictionary

十年热恋 提交于 2019-11-27 12:17:48
How can I convert an NSArray to an NSDictionary , using an int field of the array's objects as key for the NSDictionary ? - (NSDictionary *) indexKeyedDictionaryFromArray:(NSArray *)array { id objectInstance; NSUInteger indexKey = 0U; NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] init]; for (objectInstance in array) [mutableDictionary setObject:objectInstance forKey:[NSNumber numberWithUnsignedInt:indexKey++]]; return (NSDictionary *)[mutableDictionary autorelease]; } Try this magic: NSDictionary *dict = [NSDictionary dictionaryWithObjects:records forKeys:[records

What is __NSArrayI and __NSArrayM? How to convert to NSArray?

£可爱£侵袭症+ 提交于 2019-11-27 12:03:50
What is __NSArrayI and __NSArrayM? __NSArrayI(or M) cause "unrecognized selector" error. How to convert to NSArray? I did test to parse json, twitter api. http://api.twitter.com/1/followers/ids.json?cursor=-1&screen_name=twitterapi ==> works fine. parsed object is NSCFDictionary class. (This dictionary contains __NSArrayM class) http://api.twitter.com/1/statuses/user_timeline.json?&screen_name=twitterapi ==> error. parsed object is __NSArrayM class. __NSArrayI is a code-word for an immutable array - that is, a "regular" NSArray which you cannot change. __NSArrayM is a code-word for a mutable

NSArray writeToFile fails

半腔热情 提交于 2019-11-27 11:40:22
问题 I am trying to save an array, which has some dictionaries inside, to a plist file but it fails. I don't get any errors. I do exactly the same few lines above in the code just with another array and that works.. I can't figure out why it does not save the file. This is where I save the file: (see some debugger output below) // When built parse through dictionary and save to file for ( NSString *keys in [dicByCountry allKeys] ) { NSArray *arrr = [[NSArray alloc] initWithArray:[dicByCountry

Search through NSArray for string

这一生的挚爱 提交于 2019-11-27 10:23:23
问题 I would like to search through my NSArray for a certain string. Example: NSArray has the objects: "dog", "cat", "fat dog", "thing", "another thing", "heck here's another thing" I want to search for the word "another" and put the results into one array, and have the other, non results, into another array that can be filtered further. 回答1: Not tested so might have a syntax error, but you'll get the idea. NSArray* inputArray = [NSArray arrayWithObjects:@"dog", @"cat", @"fat dog", @"thing", @

Getting Index of an Object from NSArray?

怎甘沉沦 提交于 2019-11-27 10:04:55
问题 i am trying to get index of an array through indexOfObject method as follows but when i try to log the value to test the index i get a garbage value.. for testing purposes i am having an array with values {57,56,58..} to get an index of lets say 56 , NSNumber *num = [NSNumber numberWithInteger:56]; NSInteger Aindex = [myArray indexOfObject:num]; NSLog(@" %d",Aindex); the value i get is something like 2323421 . what am i possibly doing wrong?? 回答1: The index returned by indexOfObject will be