nsarray

NSArray @property backed by a NSMutableArray

别来无恙 提交于 2019-12-03 09:21:01
I've defined a class where I'd like a public property to appear as though it is backed by an NSArray . That is simple enough, but in my case the actual backing ivar is an NSMutableArray : @interface Foo { NSMutableArray* array; } @property (nonatomic, retain) NSArray* array; @end In my implementation file ( *.m ) I @synthesize the property but I immediately run into warnings because using self.words is the same as trying to modifying an NSArray . What is the correct way to do this? Thanks! I would declare a readonly NSArray in your header and override the getter for that array to return a copy

Initialize Array of Objects using NSArray

雨燕双飞 提交于 2019-12-03 09:20:48
I'm pretty new to Objective-C and iOS so I've been playing around with the Picker View. I've defined a Person Class so that when you create a new Person it automatically gives that person a name and age. #import "Person.h" @implementation Person @synthesize personName, age; -(id)init { self = [super init]; if(self) { personName = [self randomName]; age = [self randomAge]; } return self; } -(NSString *) randomName { NSString* name; NSArray* nameArr = [NSArray arrayWithObjects: @"Jill Valentine", @"Peter Griffin", @"Meg Griffin", @"Jack Lolwut", @"Mike Roflcoptor", @"Cindy Woods", @"Jessica

Populate tableview from NSDictionary

孤者浪人 提交于 2019-12-03 09:00:58
I have an NSDictionary received from a json request that looks like this: RESULT : ( { Id1 = 138; lat = "45.5292910"; long = "-73.6241500"; order = "2343YY3" }, { Id1 = 137; lat = "45.5292910"; long = "-73.6241500"; order = "2343YY3" }, etc. I want to display it in a TableView (CellforRowAtIndexPath), so I obtain the data as NSArray. The method seems inefficient as each key Id1 , lat , long , etc is created as an NSArray so that I can display them each with: [self.data1 objectAtIndex:indexPath.row]; [self.data2 objectAtIndex:indexPath.row] , etc. How can I achieve the same thing without

iPhone SDK Xcode - How to get all the filenames in the documents dir

此生再无相见时 提交于 2019-12-03 08:24:24
I want to get all the filenames in my application's documents folder, and place them in an NSMutableArray . Nothing more, nothing less. There is a convenient method in NSFileManager : NSFileManager *fileManager = [[NSFileManager alloc] init]; NSArray *files = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:nil]; ... [fileManager release]; As of ARC you can of course drop the release statement. 来源: https://stackoverflow.com/questions/7064190/iphone-sdk-xcode-how-to-get-all-the-filenames-in-the-documents-dir

Sorting Array Using NSSortDescriptor [duplicate]

好久不见. 提交于 2019-12-03 08:02:11
This question already has answers here : How to sort NSMutableArray of date objects (3 answers) I have an array of class A objects, let it be detailsArray. Class A has date, name as properties. Can any one suggest a good method to sort this array based on date? How can I use NSSortDescriptor to sort this array? I know sorting array of dictionary using NSSortDescriptor ... Any help is greatly appreciated..... Nick C NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:NO]; NSArray *sortedArray = [detailsArray sortedArrayUsingDescriptors:@[sortDescriptor]]

Loading Array From .Plist

江枫思渺然 提交于 2019-12-03 07:53:00
I'm trying to load my array from an array in my .Plist but its not working. The plist looks like this: This is the code I'm using: NSString *path = [[NSBundle mainBundle]pathForResource:@"DiseasePropertyList" ofType:@"plist"]; NSMutableArray *rootLevel = [[NSMutableArray alloc]initWithContentsOfFile:path]; self.myArray = rootLevel; [rootLevel release]; Try this. Please change file name. It works fine. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *recentFilePath =

Swift - read plist file to an array?

ⅰ亾dé卋堺 提交于 2019-12-03 07:31:56
I have created a mini translation from English words to Spanish words. I would like to use the englishArray.plist instead of my englishArray = ["the cat"] How can I create this? I have also used a localizable.strings to retrieve the value "the cat" for "el gato" but I would like to retrieve this from englishArray.plist I started off with this but not sure if I'm on the right path let path = NSBundle.mainBundle().pathForResource("englishArray", ofType: "plist") let plistEnglishArray = NSArray(contentsOfFile: path!) Here is the rest of my code: var englishArray: [String] = ["rainbow", "boots",

NSArray adding elements

六月ゝ 毕业季﹏ 提交于 2019-12-03 06:30:27
问题 I have to create a dynamic NSArray, that is, I don't know the size of the array or what elements the array is going to have. The elements need to be added to the array dynamically. I looked at the NSArray class reference. There is a method called arrayWithObjects, which should be used at the time of initializing the array itself. But I don't know how to achieve what I need to do. I need to do some thing like the following: NSArray *stringArray = [[NSArray init] alloc] ; for (int i = 0; i <

UITableView Animation Headache

試著忘記壹切 提交于 2019-12-03 06:06:55
问题 NSIndexPath* updatedPath = [NSIndexPath indexPathForRow: 0 inSection: 0]; NSIndexPath* updatedPath2 = [NSIndexPath indexPathForRow: 1 inSection: 0]; NSArray* updatedPaths = [NSArray arrayWithObjects:updatedPath, updatedPath2, nil]; [self.mySexyTableView reloadRowsAtIndexPaths:updatedPaths withRowAnimation:UITableViewRowAnimationTop]; The above code works and it animates. The problem is that I have lot of data and I don't want to hard-code the row indexes. Since I have only one section in my

How can I get all values for specific key from each NSDictionary in an NSArray? [duplicate]

▼魔方 西西 提交于 2019-12-03 05:42:01
问题 This question already has an answer here : How to get values from NSDictionaries inside an NSArray (1 answer) Closed 6 years ago . I have an array which contains dictionary objects. In each dictionary the key are common. Now I want to get all the values of that key. I have got these values with iteration, but I am looking for some straight forward way or a default method which does this job. Can you please help me to get one default method which serves the purpose? Thanks. Data Structure is