nsmutablearray

how to change order of NSMutable array in same way another mutable arrays get changed

徘徊边缘 提交于 2019-12-04 02:35:26
问题 I have three arrays . They are name , birthdates and remaining days like below: name birthdate remaining "Abhi Shah", "01/14", 300 "Akash Parikh", "12/09/1989", 264 "Anand Kapadiya", "12/01", 256 "Annabella Faith Perez", "03/02", 347 "Aysu Can", "04/14/1992", 25 "Chirag Pandya" "10/07/1987" 201 I want to rearrange the remaining days array into ascending order, but at the same time name and birthdate should also get reordered in the same way. See this example below: name birthdate remaining

How to initialize a NSMutableArray in Objective C?

浪子不回头ぞ 提交于 2019-12-04 01:24:59
I come from a Java background and I am learning Objective C. I am trying to create a class that has a string array and a member function to modify the Array. My code looked like this: @implementation TAWChapter @synthesize mSubject; @synthesize mItems; - (id) init{ self.mItems = [[NSMutableArray alloc] init]; return self; } - (void) setSubject:(NSString *)subject{ self.mSubject = subject; } - (void) addItem:(NSString *)item{ [self.mItems addObject:@"asdf"]; } @end Which didn't work. I got a "[__NSArrayI addObject:]: unrecognized selector sent to instance " and a "NSInvalidArgumentException" .

Finding out NSArray/NSMutableArray changes' indices

泄露秘密 提交于 2019-12-04 01:09:34
问题 I have a NSMutableArray oldArray . Now, at one point, this NSMutableArray object gets updated with another NSMutableArray , which may have more, less or same number of elements as the previous NSMutableArray . I want to compare the old and the new array for changes. What I want are two NSArray s addedArray and removedArray which will contain the indices of the elements which have been added and/or removed from the old array. This whole problem will be more clear with an example : oldArray = {

iOS 笔试题~两个有序数组合并成一个有序数组

不打扰是莪最后的温柔 提交于 2019-12-04 00:55:33
// 联系人 : 石虎 QQ: 1224614774 昵称 : 嗡嘛呢叭咪哄 面试题 : 怎样把两个有序数组合并成有序数组呢 逻辑步骤 : 1. 假设两个数组为 A 和 B 2.A 和 B 都是从小到大的顺序进行排列 ** 1. 我们可以直接比较两个数组的首元素,哪个小就把这个小元素放入可变数组。 2. 把小元素所在的数组中的这个元素删除。 3. 继续比较两个数组中的首元素,直到有一个数组为空。那么就停止进行比较。把另外一个不空的数组元素全部放入可变数组中即可。 实现代码: - (void)viewDidLoad { [super viewDidLoad]; // 实例化数组 A NSMutableArray *arrA = [NSMutableArray arrayWithArray:@[@1,@3,@5,@7,@9,@11]]; // 实例化数组 B NSMutableArray *arrB = [NSMutableArray arrayWithArray:@[@8,@15,@17,@20,@22,@35]]; //新数组 NSMutableArray *marr = [NSMutableArray array]; //开始遍历 for(int i = 0; i< 100; i++) { if (arrA[0] < arrB[0]) { [marr addObject:arrA

iPhone: Using a NSMutableArry in the AppDelegate as a Global Variable

烈酒焚心 提交于 2019-12-03 21:57:54
What i'm trying to accomplish is to have an NSMutableArray defined in the AppDelegate. I then have two UIViewControllers. One view is responsible for displaying the array from the AppDelegate. The other view is used to add items to the array. So the array starts out to be empty. View1 doesn't display anything because the array is empty. The User goes to View2 and adds an item to the array in AppDelegate. Then when the user goes back to View1 it now displays one item. Here is how I'm trying to accomplish this @interface CalcAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window;

NSMutableArray addobject with malloc'd struct

假如想象 提交于 2019-12-03 21:47:03
I'm having trouble with a snippet of code. I'm trying to add an instance of CLLocationCoordinate2D to a NSMutable array using the addObject method, but whenever the line is executed, my app crashes. Is there anything obvious wrong with this code? The crash is on this line: [points addObject:(id)new_coordinate]; Polygon.m: #import "Polygon.h" @implementation Polygon @synthesize points; - (id)init { self = [super init]; if(self) { points = [[NSMutableArray alloc] init]; } return self; } -(void)addPointLatitude:(double)latitude Longitude:(double)longitude { NSLog(@"Adding Coordinate: [%f, %f] %d"

Multiple Arrays From Plist

做~自己de王妃 提交于 2019-12-03 21:42:34
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <array> <array> <string>Title 1</string> <string>Subtitle 1</string> <string>image1.png</string> </array> <array> <string>Title 2</string> <string>Subtitle 2</string> <string>image2.png</string> </array> </array> </plist> This is my Plist file for an app I am working on. I am not sure on how to take the first string of many arrays to create an NSMutableArray with all the titles and again for the subtitles and image names. My

Nested arrays in Objective-C ( NSMutableArray )

依然范特西╮ 提交于 2019-12-03 21:23:35
I'm trying to build a nested array: First, I make a "PlayerItems" array which will contain 10 arrays, each containing item objects, corresponding to the inventories of each player in the game. On the indicated line, I get the following error: error: void valued not ignored as it ought to be What is the void value here? If I used [[PlayerItems objectAtIndex:i] addObject:myitem] instead, the program compiles but crashes. If I comment that line out, it compiles and runs OK. Thank you for your help! self.PlayerItems = [[NSMutableArray alloc] initWithCapacity:11]; NSMutableArray *itemarray = [

How to sort an NSMutableArray of objects by a member of its class, that is an int or float

走远了吗. 提交于 2019-12-03 21:20:08
问题 I have a class (from NSObject ) that contains: NSString name int position float speed I then create an array ( NSMutableArray ) of objects from this class. I would like to then sort the array by the 'speed' value, which is a float . I initially has the float value as an NSNumber and the int as NSInteger , and I was successfully sorting with: [myMutableArray sortUsingFunction:compareSelector context:@selector(position)]; where myMutableArray is my array of objects. here is the function: static

How to add observer on NSMutableArray?

非 Y 不嫁゛ 提交于 2019-12-03 18:30:25
问题 I have searched a lot but didn't find useful code or tutorial. In my application, I have an mutable array which update in every 60 seconds. The objects in array is being displayed by table view in multiple view controllers. I want to reload table view automatically when only when values in array changes or updated. For this, I want to add observer on mutable array i.e when values in array changes then it should call a particular method for e.g -(void)ArrayUpdatedNotification:(NSMutableArray*