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

Clean up SDL Structs with a category on NSMutableDictionary #21

Closed
justinjdickow opened this issue Oct 30, 2014 · 0 comments
Closed

Clean up SDL Structs with a category on NSMutableDictionary #21

justinjdickow opened this issue Oct 30, 2014 · 0 comments
Assignees

Comments

@justinjdickow
Copy link
Contributor

Every setter method in every SDLRPCStruct subclass takes an object and sets it in the store. If the object passed into the method is nil, the object is removed from the store instead (because passing nil to setObject throws an NSInvalidArgumentException). This makes every setter look like

-(void) setNavigationText:(NSString*) navigationText {
    if (navigationText != nil) {
        [store setObject:navigationText forKey:NAMES_navigationText];
    } else {
        [store removeObjectForKey:NAMES_navigationText];
    }
}

This can be cleaned up by creating a category on NSMutableDictionary and including it in the SDLRPCStruct class. It would look like

- (void)setOrRemoveObject:(id)object forKey:(id <NSCopying>)key {
    if (nil != object) {
        [self setObject:object forKey:key];
    } else {
        [self removeObjectForKey:key];
    }
}

Then every setter can be reduced to

- (void)setNavigationText:(NSString *)navigationText {
    [store setOrRemoveObject:navigationText forKey:NAMES_navigationText];
}
@justinjdickow justinjdickow self-assigned this Oct 30, 2014
davidswi pushed a commit to davidswi/sdl_ios that referenced this issue May 18, 2017
…L-872 to master

* commit '6276c5abb2a0f50d270112872845a42bbc20aa06':
  Fix incorrect logic for isStopped getter.
  Check for nil session objects before closing and merge background task changes.
  Check for both control and data session stopped on transport dispose.
  Guard against destroying transport before session is stopped.
davidswi pushed a commit to davidswi/sdl_ios that referenced this issue Nov 15, 2017
…29 to xevo_master

* commit 'b8e401d4e09bdcb6402fd453575c2aa6e411fb17':
  Remove #define/ifdef around lockscreen icon download.
  Use properties to set up task in more sane order and protect against empty icon data.
  Cancel proxy timer on dealloc.
  Protocol index cancel on dealloc.
kshala-ford pushed a commit to kshala-ford/sdl_ios that referenced this issue Oct 15, 2020
…wer_to_the_box

[F099] Remote Control - Power to the Box
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants