nsarray

How to convert a JSON array into an NSArray

萝らか妹 提交于 2019-12-08 10:40:02
问题 I've been having trouble finding out how to convert a JSON array into an NSArray. I have a php script that creates an array that is converted into JSON which is then sent and stored into an NSString that looks like: [1,2,3,4] My problem is that I need to make that into an NSArray of ints. How would one do that? Thanks! 回答1: If I wanted to quickly break that into an array I would do it like this: NSString * jstring = @"[1,2,3,4]"; //your json string jstring = [jstring

objective-c why does nslog show strings inbetween double quotation marks “ ”?

蹲街弑〆低调 提交于 2019-12-08 10:19:51
问题 I am loading a nsarray from a textfile: NSArray *noWords = [[NSArray alloc] initWithArray: [[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"untitled" ofType:@"txt"] encoding:NSUTF8StringEncoding error:NULL] componentsSeparatedByString:@"\n"]]; Untitled.txt contains: alfa beta (geologi). beta jaha javel jam (geologi) en jamen jamen jamen jax. (geologi)jammen det var æhæhæ øhøh på tide .(geologi),be;ta; tiden men but men aha beta NSLog (@"noWords : %@", noWords);

Get all dates (not days) between two NSDates

…衆ロ難τιáo~ 提交于 2019-12-08 07:52:56
问题 How can I get all the dates that come in between 2 dates? For example: Start date = 2011/01/25 End date = 2011/02/03 回答1: 1) Find the no of days between two dates. Then, for(i=0;i<noofdays;i++) { //Find the next date //add to the array } To find number of days To find next date 回答2: NSCalendarUnit serves for defining the step between the dates & taking care of the dates being normalized. iOS 8 API, Swift 2.0 func generateDates(calendarUnit: NSCalendarUnit, startDate: NSDate, endDate: NSDate)

Observe value changes of NSDictionary inside NSArray

别等时光非礼了梦想. 提交于 2019-12-08 07:22:40
问题 here's my NSArray carType ( { isSelected = 0; kFieldName = "All types"; kObjectValue = 0; kObjectValueText = All; }, { isSelected = 0; kFieldName = "4 seats"; kObjectValue = 4; kObjectValueText = "4 seats"; }, { isSelected = 1; kFieldName = "7 seats"; kObjectValue = 7; kObjectValueText = "7 seats"; } ) how can I observe the change of isSelected field ? I used KVO in my code but it doesn't work. carType is a NSArray property of context - (void)viewDidLoad { [super viewDidLoad]; [context

How to get last element from NSMutableArray in which status as complete?

故事扮演 提交于 2019-12-08 07:12:45
问题 I have an array of dictionaries in following format [ { "status":"not completed", "rating":2 },{ "status":"completed", "rating":2 },{ "status":"not completed", "rating":"<null>" },{ "status":"completed", "rating":"<null>"},{ "status":"not completed", "rating":"<null>" } ] and from this i want response as last object where status is completed and rating is null output { "status":"completed", "rating":"<null>" } how do i get second element easily without any big iteration. in real case this

NSArray of NSDictionaries - merge dictionaries with same key value pair

一笑奈何 提交于 2019-12-08 06:09:39
问题 I have a NSArray of NSDictionary objects: [ { id = 1; fromDate = 2014-04-03; toDate = 2014-04-05; date = 0000-00-00; title = title 1 }, { id = 1; fromDate = 0000-00-00; toDate = 0000-00-00; date = 2014-04-03 title = title 1 }, { id = 1; fromDate = 0000-00-00; toDate = 0000-00-00; date = 2014-04-04; title = title 1 }, { id = 2; fromDate = 0000-00-00; toDate = 0000-00-00; date = 2014-05-10; title = title 2 }, { id = 2; fromDate = 0000-00-00; toDate = 0000-00-00; date = 2014-05-11; title = title

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

元气小坏坏 提交于 2019-12-08 06:03:44
问题 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? 回答1: You need to use NSPredicate with your second array. NSPredicate *predicate = [NSPredicate predicateWithFormat:@

UITable is not getting populated with NSMutableArray

时光毁灭记忆、已成空白 提交于 2019-12-08 05:41:59
问题 In my app i have a text field where if i enter a word i should get all the file names starting with the particular word into a UITable. Here i am getting these file names into an array and its available in NSLog too... But the table remains empty always. Control is not entering into table(NSLog in tables method is not getting displayed). Can anyone help me? my code is -(IBAction)Do_Search:(id)sender { files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: [[NSBundle mainBundle]

How to sort NSArray of custom objects by a specific property in descending order?

半世苍凉 提交于 2019-12-08 05:13:27
问题 How do I make this piece of code to order in descending order. This code always gives me the array in ascending order: NSArray *sortedProductsByStyle = [unsortedProducts sortedArrayUsingComparator: ^(Product *p1, Product *p2) { return [p1.productStyle compare:p2.productStyle options:NSNumericSearch]; }]; I thought that using NSOrderedDescending would work but it didn't: NSArray *sortedProductsByStyle = [unsortedProducts sortedArrayUsingComparator: ^(Product *p1, Product *p2) { return [p1

tableView:didSelectRowAtIndexPath: call to current-view Parser delegates

我的梦境 提交于 2019-12-08 04:44:53
问题 I have some pretty interesting logic going, basically I have this data which I want to check over before I display the next view.. just in case the data is empty I want to pop the view, if the data is not empty then I want to load the the view to display it onto the navigational stack. so in my tableView:didSelectRowAtIndexPath: method, when the selection is made I, get the current selection ID number so I can restrict the values of the data Im going to parse to only related values. This is