Chromium Code Reviews| Index: ios/chrome/browser/content_suggestions/content_suggestions_category_wrapper.mm |
| diff --git a/ios/chrome/browser/content_suggestions/content_suggestions_category_wrapper.mm b/ios/chrome/browser/content_suggestions/content_suggestions_category_wrapper.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c7c2b7488003ac7bb0609d30609e642c12a20c5c |
| --- /dev/null |
| +++ b/ios/chrome/browser/content_suggestions/content_suggestions_category_wrapper.mm |
| @@ -0,0 +1,56 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ios/chrome/browser/content_suggestions/content_suggestions_category_wrapper.h" |
| + |
| +#include "base/mac/foundation_util.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +@implementation ContentSuggestionsCategoryWrapper { |
| + int _categoryID; |
|
stkhapugin
2017/02/13 12:19:18
Since this is a primitive and not a C++ object, yo
gambard
2017/02/13 14:51:41
Done.
|
| +} |
| + |
| +- (instancetype)initWithCategory:(ntp_snippets::Category)category { |
| + self = [super init]; |
| + if (self) { |
| + _categoryID = category.id(); |
| + } |
| + return self; |
| +} |
| + |
| +- (BOOL)isEqual:(id)object { |
| + if (self == object) { |
| + return YES; |
| + } |
| + |
| + if (![object isKindOfClass:[ContentSuggestionsCategoryWrapper class]]) { |
|
stkhapugin
2017/02/13 12:19:18
s/isKindOfClass/isMemberOfClass
lpromero
2017/02/13 12:34:55
Why? Subclassing would mean two objects couldn't b
stkhapugin
2017/02/13 13:31:38
Since subclasses are generally different from thei
lpromero
2017/02/13 13:55:32
I don't have any particular point of view on this.
gambard
2017/02/13 14:51:41
I keep it this way.
|
| + return NO; |
| + } |
| + |
| + ContentSuggestionsCategoryWrapper* other = |
| + base::mac::ObjCCastStrict<ContentSuggestionsCategoryWrapper>(object); |
| + |
| + return self.category == other.category; |
| +} |
| + |
| +- (NSUInteger)hash { |
|
stkhapugin
2017/02/13 12:19:18
-hash and -isEqual are usually put in a #pragma ma
gambard
2017/02/13 14:51:41
Done.
|
| + return _categoryID; |
| +} |
| + |
| +- (ntp_snippets::Category)category { |
| + return ntp_snippets::Category::FromIDValue(_categoryID); |
| +} |
| + |
| +#pragma mark - NSCopying |
| + |
| +- (id)copyWithZone:(nullable NSZone*)zone { |
| + ContentSuggestionsCategoryWrapper* copy = |
| + [[[self class] allocWithZone:zone] initWithCategory:self.category]; |
| + return copy; |
| +} |
| + |
| +@end |