nsarray

Sort NSArray of custom objects by their NSDate properties

怎甘沉沦 提交于 2019-11-26 12:43:39
问题 I am attempting to sort an NSArray that is populated with custom objects. Each object has a property startDateTime that is of type NSDate. The following code results in an array, sortedEventArray , populated but not sorted. Am I going about this the completely wrong way or am I just missing something small? NSSortDescriptor *dateDescriptor = [NSSortDescriptor sortDescriptorWithKey:@\"startDateTime\" ascending:YES]; NSArray *sortDescriptors = [NSArray arrayWithObject:dateDescriptor]; NSArray

How to convert NSNumber to NSString

爱⌒轻易说出口 提交于 2019-11-26 12:37:16
问题 So I have an NSArray \"myArray\" with NSNumber s and NSString s. I need them in another UIView so i go like this: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { DetailViewController *details = [[DetailViewController alloc] initWithNibName:@\"DetailView\" bundle:nil]; details.subjectText = [[myArray objectAtIndex:indexPath.row] objectForKey:@\"subject\"]; The subjectText works. But how can I get the NSNumber s out of it? (I actually need them as

Non-retaining array for delegates

我怕爱的太早我们不能终老 提交于 2019-11-26 12:36:52
问题 In a Cocoa Touch project, I need a specific class to have not only a single delegate object, but many of them. It looks like I should create an NSArray for these delegates; the problem is that NSArray would have all these delegates retained, which it shouldn\'t (by convention objects should not retain their delegates). Should I write my own array class to prevent retaining or are there simpler methods? Thank you! 回答1: I found this bit of code awhile ago (can't remember who to attribute it to)

Best practice? - Array/Dictionary as a Core Data Entity Attribute [closed]

一世执手 提交于 2019-11-26 11:58:36
I am new to Core Data. I have noticed that collection types are not available as attribute types and would like to know what the most efficient way is of storing array/dictionary type data as an attribute (e.g. the elements that make up an address like street, city, etc. does not require a separate entity and is more conveniently stored as a dictionary/array than separate attributes/fields). Thank you. There is no "native" array or dictionary type in Core Data. You can store an NSArray or an NSDictionary as a transformable attribute. This will use the NSCoding to serialize the array or

Array of tuples in Swift

ε祈祈猫儿з 提交于 2019-11-26 11:29:50
问题 I have a function: func parseJSON3(inputData: NSData) -> NSArray { var tempDict: (id:Int, ccomments:Int, post_date:String, post_title:String, url:String) = (id: 0, ccomments: 0, post_date: \"null\", post_title: \"null\", url: \"null\") var resultArray: (id:Int, ccomments:Int, post_date:String, post_title:String, url:String)[] = [] var error: NSError? var jsonDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(inputData, options: NSJSONReadingOptions.MutableContainers, error:

Serialize and Deserialize Objective-C objects into JSON

眉间皱痕 提交于 2019-11-26 10:35:43
问题 I need to serialize and deserialize objective-c objects into JSON to store in CouchDB. Do people have any example code for best practice for a general solution? I looked at a few JSON framework and they are stopped at the NSDictionary/NSArray level. i.e. A lot of framework will serialize and deserialize NSDictionary/NSArray into JSON. But I still have to do the work to convert NSDictionary into Objective-C objects. To make things more complex, my Object A can have reference to an NSArray

Rebuild an NSArray by grouping objects that have matching id numbers?

百般思念 提交于 2019-11-26 09:43:27
问题 I have an NSArray and each object in the array has a groupId and a name. Each object is unique but there are many with the same groupId. Is there a way i can tear the array apart and rebuild it so that the names are grouped into a single object with the corresponding groubId? Here is what the array currently looks like: 2013-03-12 20:50:05.572 appName[4102:702] the array: ( { groupId = 1; name = \"Dan\"; }, { groupId = 1; name = \"Matt\"; }, { groupId = 2; name = \"Steve\"; }, { groupId = 2;

Compiler error “expected method not found” when using subscript on NSArray

家住魔仙堡 提交于 2019-11-26 09:35:29
问题 I wrote this simple code to try out the new Objective-C literal syntax for NSArray s: NSArray *array = @[@\"foo\"]; NSLog(@\"%@\", array[0]); The first line works fine, but the subscripting results in an error: Expected method to read array element not found on object of type \'NSArray *\' Just wondering if I have done something wrong, or if the literals haven\'t been fully implemented yet. I\'m compiling with Apple LLVM 4.0 and using the iOS 5 SDK. Here\'s a screenshot of the error, too. 回答1

Getting a random object from NSArray without duplication

醉酒当歌 提交于 2019-11-26 09:13:45
问题 I have an NSArray with 17 objects, something like this: NSArray *objArray = [[NSArray alloc]initWithObjects: @\"1\",@\"2\",@\"3\",@\"4\",@\"5\",@\"6\" ,@\"7\",@\"8\",@\"9\",@\"10\",@\"11\",@\"12\",@\"13\",@\"14\",@\"15\",@\"16\",@\"17\", nil]; and an int with a random number as follows: int random = arc4random()%17+1; I want to get a random object from this NSArray without it being a duplicate, even if I closed the app (maybe by using NSUserDefaults ). If I\'ve gotten all the objects I want

Sorting NSArray of dictionaries by value of a key in the dictionaries

本秂侑毒 提交于 2019-11-26 08:53:32
问题 I have an array populated by dictionaries, and I need to sort the array alphabetically by the values of one of the keys of the dictionaries. This is my array: tu dictus: ( { brand = Ryul; productTitle = Any; quantity = 1; subBrand = \"Ryul INJ\"; type = Product; }, { brand = Trol; productTitle = Different; quantity = 2; subBrand = \"\"; type = Brand; }, { brand = Dtor; productTitle = Any; quantity = 1; subBrand = \"\"; type = Product; }, { brand = Ryul; productTitle = Different; quantity = 2;