Skip to content

Commit

Permalink
Added ESUniqueNumericIdentifier() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ElfSundae committed Jul 29, 2019
1 parent ee003cf commit d357cc0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 3.17.1 (2019-07-29)

- Added `ESUniqueNumericIdentifier()` helper

## 3.17.0 (2019-07-29)

- Moved `-[NSString UUIDString]` to `ESUUIDString()` helper
Expand Down
2 changes: 1 addition & 1 deletion ESFramework.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'ESFramework'
s.version = '3.17.0'
s.version = '3.17.1'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.summary = 'An efficient, small framework for iOS, macOS, watchOS, and tvOS.'
s.homepage = 'https://github.com/ElfSundae/ESFramework'
Expand Down
6 changes: 6 additions & 0 deletions ESFramework/Core/ESHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ FOUNDATION_EXPORT uint32_t ESRandomNumber(uint32_t min, uint32_t max);
*/
FOUNDATION_EXPORT NSString *ESUUIDString(void);

/**
* Generates a time based unique numeric identifier.
* e.g. "586063599884852".
*/
FOUNDATION_EXPORT NSString *ESUniqueNumericIdentifier(void);

/**
* Generates a random alphanumeric string that contains a-zA-Z0-9.
*/
Expand Down
8 changes: 8 additions & 0 deletions ESFramework/Core/ESHelpers.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ uint32_t ESRandomNumber(uint32_t min, uint32_t max)
return [NSUUID UUID].UUIDString;
}

NSString *ESUniqueNumericIdentifier(void)
{
NSTimeInterval time = NSDate.date.timeIntervalSinceReferenceDate;
NSUInteger seconds = (NSUInteger)time;
NSUInteger random = (NSUInteger)((time - seconds) * 1000000.0 + arc4random() % 100000);
return [NSString stringWithFormat:@"%lu%lu", (unsigned long)seconds, (unsigned long)random];
}

NSString * _Nullable ESRandomString(NSUInteger length)
{
static char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Expand Down
4 changes: 2 additions & 2 deletions Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.17.0</string>
<string>3.17.1</string>
<key>CFBundleVersion</key>
<string>3.17.0</string>
<string>3.17.1</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2019 https://0x123.com All rights reserved.</string>
</dict>
Expand Down

0 comments on commit d357cc0

Please sign in to comment.