Я надеюсь, что кто-то может помочь, я нахожусь на своем пути, пытаясь понять это!Нужно перезагрузить/пересчитать NSArray
В основном у меня есть передача JSON-данных в файл NSDictionary
с дополнительным файлом (.h и .m), добавляющим некоторые условные поля относительно текущего времени. Мне нужно обновлять/обновлять условные поля каждые x минут без перезагрузки/вытягивания данных из канала JSON. Вместо этого я хотел бы повторно запустить условный тест и обновить базу данных с первоначально созданной базой данных.
У кого-нибудь есть подсказка, как это сделать, я всюду исследую и не могу найти ответ!
FYI здесь условный аргумент, чтобы установить дополнительные поля/сущности в базе данных:
//
// Entity.m
// tabbed
//
// Created by administrator on 16.07.12.
// Copyright (c) 2012 __HappyTimes__. All rights reserved.
//
#import "RestarauntEntity.h"
#import "NSDate+DeviceDate.h"
@implementation RestarauntEntity
@synthesize city = _city;
@synthesize closingTime = _closingTime;
@synthesize description = _description;
@synthesize lattitude = _lattitude;
@synthesize longditude = _longditude;
@synthesize openingState = _openingState;
@synthesize openingTime = _openingTime;
@synthesize phoneNumber = _phoneNumber;
@synthesize thumbnailUrl = _thumbnailUrl;
@synthesize title = _title;
@synthesize website = _website;
- (id)initWithDictionary:(NSMutableDictionary *) dictionary
{
self = [super init];
if (self) {
_title = [dictionary objectForKey:@"title"];
_description = [dictionary objectForKey:@"content"];
_thumbnailUrl = [dictionary objectForKey:@"thumbnail"];
_city = [[[dictionary objectForKey:@"custom_fields"] objectForKey:@"City"] objectAtIndex:0];
_phoneNumber = [[[dictionary objectForKey:@"custom_fields"] objectForKey:@"Phone Number"] objectAtIndex:0];
_website = [[[dictionary objectForKey:@"custom_fields"] objectForKey:@"Address"] objectAtIndex:0];
// get opening/closing time values
NSString *currentWeekDayName = [NSDate currentDayOfTheWeekInEnglish];
NSString *openingTimeForCurentDay = [NSString stringWithFormat:@"%@ Opening Time", currentWeekDayName];
NSString *closingTimeForCurentDay = [NSString stringWithFormat:@"%@ Closing Time", currentWeekDayName];
_openingTime = [[[dictionary objectForKey:@"custom_fields"] objectForKey:openingTimeForCurentDay] objectAtIndex:0];
_closingTime = [[[dictionary objectForKey:@"custom_fields"] objectForKey:closingTimeForCurentDay] objectAtIndex:0];
// Prepare current day string in format yyyy-MM-dd
NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
[timeFormat setDateFormat:@"yyyy-MM-dd "];
[timeFormat setPMSymbol:@"pm"];
[timeFormat setAMSymbol:@"am"];
NSDate *now = [[NSDate alloc] init];
NSString *currentDay = [timeFormat stringFromDate:now];
// Find full date for opening and close time
[timeFormat setDateFormat:@"yyyy-MM-dd hh:mm a"];
NSDate *openingTimeDate = [timeFormat dateFromString:[currentDay stringByAppendingString:_openingTime]];
NSDate *closingTimeDate = [timeFormat dateFromString:[currentDay stringByAppendingString:_closingTime]];
// Find out opening state of the restaraunt
if(([openingTimeDate compare:now] == NSOrderedAscending) || ([openingTimeDate compare:now] == NSOrderedSame)) {
if([closingTimeDate compare:now] == NSOrderedDescending)
{
_openingState = RestarauntOpeningStateOpen;
} else {
_openingState = RestarauntOpeningStateClosed;
}
} else {
NSDate *nowPlusTwoHours = [now dateByAddingTimeInterval:7200.0];
if(([openingTimeDate compare:nowPlusTwoHours] == NSOrderedAscending) || ([openingTimeDate compare:nowPlusTwoHours] == NSOrderedSame))
{
_openingState = RestarauntOpeningStateWillBeOpenedInTwoHours;
} else {
_openingState = RestarauntOpeningStateClosed;
}
}
// _openingState = RestarauntOpeningStateWillBeOpenedInTwoHours;
NSArray *lattitudeRecord = [[dictionary objectForKey:@"custom_fields"] objectForKey:@"Lattitude"];
_lattitude = [[lattitudeRecord objectAtIndex:0] doubleValue];
NSArray *longditudeRecord = [[dictionary objectForKey:@"custom_fields"] objectForKey:@"Longditude"];
_longditude = [[longditudeRecord objectAtIndex:0] doubleValue];
}
//[setValue:@"RestarauntOpeningStateOpen" forKey:@"_openingState"];
// _openingState setValue:@"RestarauntOpeningStateOpen" forKeyPath:RestarauntOpeningState;
return self;
}
//-(void)setValue:(id)value forKeyPath:(NSString *)keyPath{
// _openingState = RestarauntOpeningStateOpen;
//}
//-(void)setValue:(id)value forKeyPath:(NSString *)keyPath{
// _openingState = RestarauntOpeningStateOpen;
//}
@end
«форматирование кода» - это код, а не акцент. Кроме того, ваш вопрос - это дамп кода, который вы хотите, чтобы кто-то другой изменил для вас, что делает его низким. Кроме того, просто заявив, что вы исследовали свою проблему, не квалифицируется как исследование. – dandan78
Привет, Dan, спасибо за ваш вклад, но я боюсь, что вы совершенно ошибаетесь, я пытаюсь узнать здесь. Еще раз благодарю вас за вашу низкую качественную критику и напыщенно принимая/высокомерный вход (!) – user1419810