Skip to content

Commit a92b3d8

Browse files
committed
Merge pull request #34 from square/rhg/ark-log-message-create-with-date
Allow an ARKLogMessage to be created with an arbitrary creationDate. …
2 parents a4a9ab5 + f1e7dbc commit a92b3d8

6 files changed

+37
-72
lines changed

Aardvark.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Aardvark'
3-
s.version = '1.4.0'
3+
s.version = '1.5.0'
44
s.license = 'Apache License, Version 2.0'
55
s.summary = 'Aardvark is a library that makes it dead simple to create actionable bug reports.'
66
s.homepage = 'https://github.com/square/Aardvark'

AardvarkTests/ARKLogTableViewControllerTests.m

+1-32
Original file line numberDiff line numberDiff line change
@@ -46,49 +46,18 @@ - (instancetype)initWithDate:(NSDate *)date;
4646

4747
@implementation ARKFakeLogMessage
4848

49-
@synthesize creationDate = _creationDate;
50-
5149
#pragma mark - Initialization
5250

5351
- (instancetype)initWithDate:(NSDate *)date;
5452
{
55-
self = [self init];
53+
self = [super initWithText:@"Fake Log" image:nil type:ARKLogTypeDefault userInfo:nil creationDate:date];
5654
if (!self) {
5755
return nil;
5856
}
5957

60-
_creationDate = date;
61-
6258
return self;
6359
}
6460

65-
#pragma mark - NSObject
66-
67-
- (NSString *)description;
68-
{
69-
NSString *dateString = [NSDateFormatter localizedStringFromDate:self.creationDate dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterMediumStyle];
70-
return [NSString stringWithFormat:@"[%@] Fake Log", dateString];
71-
}
72-
73-
#pragma mark - NSCoding
74-
75-
- (instancetype)initWithCoder:(NSCoder *)aDecoder;
76-
{
77-
self = [self init];
78-
if (!self) {
79-
return nil;
80-
}
81-
82-
_creationDate = [[aDecoder decodeObjectOfClass:[NSDate class] forKey:ARKSelfKeyPath(creationDate)] copy];
83-
84-
return self;
85-
}
86-
87-
- (void)encodeWithCoder:(NSCoder *)aCoder;
88-
{
89-
[aCoder encodeObject:self.creationDate forKey:ARKSelfKeyPath(creationDate)];
90-
}
91-
9261
@end
9362

9463

Log Viewing/ARKLogTableViewController.m

+4-21
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,6 @@ - (void)_scrollTableViewToBottomAnimated:(BOOL)animated;
481481

482482
@implementation ARKTimestampLogMessage
483483

484-
@synthesize text = _text;
485-
@synthesize type = _type;
486-
@synthesize creationDate = _creationDate;
487-
488484
#pragma mark - Class Methods
489485

490486
+ (NSDateFormatter *)sharedDateFormatter;
@@ -505,26 +501,13 @@ + (NSDateFormatter *)sharedDateFormatter;
505501

506502
- (instancetype)initWithDate:(NSDate *)date;
507503
{
508-
self = [self init];
509-
if (!self) {
510-
return nil;
511-
}
512-
513-
_type = ARKLogTypeSeparator;
514-
_creationDate = date;
515-
516-
return self;
504+
NSString *text = [[[self class] sharedDateFormatter] stringFromDate:date];
505+
return [super initWithText:text image:nil type:ARKLogTypeSeparator userInfo:nil creationDate:date];
517506
}
518507

519-
#pragma mark - Properties
520-
521-
- (NSString *)text;
508+
- (instancetype)initWithText:(NSString *)text image:(UIImage *)image type:(ARKLogType)type userInfo:(NSDictionary *)userInfo creationDate:(nonnull NSDate *)date;
522509
{
523-
if (!_text) {
524-
_text = [[[self class] sharedDateFormatter] stringFromDate:self.creationDate];
525-
}
526-
527-
return _text;
510+
return [self initWithDate:date];
528511
}
529512

530513
@end

Log Viewing/ARKLogTableViewController_Testing.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232

3333
@interface ARKTimestampLogMessage : ARKLogMessage
3434

35-
- (instancetype)initWithDate:(NSDate *)date;
35+
- (instancetype)initWithDate:(NSDate *)date NS_DESIGNATED_INITIALIZER;
36+
37+
+ (instancetype)new NS_UNAVAILABLE;
38+
- (instancetype)init NS_UNAVAILABLE;
39+
- (instancetype)initWithText:(NSString *)text image:(UIImage *)image type:(ARKLogType)type userInfo:(NSDictionary *)userInfo NS_UNAVAILABLE;
40+
- (instancetype)initWithText:(NSString *)text image:(UIImage *)image type:(ARKLogType)type userInfo:(NSDictionary *)userInfo creationDate:(NSDate *)date NS_UNAVAILABLE;
41+
3642

3743
@end

Logging/ARKLogMessage.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,22 @@ NS_ASSUME_NONNULL_BEGIN
2727

2828
@interface ARKLogMessage : NSObject <NSCopying, NSSecureCoding>
2929

30+
+ (instancetype)new NS_UNAVAILABLE;
31+
- (instancetype)init NS_UNAVAILABLE;
32+
33+
/// Creates an ARKLogMessage with the provided parameters, created at the current date.
34+
/// @see initWithText:image:type:userInfo:creationDate:
3035
- (instancetype)initWithText:(NSString *)text image:(nullable UIImage *)image type:(ARKLogType)type userInfo:(nullable NSDictionary *)userInfo;
3136

37+
- (instancetype)initWithText:(NSString *)text image:(nullable UIImage *)image type:(ARKLogType)type userInfo:(nullable NSDictionary *)userInfo creationDate:(NSDate *)date NS_DESIGNATED_INITIALIZER;
38+
3239
@property (nonatomic, copy, readonly) NSDate *creationDate;
3340
@property (nonatomic, copy, readonly) NSString *text;
34-
@property (nonatomic, readonly) UIImage *image;
41+
@property (nonatomic, readonly, nullable) UIImage *image;
3542
@property (nonatomic, readonly) ARKLogType type;
3643

37-
/// Arbitrary information used by ARKLogBlocks. This data is not persisted
38-
@property (nonatomic, copy, readonly) NSDictionary *userInfo;
44+
/// Arbitrary information used by ARKLogBlocks. This data is not persisted.
45+
@property (nonatomic, copy, readonly, nullable) NSDictionary *userInfo;
3946

4047
@end
4148

Logging/ARKLogMessage.m

+14-14
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,35 @@ + (BOOL)supportsSecureCoding;
3636

3737
- (instancetype)initWithText:(NSString *)text image:(UIImage *)image type:(ARKLogType)type userInfo:(NSDictionary *)userInfo;
3838
{
39-
self = [self init];
39+
return [self initWithText:text image:image type:type userInfo:userInfo creationDate:[NSDate date]];
40+
}
41+
42+
- (instancetype)initWithText:(NSString *)text image:(UIImage *)image type:(ARKLogType)type userInfo:(NSDictionary *)userInfo creationDate:(nonnull NSDate *)date;
43+
{
44+
self = [super init];
4045
if (!self) {
4146
return nil;
4247
}
43-
48+
4449
_text = [text copy];
4550
_image = image;
4651
_type = type;
4752
_userInfo = [userInfo copy];
48-
_creationDate = [NSDate date];
49-
53+
_creationDate = date;
54+
5055
return self;
5156
}
5257

5358
#pragma mark - NSCoding
5459

5560
- (instancetype)initWithCoder:(NSCoder *)aDecoder;
5661
{
57-
self = [self init];
58-
if (!self) {
59-
return nil;
60-
}
61-
62-
_text = [aDecoder decodeObjectOfClass:[NSString class] forKey:ARKSelfKeyPath(text)];
63-
_image = [aDecoder decodeObjectOfClass:[UIImage class] forKey:ARKSelfKeyPath(image)];
64-
_type = (ARKLogType)[[aDecoder decodeObjectOfClass:[NSNumber class] forKey:ARKSelfKeyPath(type)] unsignedIntegerValue];
65-
_creationDate = [[aDecoder decodeObjectOfClass:[NSDate class] forKey:ARKSelfKeyPath(creationDate)] copy];
62+
NSString *text = [aDecoder decodeObjectOfClass:[NSString class] forKey:ARKSelfKeyPath(text)];
63+
UIImage *image = [aDecoder decodeObjectOfClass:[UIImage class] forKey:ARKSelfKeyPath(image)];
64+
ARKLogType type = (ARKLogType)[[aDecoder decodeObjectOfClass:[NSNumber class] forKey:ARKSelfKeyPath(type)] unsignedIntegerValue];
65+
NSDate *creationDate = [[aDecoder decodeObjectOfClass:[NSDate class] forKey:ARKSelfKeyPath(creationDate)] copy];
6666

67-
return self;
67+
return [self initWithText:text image:image type:type userInfo:nil creationDate:creationDate];
6868
}
6969

7070
- (void)encodeWithCoder:(NSCoder *)aCoder;

0 commit comments

Comments
 (0)