Skip to content
This repository was archived by the owner on Apr 18, 2023. It is now read-only.

Commit c3ac3ed

Browse files
author
Vikas Dadheech
committed
Add comments and keep formatting consitant
1 parent cbd50f6 commit c3ac3ed

File tree

10 files changed

+177
-93
lines changed

10 files changed

+177
-93
lines changed

MSGraphCoreSDK/MSGraphCoreSDK/Models/MSCollection.h

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,35 @@
22

33
#import <MSGraphCoreSDK/MSObject.h>
44

5-
/**
5+
/*
66
An `MSCollection` object is a collection of Graph objects.
77
@see MSObject
88
*/
99
@interface MSCollection : MSObject
1010

11-
/**
12-
An array of Graph objects.
11+
/*
12+
An array of dictionaries.
1313
*/
1414
@property (strong, nonatomic) NSArray *value;
1515

16-
/**
16+
/*
1717
There may be more items in the collection available via paging. This is the url to the next page of the collection.
1818
*/
1919
@property (strong, nonatomic) NSURL *nextLink;
2020

21-
/**
21+
/*
2222
Any additional data returned from the collection request will be in this dictionary.
2323
*/
2424
@property (strong, nonatomic) NSDictionary *additionalData;
2525

26-
/**
26+
/*
2727
Creates an MSCollection with the response from the service.
28-
@param array The array of OneDrive objects.
28+
@param array The array of objects.
2929
@param nextLink The link to the next page of items, if there is one.
3030
@param additionalData Any other data returned from the service.
3131
*/
3232
- (instancetype)initWithArray:(NSArray *)array
3333
nextLink:(NSString *)nextLink
3434
additionalData:(NSDictionary *)additionalData;
35-
//
36-
///**
37-
// Return an array with all values compatible with NSJsonSerialization
38-
//*/
39-
//- (NSArray *) arrayFromItem;
4035

4136
@end

MSGraphCoreSDK/MSGraphCoreSDK/Models/MSCollection.m

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@ -(instancetype)initWithArray:(NSArray *)array
1010
additionalData:(NSDictionary *)additionalData
1111
{
1212
self = [super init];
13-
if (self){
13+
if (self)
14+
{
1415
_value = array;
1516
_nextLink = [NSURL URLWithString:nextLink];
1617
_additionalData = additionalData;
1718
}
1819
return self;
1920
}
2021

21-
- (instancetype)initWithData:(NSData *)data
22+
- (instancetype)initWithData:(NSData *)data error:(NSError *__autoreleasing *)error
2223
{
23-
self = [super initWithData:data];
24-
if(self){
25-
self.value = [[self dictionaryFromItem] objectForKey:@"value"];
26-
self.nextLink = [[self dictionaryFromItem] objectForKey:@"@odata.nextLink"];
24+
self = [super initWithData:data error:error];
25+
if(self)
26+
{
27+
self.value = [[self getDictionary] objectForKey:@"value"];
28+
self.nextLink = [NSURL URLWithString:[[self dictionaryFromItem] objectForKey:@"@odata.nextLink"]];
29+
self.additionalData = [self getDictionary];
2730
}
2831
return self;
2932
}
@@ -33,19 +36,11 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary
3336
self = [super initWithDictionary:dictionary];
3437
if(self)
3538
{
36-
self.value = [dictionary objectForKey:@"values"];
37-
self.nextLink = [dictionary objectForKey:@"@odata.nextLink"];
39+
self.value = [[self getDictionary] objectForKey:@"values"];
40+
self.nextLink = [NSURL URLWithString:[[self getDictionary] objectForKey:@"@odata.nextLink"]];
41+
self.additionalData = [self getDictionary];
3842
}
3943
return self;
4044
}
4145

42-
//- (NSArray *) arrayFromItem
43-
//{
44-
// NSMutableArray *retArray = [NSMutableArray arrayWithCapacity:[self.value count]];
45-
// [self.value enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){
46-
// retArray[idx] = [MSObject getNSJsonSerializationCompatibleValue:obj];
47-
// }];
48-
// return retArray;
49-
//}
50-
5146
@end

MSGraphCoreSDK/MSGraphCoreSDK/Models/MSDate.h

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,45 @@
22

33
#import <Foundation/Foundation.h>
44

5+
6+
/*
7+
A wrapper class around native NSDate class to ease the conversion and initialization of date.
8+
*/
59
@interface MSDate : NSObject
610

11+
@property (nonatomic, readonly) NSInteger year;
12+
@property (nonatomic, readonly) NSInteger month;
13+
@property (nonatomic, readonly) NSInteger day;
14+
15+
/*
16+
Class method to initialize an instance of MSDate with NSDate
17+
*/
718
+ (instancetype) date;
19+
20+
/*
21+
Class method to initialize an instance of MSDate with year, month and day in Integer form.
22+
*/
823
+ (instancetype) dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day;
924

10-
- (id) initWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day;
25+
/*
26+
Instance method to initialize an instance of MSDate with NSDate
27+
*/
1128
- (id) initWithNSDate:(NSDate*)date;
1229

13-
@property (nonatomic, readonly) NSInteger year;
14-
@property (nonatomic, readonly) NSInteger month;
15-
@property (nonatomic, readonly) NSInteger day;
30+
/*
31+
Instance method to initialize an instance of MSDate with year, month and day in Integer form.
32+
*/
33+
- (id) initWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day;
1634

35+
/*
36+
This method generates a string equivalent of MSDate instance.
37+
*/
1738
- (NSString *)ms_toString;
39+
40+
/*
41+
This method can be used to get an MSDate instance from a date string
42+
@param dateString The date string which needs to be converted.
43+
*/
1844
+ (instancetype)ms_dateFromString:(NSString *)dateString;
1945

2046
@end

MSGraphCoreSDK/MSGraphCoreSDK/Models/MSDate.m

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,29 @@ @implementation MSDate
1414

1515
#pragma mark - Initializers
1616

17-
+ (instancetype) date {
17+
+ (instancetype) date
18+
{
1819
return [[MSDate alloc] initWithNSDate:[NSDate date]];
1920
}
2021

21-
+ (instancetype) dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day {
22+
+ (instancetype) dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day
23+
{
2224
return [[MSDate alloc] initWithYear:year month:month day:day];
2325
}
2426

25-
- (id) initWithNSDate:(NSDate*)date {
26-
if (self = [super init]) {
27+
- (id) initWithNSDate:(NSDate*)date
28+
{
29+
if (self = [super init])
30+
{
2731
self.date = date;
2832
}
2933
return self;
3034
}
3135

32-
- (id) initWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day {
33-
if (self = [super init]) {
36+
- (id) initWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day
37+
{
38+
if (self = [super init])
39+
{
3440
NSDateComponents *components = [[NSDateComponents alloc] init];
3541
components.year = year;
3642
components.month = month;
@@ -44,17 +50,20 @@ - (id) initWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day {
4450

4551
#pragma mark - Properties
4652

47-
- (NSInteger) year {
53+
- (NSInteger) year
54+
{
4855
NSDateComponents *components = [[MSDate gregorianCalendar] components:NSCalendarUnitYear fromDate:self.date];
4956
return components.year;
5057
}
5158

52-
- (NSInteger) month {
59+
- (NSInteger) month
60+
{
5361
NSDateComponents *components = [[MSDate gregorianCalendar] components:NSCalendarUnitMonth fromDate:self.date];
5462
return components.month;
5563
}
5664

57-
- (NSInteger) day {
65+
- (NSInteger) day
66+
{
5867
NSDateComponents *components = [[MSDate gregorianCalendar] components:NSCalendarUnitDay fromDate:self.date];
5968
return components.day;
6069
}
@@ -74,7 +83,8 @@ - (NSString *)ms_toString
7483
+ (instancetype)ms_dateFromString:(NSString *)dateString
7584
{
7685
NSDate *date = nil;
77-
if (dateString){
86+
if (dateString)
87+
{
7888
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
7989
[dateFormatter setDateFormat:dateFormat];
8090
NSLocale *posix = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
@@ -86,7 +96,8 @@ + (instancetype)ms_dateFromString:(NSString *)dateString
8696

8797
#pragma mark - Helpers
8898

89-
+ (NSCalendar*) gregorianCalendar {
99+
+ (NSCalendar*) gregorianCalendar
100+
{
90101
static NSCalendar *calendar;
91102
static dispatch_once_t onceToken;
92103
dispatch_once(&onceToken, ^{
Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
1-
//
2-
// MSObject.h
3-
// MSGraphPOCSDK
4-
//
5-
// Created by Vikas Dadheech on 26/07/18.
6-
// Copyright © 2018 Vikas Dadheech. All rights reserved.
7-
//
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
82

93
#import <Foundation/Foundation.h>
104

115
@interface MSObject : NSObject
126

13-
/**
7+
/*
8+
Creates an MSObject with the given data.
9+
@param data The NSData instance from the response.
10+
@error If there are any errors during the conversion of data then it will be assigned to this.
11+
@warning This method will return nil if the data is nil.
12+
*/
13+
-(instancetype)initWithData:(NSData *)data error:(NSError **)error;;
14+
15+
/*
1416
Creates an MSObject with the given dictionary.
1517
@param dictionary The dictionary representation of the object.
1618
@warning This method will return nil if the dictionary is nil.
1719
*/
1820
- (instancetype)initWithDictionary:(NSDictionary*)dictionary;
1921

20-
-(instancetype)initWithData:(NSData *)data;
21-
22-
/**
23-
Creates a dictionary from the given item.
24-
@return dictionary Representation for the given item.
22+
/*
23+
This method returns the underlying dictionary which is used to construct the model.
24+
@return The NSDictionary consisting of different properties and their values for the model.
2525
*/
26-
- (NSDictionary*)dictionaryFromItem;
26+
- (NSMutableDictionary*)getDictionary;
2727

28-
- (NSData *)serializedData;
28+
/*
29+
This method converts the internal dictionary to serialized data.
30+
@param error If there are any errors during the conversion of internal dictionary then it will be assigned to this.
31+
@return NSData representation of the internal dictionary,
32+
*/
33+
- (NSData *)getSerializedDataWithError:(NSError **)error;;
2934

3035

3136
@end
Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
//
2-
// MSObject.m
3-
// MSGraphPOCSDK
4-
//
5-
// Created by Vikas Dadheech on 26/07/18.
6-
// Copyright © 2018 Vikas Dadheech. All rights reserved.
7-
//
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
82

93
#import "MSObject.h"
104

@@ -16,32 +10,46 @@ @interface MSObject()
1610

1711
@implementation MSObject
1812

19-
20-
- (instancetype)init {
13+
- (instancetype)init
14+
{
2115
return [self initWithDictionary:[NSMutableDictionary new]];
2216
}
2317

24-
-(instancetype)initWithData:(NSData *)data{
18+
-(instancetype)initWithData:(NSData *)data error:(NSError *__autoreleasing *)error
19+
{
20+
if(!data)
21+
{
22+
return nil;
23+
}
2524
self = [super init];
26-
if(self){
27-
self.dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
25+
if(self)
26+
{
27+
self.dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:error];
2828
}
2929
return self;
3030
}
3131

32-
-(instancetype)initWithDictionary:(NSDictionary *)dictionary{
32+
-(instancetype)initWithDictionary:(NSDictionary *)dictionary
33+
{
34+
if (!dictionary)
35+
{
36+
return nil;
37+
}
3338
self = [super init];
34-
if(self){
39+
if(self)
40+
{
3541
self.dictionary = [NSMutableDictionary dictionaryWithDictionary:dictionary];
3642
}
3743
return self;
3844
}
3945

40-
-(NSMutableDictionary *)dictionaryFromItem{
46+
-(NSMutableDictionary *)getDictionary
47+
{
4148
return [self.dictionary mutableCopy];
4249
}
4350

44-
- (NSData *)serializedData{
45-
return [NSJSONSerialization dataWithJSONObject:self.dictionary options:kNilOptions error:nil];
51+
- (NSData *)getSerializedDataWithError:(NSError *__autoreleasing *)error
52+
{
53+
return [NSJSONSerialization dataWithJSONObject:self.dictionary options:kNilOptions error:error];
4654
}
4755
@end

MSGraphCoreSDK/MSGraphCoreSDK/Models/MSTimeOfDay.h

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,40 @@
22

33
#import <Foundation/Foundation.h>
44

5+
/*
6+
A wrapper class around native NSDate class to represent a specific time in the day.
7+
*/
58
@interface MSTimeOfDay : NSObject
69

7-
+ (instancetype) timeWithSeconds:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second;
8-
9-
- (id) initWithSeconds:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second;
10-
1110
@property (nonatomic, readonly) NSInteger hour;
1211
@property (nonatomic, readonly) NSInteger minute;
1312
@property (nonatomic, readonly) NSInteger second;
1413

14+
/*
15+
Class method to create an instance of MSTimeOfDay
16+
@param hour Integer value denoting the hour of day
17+
@param minute Integer value denoting the minutes of that hour
18+
@param second Integer value denoting the seconds of that minute
19+
*/
20+
+ (instancetype) timeWithSeconds:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second;
21+
22+
/*
23+
Instance method to create an instance of MSTimeOfDay
24+
@param hour Integer value denoting the hour of day
25+
@param minute Integer value denoting the minutes of that hour
26+
@param second Integer value denoting the seconds of that minute
27+
*/
28+
- (id) initWithSeconds:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second;
29+
30+
/*
31+
This method generates a string equivalent of MSTimeOfDay instance.
32+
*/
1533
- (NSString *)ms_toString;
34+
35+
/*
36+
This method can be used to get an MSTimeOfDay instance from a date string
37+
@param dateString The date string which needs to be converted.
38+
*/
1639
+ (instancetype)ms_timeFromString:(NSString *)timeString;
1740

1841
@end

0 commit comments

Comments
 (0)