Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(474)

Unified Diff: ios/chrome/browser/content_suggestions/content_suggestions_category_wrapper.mm

Issue 2689953003: Add Category wrapper for ContentSuggestions on iOS (Closed)
Patch Set: Fix title copu Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..cc342d5388e749ed72578d7542a0b71ce8ed872f
--- /dev/null
+++ b/ios/chrome/browser/content_suggestions/content_suggestions_category_wrapper.mm
@@ -0,0 +1,64 @@
+// 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
+
+@interface ContentSuggestionsCategoryWrapper ()
+
+@property(nonatomic, assign) int categoryID;
+
+@end
+
+@implementation ContentSuggestionsCategoryWrapper
+
+@synthesize categoryID = _categoryID;
+
+- (instancetype)initWithCategory:(ntp_snippets::Category)category {
+ self = [super init];
+ if (self) {
+ _categoryID = category.id();
+ }
+ return self;
+}
+
+- (ntp_snippets::Category)category {
+ return ntp_snippets::Category::FromIDValue(self.categoryID);
+}
+
+#pragma mark - NSObject
+
+- (BOOL)isEqual:(id)object {
+ if (self == object) {
+ return YES;
+ }
+
+ if (![object isKindOfClass:[ContentSuggestionsCategoryWrapper class]]) {
+ return NO;
+ }
+
+ ContentSuggestionsCategoryWrapper* other =
+ base::mac::ObjCCastStrict<ContentSuggestionsCategoryWrapper>(object);
+
+ return self.category == other.category;
+}
+
+- (NSUInteger)hash {
+ return self.categoryID;
+}
+
+#pragma mark - NSCopying
+
+- (id)copyWithZone:(nullable NSZone*)zone {
+ ContentSuggestionsCategoryWrapper* copy =
+ [[[self class] allocWithZone:zone] initWithCategory:self.category];
+ return copy;
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698