Вы должны использовать moment.js для форматирования даты. Для проверки действительной даты используется isValid()
функция момента.
var dateArr = ['one', '2019-08-01'];
console.log(getDate(dateArr));
function getDate(arr) {
for (var key in arr) {
var tempDate = moment(new Date(arr[key]));
if (tempDate.isValid()) {
arr[key] = tempDate.format('DD-MM-YYYY');
}
}
return arr;
}
Вы можете протестировать представление, выполнив следующие действия:
- (NSTimeInterval)timeTakenToDrawView:(UIView *)view count:(NSInteger)count
{
CGRect bounds = [view bounds];
NSDate *startDate = [NSDate date];
UIGraphicsBeginImageContext(bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
NSInteger i = 0;
for (i = 0; i < count; i++) {
CGContextSaveGState(context);
[view drawRect:bounds];
CGContextRestoreGState(context);
}
UIGraphicsEndImageContext();
return [[NSDate date] timeIntervalSinceDate:startDate];
}
(Не пробовал, но должно работать)
Внутри вашего NSView .m. Очевидно, вы можете захотеть подключить это к пользовательскому интерфейсу или чему-то еще.
- (void)awakeFromNib {
// Have to wait for the window to be onscreen, graphics context ready, etc
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFired:) userInfo:NULL repeats:NO];
}
- (void)timerFired:(NSTimer *)aTimer {
[self lockFocus];
NSDate* then = [NSDate date];
int callIdx = 0;
for( callIdx = 0; callIdx < 1000; callIdx++ ) {
[self drawRect:[self bounds]];
}
NSDate* now = [NSDate date];
[self unlockFocus];
NSLog(@"Took %f seconds", [now timeIntervalSinceDate:then]);
}
- (void)drawRect:(NSRect)rect {
[[NSColor redColor] set];
NSRectFill(rect);
}
Не забывайте, что вы также можете использовать инструмент производительности CoreImage и получать частоту кадров, если ваш drawRect используется часто.
Вы также можете использовать некоторые инструменты производительности, чтобы узнать, сколько времени потрачено в этом методе.