Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 65 additions & 47 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,67 @@
/** MacOS **/

# Created by https://www.toptal.com/developers/gitignore/api/swiftpm,xcode,macos,cocoapods
# Edit at https://www.toptal.com/developers/gitignore?templates=swiftpm,xcode,macos,cocoapods

### CocoaPods ###
## CocoaPods GitIgnore Template

# CocoaPods - Only use to conserve bandwidth / Save time on Pushing
# - Also handy if you have a large number of dependant pods
# - AS PER https://guides.cocoapods.org/using/using-cocoapods.html NEVER IGNORE THE LOCK FILE
Pods/

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

/** NPM **/
*/node_modules
*npm*
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### SwiftPM ###
Packages
.build/
xcuserdata
DerivedData/
*.xcodeproj


### Xcode ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/
## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## Various settings
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
Expand All @@ -22,46 +70,16 @@ DerivedData/
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xcuserstate

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
## Gcc Patch
/*.gcno

Carthage/Build
### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
**/xcshareddata/WorkspaceSettings.xcsettings

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md

fastlane/report.xml
fastlane/screenshots

#Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode
# End of https://www.toptal.com/developers/gitignore/api/swiftpm,xcode,macos,cocoapods

iOSInjectionProject/
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 21 additions & 13 deletions EDSemver/EDSemver.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,42 @@

#import <Foundation/Foundation.h>

#ifndef EDSEMVER_EDSEMVER_H
#define EDSEMVER_EDSEMVER_H

/**
`EDSemver` is a helper library for Objective-C based on the 2.0.0 spec of [Semantic Versioning](https://semver.org/).
*/
@interface EDSemver : NSObject

/*!
/**
* The major version number (API changes)
*/
@property (readonly) NSInteger major;
/*!
/**
* The minor version (functionality added in a backwards compatible manor)
*/
@property (readonly) NSInteger minor;
/*!
/**
* The patch version (bug fixes made in a backwards compatible manor)
*/
@property (readonly) NSInteger patch;
/*!
/**
* The prerelease number, preceded with -, e.g. 1.2.3-alpha1
*/
@property (readonly, nullable) NSString *prerelease;
/*!
/**
* The build number, preceded with +, e.g. 1.2.3+456
*/
@property (readonly, nullable) NSString *build;

/*!
/**
* The current semver spec version
*
* @return The spec version as a string
*/
+ (nonnull NSString *)spec;
/*!
/**
* Create a semver object with a version string
*
* @param aString The version string
Expand All @@ -46,7 +52,7 @@
*/
+ (nonnull instancetype)semverWithString:(nonnull NSString *)aString;

/*!
/**
* Create a semver object with a version string
*
* @param aString The version string
Expand All @@ -55,15 +61,15 @@
*/
- (nonnull instancetype)initWithString:(nonnull NSString *)aString;

/*!
/**
* Compare semver objects
*
* @param aVersion The version string
*
* @return The semver object
*/
- (NSComparisonResult)compare:(nonnull EDSemver *)aVersion;
/*!
/**
* Is version equal to another version
* Implemented using `compare:`. Returns NO parameter is nil
*
Expand All @@ -72,7 +78,7 @@
* @return YES if equal, NO otherwise
*/
- (BOOL)isEqualTo:(nullable id)object;
/*!
/**
* Is version less than another version.
* Implemented using `compare:`. Returns NO parameter is nil
*
Expand All @@ -81,7 +87,7 @@
* @return YES if less than, NO otherwise
*/
- (BOOL)isLessThan:(nullable id)object;
/*!
/**
* Is version greater than than another version.
* Implemented using `compare:`. Returns NO parameter is nil
*
Expand All @@ -91,11 +97,13 @@
*/
- (BOOL)isGreaterThan:(nullable id)object;

/*!
/**
* Is the semver object valid?
*
* @return YES if valid, NO otherwise
*/
- (BOOL)isValid;

@end

#endif
39 changes: 38 additions & 1 deletion EDSemver/EDSemver.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,45 @@ - (NSComparisonResult)compare:(EDSemver *)aVersion
if (self.prerelease.length > 0 || aVersion.prerelease.length > 0) {
if (self.prerelease.length > 0 && aVersion.prerelease.length == 0) return NSOrderedAscending;
if (self.prerelease.length == 0 && aVersion.prerelease.length > 0) return NSOrderedDescending;
return [self.prerelease compare:(NSString * _Nonnull)aVersion.prerelease];
return [self comparePrerelease:aVersion.prerelease];
}

return NSOrderedSame;
}

- (NSComparisonResult)comparePrerelease:(NSString *)aPrerelease
{
NSArray *aPr = [self parse:aPrerelease strict:NO];
NSUInteger minCount = self.pr.count < aPr.count ? self.pr.count : aPr.count;
NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
NSString *part, *aPart;
NSNumber *numPart, *aNumPart;
NSComparisonResult result;
for (NSUInteger i = 0; i < minCount; i++) {
part = self.pr[i];
aPart = aPr[i];
numPart = [nf numberFromString:part];
aNumPart = [nf numberFromString:aPart];

if (numPart && aNumPart) {
result = [numPart compare:aNumPart];
if (result != NSOrderedSame) {
return result;
}
} else if (!numPart && aNumPart) {
return NSOrderedDescending;
} else if (numPart && !aNumPart) {
return NSOrderedAscending;
} else {
result = [part compare:aPart];
if (result != NSOrderedSame) {
return result;
}
}
}

return [@(self.pr.count) compare:@(aPr.count)];
}

- (BOOL)isEqualTo:(id)aVersion
{
Expand All @@ -126,6 +159,10 @@ - (BOOL)isGreaterThan:(id)aVersion
return [self compare:(EDSemver * _Nonnull)aVersion] == NSOrderedDescending;
}

- (BOOL)isEqual:(id)object {
return [self isEqualTo:object];
}

- (NSString *)description
{
return self.original;
Expand Down
31 changes: 31 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Semver",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "Semver",
targets: ["Semver"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "Semver",
dependencies: [],
path: "EDSemver",
publicHeadersPath: ".",
cSettings: [
.headerSearchPath("."),
]
)
]
)
16 changes: 14 additions & 2 deletions Project/semver.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@
attributes = {
CLASSPREFIX = ED;
LastTestingUpgradeCheck = 0730;
LastUpgradeCheck = 0820;
LastUpgradeCheck = 0940;
ORGANIZATIONNAME = "Andrew Sliwinski";
TargetAttributes = {
01DA90111D0ADA5F00D65599 = {
Expand All @@ -402,7 +402,7 @@
};
buildConfigurationList = C390380B178615E400ECBCAC /* Build configuration list for PBXProject "semver" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Expand Down Expand Up @@ -802,11 +802,17 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -843,11 +849,17 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down
Loading