Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General cleanup and Objective-C modernization #211

Merged
merged 24 commits into from
May 11, 2017

Conversation

danieltiger
Copy link
Contributor

@danieltiger danieltiger commented May 10, 2017

  • Cleanup up code inconsistencies where I saw a general preference
  • Switched from [[alloc] init] to [new] where appropriate
  • Switched from explicitly checking against nil/null to just checking for presence
  • Removed unneeded assignment to nil, as it's the default behavior in Objective-C
  • Switched to using NS_UNAVAILABLE annotation to indicate no init method, rather than implementing it and raising an assertion. This way user code won't compile with init and they'll be told why.
  • Flipped some check logic so that we return early in the negative case, thus collapsing branches and de-indenting code.
  • Switched a check to search for object presence first, before calling an external method. This way if we don't have the object we don't waste time making the call.
  • Switched from [[alloc] init] for dictionaries and arrays to [dictionary] and [array]
  • Removed validate methods that only checked for nil/length of 0. They were being used in ways that made it clear they were misunderstood. Instead just checked for things directly.
  • Switched KIOQuery to use [super init] instead of [self init]. This is so that if anyone ever subclasses KIOQuery they will get the expected behavior. If there is some reason it was [self init] please let me know.
  • Removed makeDictionaryMutable and makeArrayMutable methods. Instead just use the built-in mutableCopy.
  • Removed strong from property declarations as it's the default.
  • Changed some error messages to be more explicit about what the problem is.
  • Switched from rangeOfString to hasPrefix and containsString.
  • Check for existence of self in KeenProperties before setting property values.

…jectID:andWriteKey:andReadKey:, after they have been initially set.
…hecking for nil and empty string, but were being used in a way that indicated that wasn't clear.
… the default. Use containsString and hasPrefix instead of range checking.
…d confusing validate method and just check for nil/empty. No need to init to nil in Objective-C for objects.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 65.908% when pulling ccf6c8c on danieltiger:assorted-improvements into b3aad6c on keenlabs:master.

Copy link
Contributor

@baumatron baumatron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Only concern is with breaking changes that would require a major revision bump. We could throw those in a vnext_major branch until we're ready to roll a major release.

@@ -15,24 +15,25 @@
+ (instancetype)sharedInstance;

// Initialize the object
- (instancetype)initWithURLSession:(NSURLSession*)urlSession
andStore:(KIODBStore*)store;
- (instancetype)init NS_UNAVAILABLE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a handy one!

return nil;
}

self = [self init];
self = [super init];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

@@ -23,21 +23,13 @@ + (NSData *)serializeEventToJSON:(NSMutableDictionary *)event error:(NSError**)
return [NSJSONSerialization dataWithJSONObject:fixed options:0 error:error];
}

+ (NSMutableDictionary *)makeDictionaryMutable:(NSDictionary *)dict {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to see these gone.

return nil;
}

// If the keys are already set, return the existing instance, don't overwrite the keys
if (self.sharedClient.projectID || self.sharedClient.writeKey || self.sharedClient.readKey) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would technically require revving a major revision, maybe this part of the change could be pared off and thrown into a vnext_major branch until we're ready to release a major revision then bring it to master?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'll pull it out for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you want me to do that? I can't create branches on this repo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pushed a vnext_major branch we can use.

if ([KeenClient isLocationAuthorized:clAuthStatus]) {
[self startMonitoringLocation];
}
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm all for going iOS 8+. We could make a pass and update targets at some point to actually require this deployment target. The podspec is at iOS 6 right now and there's a spattering of different versions throughout the project. Technically this is a breaking change, so it would be a major revision and should probably go in a vnext_major branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #214

@@ -54,13 +54,13 @@ - (KeenLogger*)init {
// about concurrent access when adding and removing loggers
// since those operations will be dispatched to this queue as well.
_loggerQueue = dispatch_queue_create("io.keen.logger", DISPATCH_QUEUE_SERIAL);
if (NULL == _loggerQueue) {
if (_loggerQueue == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these also be updated to if (!_loggerQueue), etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't... but that's mainly a stylistic thing with me, I find if (!_loggerQueue) harder to read. If you want me to do that though, I totally can.

In general I tried to keep the existing style as much as possible, and simply clean up inconsistencies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I'm good leaving it like this. I'm not highly opinionated about it.

@danieltiger
Copy link
Contributor Author

Ok, major changes removed. I'm creating new branches and PRs for each of those.

@baumatron
Copy link
Contributor

Looks like a couple of tests failed, but they look like they could be due to some jankiness with the tests. Changes in #212 will help make those more reliable. I'll re-run the build.

@danieltiger
Copy link
Contributor Author

They are passing locally, for what that's worth :)

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.09%) to 65.882% when pulling 3e9dd5a on danieltiger:assorted-improvements into b3aad6c on keenlabs:master.

@baumatron
Copy link
Contributor

Passed on this run, good to go!

@danieltiger
Copy link
Contributor Author

Cool! Merge away then, or whenever you feel comfortable :)

@baumatron baumatron merged commit 2816c7c into keenlabs:master May 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants