nsmutablearray

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

Synchronizing NSMutableArray for Thread Security ?

烈酒焚心 提交于 2019-11-27 12:28:52
问题 I have a Threaded application, in which there is a NSMutableArray , which contains the NSManagedObjects , Now i want my array to be accessed once at a time by any Thread. So how do i synchronize that array, or may be put locking mechanism on it. Thanks in Advance ... 回答1: You could wrap every access to the class with something like the following: @synchronized(myArray) { [myArray doSomething]; } 来源: https://stackoverflow.com/questions/3521190/synchronizing-nsmutablearray-for-thread-security

Storing CLLocationCoordinates2D in NSMutableArray

廉价感情. 提交于 2019-11-27 11:43:02
问题 After some searching, I got the following solution : reference. CLLocationCoordinate2D* new_coordinate = malloc(sizeof(CLLocationCoordinate2D)); new_coordinate->latitude = latitude; new_coordinate->longitude = longitude; [points addObject:[NSData dataWithBytes:(void *)new_coordinate length:sizeof(CLLocationCoordinate2D)]]; free(new_coordinate); And access it as: CLLocationCoordinate2D* c = (CLLocationCoordinate2D*) [[points objectAtIndex:0] bytes]; However, someone claims that there is a

How can i get Original order of NSDictionary/NSMutableDictionary?

北慕城南 提交于 2019-11-27 09:27:59
i have created NSMutableDictionary with 10 keys.Now i want to access NSMutableDictionary keys in a same order as it was added to NSMutableDictionary (using SetValue:* forKey:* ); How can i achieve that ? If you absolutely must use a dictionary container, you have to use a key that is sortable by the order in which you add key-value pairs. Thus, when creating your dictionary, you use a key that is an auto-incrementing integer or similar. You can then sort on the (integer) keys and retrieve the values associated with those keys. If you do all of that, however, you may as well just use an

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

倖福魔咒の 提交于 2019-11-27 09:18:10
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]

How to Print out(NSLog) the properties of a custom object added to a NSMutableArray

China☆狼群 提交于 2019-11-27 07:38:41
问题 I have a custom object that I create with 3 properties defined in it. I create the object and assign the values to those properties. After that I put that object into an NSMutable Array . I know I can use : for (id obj in personArray) { NSLog(@"obj: %@", obj); } NSLog(@"%@", personArray); To tell me what kind of objects are in my array. But I want to go a level deeper, I want to be able to see what the properties are for each of those objects. I'm just not sure how to target them. Here is the

Why can't I return an object from my block?

六月ゝ 毕业季﹏ 提交于 2019-11-27 07:29:35
问题 I'm trying to return a NSMutableArray from my block in my method, but when I add the line return [responseString JSONValue]; , I get some compiler warnings. - (NSMutableArray*)getTodayData:(NSDate*)today { ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease]; [request setPostValue:[dateFormat stringFromDate:today] forKey:@"target_date"]; NSError *error = [request error]; [request setCompletionBlock:^{ NSString *responseString; if (!error) { responseString =

How to wrap a Struct into NSObject

风格不统一 提交于 2019-11-27 06:27:37
this is supposed to be trivial… I think, but I can't find a way how to wrap a Struct variable into an NSObject . Is there a method to do so? If not, how would I go about adding a struct into an NSMutableArray ? Thanks. Rpranata Hm, try to look at the NSValue at https://developer.apple.com/documentation/foundation/nsvalue You can use it like struct aStruct { int a; int b; }; typedef struct aStruct aStruct; Then sort of "wrap" it to an NSValue object like: aStruct struct; struct.a = 0; struct.b = 0; NSValue *anObj = [NSValue value:&struct withObjCType:@encode(aStruct)]; NSArray *array = @[anObj]

NSMutableArray addObject: -[__NSArrayI addObject:]: unrecognized selector sent to instance

痞子三分冷 提交于 2019-11-27 06:22:22
I have tried to initialize my NSMutableArray 100 ways from Sunday, and NOTHING is working for me. I tried setting it equal to a newly allocated and initialized NSMutableArray, just allocating, initializing the variable by itself, every combination I could think of and always the same result. Here's the code: Object.h NSMutableArray *array; @property (copy) NSMutableArray *array; Object.m @synthesize array; if ( self.array ) { [self.array addObject:anObject]; } else { self.array = [NSMutableArray arrayWithObjects:anObject, nil]; } NOTE: In debug "anObject" is NOT nil at time of execution... I

iPhone - Crash using addObject on a NSMutableArray

梦想与她 提交于 2019-11-27 06:22:11
问题 I have a problem here. Or Maybe I'm really tired... I have a class : @interface THECLASS : UIViewController <UITableViewDelegate> { NSMutableArray* param; } @property(nonatomic, retain) NSMutableArray* param; Inside that class I have a method that is called when the user clicks on a UISwitch inside a tableViewCell (I build the params into a IBAction method that is not shwon here) : @synthesize param; - (void) changedSelectorValue:(NSIndexPath*)indexPath isOn:(BOOL)isOn { [self.param addObject