nsarray

NSPredicate on nested array with NSDictionary as object

回眸只為那壹抹淺笑 提交于 2019-12-02 04:46:46
i have a NSDictionary like: { "2017-05-02" = ( { "always_valid" = 0; date = "2017-05-02"; from = "12:00"; to = "13:00"; }, { "always_valid" = 0; date = "2017-05-02"; from = "12:00"; to = "12:00"; }, { "always_valid" = 0; date = "2017-05-02"; from = "14:00"; "hourly_rate" = 12; to = "15:00"; } ); "2017-05-03" = ( { "always_valid" = 0; date = "2017-05-03"; from = "12:00"; to = "13:00"; } ); "2017-05-18" = ( { "always_valid" = 1; date = "2017-05-18"; from = "12:00"; to = "12:00"; } ); } i'm trying to apply NSPredicate *filter = [NSPredicate predicateWithFormat:@"always_valid = \"1\""]; NSArray

Objective-C, sorting muti-dimensional arrays

一世执手 提交于 2019-12-02 04:31:07
I've been having some trouble with sorting multi-dimensional arrays in Objective-C. I basically have an array of which every element is an array of the form: (NSString, NSDate, NSString, NSString) such that my top level array has the form: ( (NSString, NSDate, NSString, NSString), (NSString, NSDate, NSString, NSString), (NSString, NSDate, NSString, NSString), (NSString, NSDate, NSString, NSString), ... ) I would like to be able to sort the elements of the top level array based on any of of their own elements. I wrote the following code which does this, but has proven to be far too inefficient

SearchDisplayController search multiple arrays

时光毁灭记忆、已成空白 提交于 2019-12-02 03:03:47
Currently I'm populating my tableviewcells with the contents of multiple arrays representing a name, id, etc. My question comes when I start to use the search display controller. I have an array with a list of names, a list of IDs, a list of barcodes, and a list of Aliases. When the user types in the search bar I need to be able to search all 4 arrays. When it finds the result in 1 array it has to pair the result with the 3 other arrays.. Example Names (apple,carrot,banana, dog) alias (red, orange, yellow, brown) barcode (1,2,10,20) id (30, 40, 50, 60) So if the user types "a" I should

Displaying NSArray of files in a UITableView - iOS 5

一世执手 提交于 2019-12-02 02:46:42
I have an app that allows users to save and open text files. Saving and opening files is fairly straightforward and easy, but I have to give the user an easy way to select a file to open. I decided to do this with a UITableView . When the TableView loads in my view controller, my goal is to populate the TableView with the names of all of the user's text files from within the Documents folder (part of the iOS App Sandbox). I have a general idea of how to do this: Get the contents of the Documents folder and place it in an array NSString *pathString = [[NSBundle mainBundle] pathForResource:@

Iterar over array of entity and get value of some key based on value of “other key” matche

雨燕双飞 提交于 2019-12-02 02:29:05
问题 I have an array of entity class (eg SubmittedAnswer). Its JSON format is look like as below. { "submittedAnswers": [{ "submittedQuestionId": "C7B3C4BE-CC3C-438F-A118-E798884A5FE0", "serialNumber": 4, "option": " it has a very large mass.", "testQuestionId": "55230160-b905-47d5-a91c-e1dda6dd0634", }, { "submittedQuestionId": "9A6E9EA8-1BC0-4ED9-81E8-28B7E554D5E0", "serialNumber": 1, "option": " downward", "testQuestionId": "fd0b3ae0-e999-48a6-89b8-a89b02e7b793", }] } I want to find " option "

Prevent NSRangeException in subarrayWithRange

匆匆过客 提交于 2019-12-02 01:42:01
I have this code which allows me to pass in an index, and selectively retrieve, a number of images in an array for a certain range length - depending on orientation. When in portrait the range should be be 20 items per index, and i have 43 items altogether. However when i pass in the last index, i get an out of range exception for index 59 beyond bounds of [0..42]. NSArray *tempArray = [self imageData]; UIDeviceOrientation devOr = [[UIDevice currentDevice] orientation]; int kItemsPerView; if (UIDeviceOrientationIsPortrait(devOr)) { kItemsPerView = 20; }else { kItemsPerView = 14; } NSRange

Sort an array with special characters - iPhone

≡放荡痞女 提交于 2019-12-02 01:28:41
I have an array with french strings let say: "égrener" and "exact" I would like to sort it such as égrener is the first. When I do: NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES]; NSArray *sortDescriptors = [NSArray arrayWithObject:descriptor]; NSArray *sortedArray = [myArray sortedArrayUsingDescriptors:sortDescriptors]; I get the é at the end of the list... What should I do? Thanks There’s a convenience method in NSString that lets you do this type of sorting easily: NSArray *sortedArray = [myArray sortedArrayUsingSelector:@selector

Case insensitive indexOfObject for NSArray

耗尽温柔 提交于 2019-12-02 00:39:55
Is there an easy way to do a case insensitive lookup in an NSArray of NSStrings? Reference for NSArray mentions sorting case insensitively but nothing about lookup. I can easily write my own fn to do it but would like to know if there's an easier way. I don't know of any built-in way to do this. However, it would be trivial to write a category on NSArray which does this: @interface NSArray (CaseInsensitiveIndexing) - (NSUInteger)indexOfCaseInsensitiveString:(NSString *)aString; @end @implementation NSArray (CaseInsensitiveIndexing) - (NSUInteger)indexOfCaseInsensitiveString:(NSString *)aString

Iterar over array of entity and get value of some key based on value of “other key” matche

微笑、不失礼 提交于 2019-12-02 00:07:15
I have an array of entity class (eg SubmittedAnswer). Its JSON format is look like as below. { "submittedAnswers": [{ "submittedQuestionId": "C7B3C4BE-CC3C-438F-A118-E798884A5FE0", "serialNumber": 4, "option": " it has a very large mass.", "testQuestionId": "55230160-b905-47d5-a91c-e1dda6dd0634", }, { "submittedQuestionId": "9A6E9EA8-1BC0-4ED9-81E8-28B7E554D5E0", "serialNumber": 1, "option": " downward", "testQuestionId": "fd0b3ae0-e999-48a6-89b8-a89b02e7b793", }] } I want to find " option " field from that array whose " submittedQuestionId " is "something....". I dont want to use for loop.

JSONModel returns nil

这一生的挚爱 提交于 2019-12-01 23:29:57
I'mm using JSONModel to get the JSON from the URL. It's a very simple object, containing only 2 strings - "name" and "url". First I made the Object Model: @protocol Tutorial @end @interface Tutorial : JSONModel @property (nonatomic, strong) NSString *name; @property (nonatomic, strong) NSString *url; @end Then Object Feed: #import "JSONModel.h" #import "Tutorial.h" @interface TutorialFeed : JSONModel @property (nonatomic, strong) NSArray <Tutorial> *tutorials; @end and then in MasterViewController.m: #import "MasterViewController.h" #import "DetailViewController.h" #import "TutorialFeed.h"