nsmutablearray

Undo with multitouch drawing in iOS

独自空忆成欢 提交于 2019-11-26 18:36:25
问题 I am working with multitouch while writing, So basically what I am doing is, I am writing with hand support, because typically, its how user rights, I followed this link How to ignore certain UITouch Points in multitouch sequence Everything is working fine, but their is some problem with undo when I write with my hand touching the screen, otherwise it works fine. Below is my code -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch* topmostTouch = self.trackingTouch; for

insert object in an NSMutableArray saved with NSUserDefaults

坚强是说给别人听的谎言 提交于 2019-11-26 17:10:11
问题 I have an NSMutableArray saved with NSUserDefaults. This array is my "favourite" items that the user can saves, so when i want to add one item, i need to read the array (from NSuserDefault) and save in the first free position. I'm using this method to add a value in the NSMutableArray -(IBAction)save{ NSMutableArray *abc = [[NSUserDefaults standardUserDefaults] objectForKey:@"12345"]; int n = [abc count]; [abc insertObject:@"aaa" atIndex:n]; NSUserDefaults *defaults = [NSUserDefaults

Order two NSMutableArrays based on one

淺唱寂寞╮ 提交于 2019-11-26 16:56:28
问题 I have two NSMutableArrays. The content of the first is numerically, which is paired to the content of the second one: First Array Second Array 45 Test45 3 Test3 1 Test1 10 Test10 20 Test20 That's the look of both arrays. Now how could I order them so numerically so they end up like: First Array Second Array 1 Test1 3 Test3 10 Test10 20 Test20 45 Test45 Thanks! 回答1: I would put the two arrays into a dictionary as keys and values. Then you can sort the first array (acting as keys in the

UIBezierPath Multiple Line Colors

℡╲_俬逩灬. 提交于 2019-11-26 16:56:02
问题 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]

Objective-C中NSArray类的解读

旧城冷巷雨未停 提交于 2019-11-26 16:01:07
Objective-C中NSArray类的解读 NSArray数组类是Objective-C语言中常用的也是重要的一个类,除了开发中常用到的一些基础功能,NSArray及其相关类中还封装了许多更加强大的功能。有机会总结了一下,与需要的朋友们分享。 NSArray中属性与方法: //获取数组中元素个数 @property (readonly) NSUInteger count; //通过下标获数组中的元素 - (ObjectType)objectAtIndex:(NSUInteger)index; //初始化方法 - (instancetype)init; //通过C语言风格的数组创建NSArray对象 需要注意,C数组中需要为Objective对象,cnt参数为C数组的长度 //如果cnt的值小于C数组的长度,则会对C数据进行截取赋值,如果大于则程序会崩溃 - (instancetype)initWithObjects:(const ObjectType [])objects count:(NSUInteger)cnt; //数组的归档方法 - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder; //像数组中追加一个元素 这个方法会返回一个新的数组 - (NSArray<ObjectType> *

How can i get Original order of NSDictionary/NSMutableDictionary?

你说的曾经没有我的故事 提交于 2019-11-26 14:45:49
问题 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 ? 回答1: 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

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

淺唱寂寞╮ 提交于 2019-11-26 14:39:42
问题 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

NSMutableArray - force the array to hold specific object type only

ⅰ亾dé卋堺 提交于 2019-11-26 12:56:07
Is there a way to force NSMutableArray to hold one specific object type only? I have classes definitions as follow: @interface Wheel:NSObject { int size; float diameter; } @end @interface Car:NSObject { NSString *model; NSString *make; NSMutableArray *wheels; } @end How can I force wheels array to hold Wheel objects only with code? (and absolutely not other objects) Update in 2015 This answer was first written in early 2011 and began: What we really want is parametric polymorphism so you could declare, say, NSMutableArray<NSString> ; but alas such is not available. In 2015 Apple apparently

Dictionary in Swift with Mutable Array as value is performing very slow? How to optimize or construct properly?

那年仲夏 提交于 2019-11-26 12:17:28
问题 I am trying to build a data structure in Swift that maps an Integer to an array of objects (a dictionary with int as key and array as value). The objects are extremely small, and they simply wrap a UIColor and an Int. I have two implementations one that uses a Swift array as the Dictionary\'s value type, while the other uses a NSMutableArray as the value type. My objective-C code performs extremely fast, but my Swift code is running egregiously slow. Ideally, I would not like to use an

is it possible to save NSMutableArray or NSDictionary data as file in iOS?

大城市里の小女人 提交于 2019-11-26 12:09:27
问题 I want to save an NSMutableArray or NSDictionary as a permanent file. Then, I would like to reopen the file later. Is this possible? If so, how can I do it? 回答1: To write in file NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *filePath = [documentsDirectory stringByAppendingPathComponent:FILE_NAME]; [myArray writeToFile:filePath atomically:YES]; To read from file NSArray *paths