nsmutablearray

Removing last object in NSMutablearray [closed]

心不动则不痛 提交于 2019-12-07 03:10:29
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . Is there any why to remove last object in NSMutablearray without crashing app? :D 回答1: Sure: send the removeLastObject message to a valid NSMutableArray

How to initialize NSArrays / NSMutableArrays when declared as properties

倾然丶 夕夏残阳落幕 提交于 2019-12-07 03:01:05
问题 I need some help in understanding how to use NSArrays / NSMutableArrays as properties. What property attributes should the arrays be : strong or copy ? In which case should I use which attribute? How do I initialize the arrays in code. Should my property array be NSArray or NSMutableArray Currently the way I am doing it 2 different ways as below. But it is all patchy and done with no clear understanding of the mechanics of it. Which one of it is correct or incorrect. Approach 1 .m file

NSKeyedArchiver archivedDataWithRootObject:

可紊 提交于 2019-12-07 02:56:31
问题 Is the parameter for NSKeyedArchiver archivedDataWithRootObject: supposed to be the array I am trying to save, or the array converted into NSData? 回答1: To convert a generic array to an NSData , you need an archiver! If you know how to feed the NSData , you know how to use NSKeyedArchiver . So: NSArray* array= ... ; NSData* data=[NSKeyedArchiver archivedDataWithRootObject:array]; Of course all elements in your array needs to implement encodeWithCoder: . 回答2: Yuji's answer is right. but more

Adding objects to a NSMutableArray property

耗尽温柔 提交于 2019-12-07 02:33:51
问题 this is my data strucure: group [1...n] { id, name, elements : [1...n] } I define a class for element with all properties and a class for group as: @interface Group : NSObject { NSInteger groupID; NSString *groupName; NSMutableArray *elements; } @property (assign, readwrite) NSInteger groupID; @property (assign, readwrite) NSString *groupName; @property (assign, readwrite) NSMutableArray *elements; and single element with: @interface Element : NSObject { NSInteger elementID; NSString

Is “removeAllObjects” supposed to release?

早过忘川 提交于 2019-12-07 02:19:27
I decided to start using removeAllObjects so that I could re-use some of my NSMutableArrays. However, I am finding that the call to removeAllObjects causes the array to get released and so it crashes when the viewController is displayed for the second time. I've looked on the web and it seems that some people are saying that removeAllObjects just clears their array, while others are saying that it also releases the array. Which is true? It appears to release for me, but I find that weird and would expect the behaviour to be just to release the objects within the array. Nothing in the

How to add pointer to an NSObject custom subclass to an NSMutableArray?

余生颓废 提交于 2019-12-07 02:11:27
For the following code snippet from ViewController.m: - (IBAction)buttonAction:(id)sender { CustomButton *button = (CustomButton *)sender; button.associatedObject = [self.sourceOfObjects.objectArray lastObject]; [self.foo.arrayOfObjects addObject:button.associatedObject]; // this does not work? } • CustomButton is subclass of UIButton and has @property (nonatomic, strong) associatedObject that is a pointer to an object of type NSObject. • sourceOfObjects is a @property (nonatomic, strong) of self of type MyCustomObject, a subclass of NSObject. • objectArray is a @property (nonatomic, strong)

NSStirng、NSArray、以及枚举(Method小集合)

蓝咒 提交于 2019-12-06 16:17:46
一下内容由 angellixf 整理 , 这里制作记录 : Object-c 代码 /******************************************************************************************* NSString *******************************************************************************************/ // 一、 NSString /*---------------- 创建字符串的方法 ----------------*/ // 1 、创建常量字符串。 NSString *astring = @ "This is a String!" ; // 2 、创建空字符串,给予赋值。 NSString *astring = [[NSString alloc] init]; astring = @ "This is a String!" ; [astring release]; NSLog(@ "astring:%@" ,astring); // 3 、在以上方法中,提升速度 :initWithString 方法 NSString *astring = [[NSString alloc] initWithString:@

NSMutableArray 可变数组的使用

别等时光非礼了梦想. 提交于 2019-12-06 16:17:20
NSMutableArray 是 NSArray 的一个子类,因此可以在任何使用 NSArray 的位置使用 NSMutableArray。 除了包含在 NSArray 中的方法,NSMutableArray 还提供了修改数组的方法。 // 向数组添加对象 addObject: 和 insertObject:atIndex: // 从数组删除对象 removeAllObjects、removeLastObject 和 removeObjectAtIndex: //替换数组中的某个对象 replaceObjectAtIndex:withObject: //筛选数组 filterUsingPredicate: //重新排列数组中的元素 exchangeObjectAtIndex:withObjectAtIndex:、sortUsingComparator:和sortUsingFunction: context: ps: 数组类 NSArray 和 NSMutableArray 仅能包含对象。 不能将标量数据类型,如 int、long 或者其他任何不是继承自 NSObject 的类型插入 NSArray 或 NSMutableArray。 来源: oschina 链接: https://my.oschina.net/u/2320053/blog/506941

How get objects from one array with same properties of other?

落爺英雄遲暮 提交于 2019-12-06 14:36:28
For example: I have two NSMutableArray . One @[1,2,3,4,5,6,7] . Other have objects like @[ @{@idObjectToSearch":1, @"name":@"aaaaa", @"surname": @"bbbbb"}, @{@idObjectToSearch":2, @"name":@"aaaaa", @"surname": @"ccccc"}, ... @{@idObjectToSearch":100, @"name":@"aaaaa", @"surname": @"cccdcd"} ]; So how I could extract needed objects from second array more effective way? You need to use NSPredicate with your second array. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"idObjectToSearch IN %@", firstArray]; //In above predicate instead of passing `1` you need to pass object from first

Loading the UITableView with different NSMutableArrays

久未见 提交于 2019-12-06 14:31:14
问题 I have, in my view 4 tab buttons. Upon clicking them i have 4 arrays getting populated. Now i need to display these array into the same table. depending on the button click the contents in the table should change. How can this be done? 回答1: add UITabBarControllerDelegate - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { switch (tabBarController.selectedIndex) { case 1: table_mutableArray=nil; [table_mutableArray