Skip to content

Commit

Permalink
Fix deprecation warnings in iOS 8
Browse files Browse the repository at this point in the history
  • Loading branch information
vocaro committed Nov 28, 2014
1 parent 1305199 commit 797d96e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
10 changes: 6 additions & 4 deletions DateCalculations.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 45;
objectVersion = 46;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -167,8 +167,11 @@
/* Begin PBXProject section */
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0610;
};
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "DateCalculations" */;
compatibilityVersion = "Xcode 3.1";
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
Expand Down Expand Up @@ -353,11 +356,11 @@
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
SDKROOT = iphoneos;
};
Expand All @@ -366,7 +369,6 @@
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
Expand Down
2 changes: 1 addition & 1 deletion DateCalculations/NSDate+Calculations.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

- (NSDate *)change:(NSDictionary *)changes;

- (int)daysInMonth;
- (NSUInteger)daysInMonth;

- (NSDate *)monthsSince:(int)months;
- (NSDate *)yearsSince:(int)years;
Expand Down
42 changes: 21 additions & 21 deletions DateCalculations/NSDate+Calculations.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ + (NSDate *)createDate:(int)year month:(int)month day:(int)day hour:(int)hour mi
- (NSDate *)beginningOfDay
{
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
int calendarComponents = (NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit);
int calendarComponents = (NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour);
NSDateComponents *comps = [currentCalendar components:calendarComponents fromDate:self];

[comps setHour:0];
Expand All @@ -50,7 +50,7 @@ - (NSDate *)beginningOfDay
- (NSDate *)beginningOfMonth
{
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
int calendarComponents = (NSYearCalendarUnit | NSMonthCalendarUnit);
int calendarComponents = (NSCalendarUnitYear | NSCalendarUnitMonth);
NSDateComponents *comps = [currentCalendar components:calendarComponents fromDate:self];

[comps setDay:1];
Expand All @@ -65,10 +65,10 @@ - (NSDate *)beginningOfMonth
- (NSDate *)beginningOfQuarter
{
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
int calendarComponents = (NSYearCalendarUnit | NSMonthCalendarUnit);
int calendarComponents = (NSCalendarUnitYear | NSCalendarUnitMonth);
NSDateComponents *comps = [currentCalendar components:calendarComponents fromDate:self];

int month = [comps month];
NSInteger month = [comps month];

if (month < 4)
[comps setMonth:1];
Expand All @@ -91,7 +91,7 @@ - (NSDate *)beginningOfQuarter
- (NSDate *)beginningOfWeek
{
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
int calendarComponents = (NSYearCalendarUnit | NSMonthCalendarUnit | NSWeekCalendarUnit | NSWeekdayCalendarUnit);
int calendarComponents = (NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitWeekOfYear | NSCalendarUnitWeekday);
NSDateComponents *comps = [currentCalendar components:calendarComponents fromDate:self];

[comps setWeekday:1];
Expand All @@ -105,7 +105,7 @@ - (NSDate *)beginningOfWeek
- (NSDate *)beginningOfYear
{
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
int calendarComponents = (NSYearCalendarUnit);
int calendarComponents = (NSCalendarUnitYear);
NSDateComponents *comps = [currentCalendar components:calendarComponents fromDate:self];

[comps setMonth:1];
Expand All @@ -123,7 +123,7 @@ - (NSDate *)beginningOfYear
- (NSDate *)endOfDay
{
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
int calendarComponents = (NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit);
int calendarComponents = (NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour);
NSDateComponents *comps = [currentCalendar components:calendarComponents fromDate:self];

[comps setHour:23];
Expand All @@ -136,7 +136,7 @@ - (NSDate *)endOfDay
- (NSDate *)endOfMonth
{
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
int calendarComponents = (NSYearCalendarUnit | NSMonthCalendarUnit);
int calendarComponents = (NSCalendarUnitYear | NSCalendarUnitMonth);
NSDateComponents *comps = [currentCalendar components:calendarComponents fromDate:self];

[comps setDay:[self daysInMonth]];
Expand All @@ -151,10 +151,10 @@ - (NSDate *)endOfMonth
- (NSDate *)endOfQuarter
{
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
int calendarComponents = (NSYearCalendarUnit | NSMonthCalendarUnit);
int calendarComponents = (NSCalendarUnitYear | NSCalendarUnitMonth);
NSDateComponents *comps = [currentCalendar components:calendarComponents fromDate:self];

int month = [comps month];
NSInteger month = [comps month];

if (month < 4)
{
Expand Down Expand Up @@ -187,7 +187,7 @@ - (NSDate *)endOfQuarter
- (NSDate *)endOfWeek
{
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
int calendarComponents = (NSYearCalendarUnit | NSMonthCalendarUnit | NSWeekCalendarUnit | NSWeekdayCalendarUnit);
int calendarComponents = (NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitWeekOfYear | NSCalendarUnitWeekday);
NSDateComponents *comps = [currentCalendar components:calendarComponents fromDate:self];

[comps setWeekday:7];
Expand All @@ -201,7 +201,7 @@ - (NSDate *)endOfWeek
- (NSDate *)endOfYear
{
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
int calendarComponents = (NSYearCalendarUnit);
int calendarComponents = (NSCalendarUnitYear);
NSDateComponents *comps = [currentCalendar components:calendarComponents fromDate:self];

[comps setMonth:12];
Expand All @@ -222,7 +222,7 @@ - (NSDate *)advance:(int)years months:(int)months weeks:(int)weeks days:(int)day
NSDateComponents *comps = [[[NSDateComponents alloc] init] autorelease];
[comps setYear:years];
[comps setMonth:months];
[comps setWeek:weeks];
[comps setWeekOfYear:weeks];
[comps setDay:days];
[comps setHour:hours];
[comps setMinute:minutes];
Expand All @@ -237,7 +237,7 @@ - (NSDate *)ago:(int)years months:(int)months weeks:(int)weeks days:(int)days
NSDateComponents *comps = [[[NSDateComponents alloc] init] autorelease];
[comps setYear:-years];
[comps setMonth:-months];
[comps setWeek:-weeks];
[comps setWeekOfYear:-weeks];
[comps setDay:-days];
[comps setHour:-hours];
[comps setMinute:-minutes];
Expand All @@ -250,10 +250,10 @@ - (NSDate *)change:(NSDictionary *)changes
{
NSCalendar *currentCalendar = [NSCalendar currentCalendar];

int calendarComponents = (NSEraCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit |
NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit |
NSWeekCalendarUnit | NSWeekdayCalendarUnit | NSWeekdayOrdinalCalendarUnit |
NSQuarterCalendarUnit);
int calendarComponents = (NSCalendarUnitEra | NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay |
NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond |
NSCalendarUnitWeekOfYear | NSCalendarUnitWeekday | NSCalendarUnitWeekdayOrdinal |
NSCalendarUnitQuarter);

NSDateComponents *comps = [currentCalendar components:calendarComponents fromDate:self];

Expand All @@ -271,11 +271,11 @@ - (NSDate *)change:(NSDictionary *)changes
return [currentCalendar dateFromComponents:comps];
}

- (int)daysInMonth
- (NSUInteger)daysInMonth
{
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
NSRange days = [currentCalendar rangeOfUnit:NSDayCalendarUnit
inUnit:NSMonthCalendarUnit
NSRange days = [currentCalendar rangeOfUnit:NSCalendarUnitDay
inUnit:NSCalendarUnitMonth
forDate:self];
return days.length;
}
Expand Down
4 changes: 2 additions & 2 deletions Test/DateCalculationsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ - (void)testChange
- (void)testDaysInMonth
{
NSDate *date = [NSDate dateWithYear:2011 month:8 day:14 hour:13 minute:12 second:0];
int result = [date daysInMonth];
int expected = 31;
NSUInteger result = [date daysInMonth];
NSUInteger expected = 31;

STAssertEquals(result, expected, nil);
}
Expand Down

0 comments on commit 797d96e

Please sign in to comment.