From 5897ff2c58f87fcda5f884b6e5644936625e7c58 Mon Sep 17 00:00:00 2001 From: iska Date: Sun, 15 Mar 2015 17:49:05 +0100 Subject: [PATCH] Use ordered dictionary for the HTML Element's attributes --- HTMLKit/HTMLElement.h | 4 ++-- HTMLKit/HTMLElement.m | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/HTMLKit/HTMLElement.h b/HTMLKit/HTMLElement.h index ea0f15e..499c855 100644 --- a/HTMLKit/HTMLElement.h +++ b/HTMLKit/HTMLElement.h @@ -23,7 +23,7 @@ @property (nonatomic, copy) NSString *className; - (instancetype)initWithTagName:(NSString *)tagName; -- (instancetype)initWithTagName:(NSString *)tagName attributes:(id)attributes; -- (instancetype)initWithTagName:(NSString *)tagName attributes:(id)attributes namespace:(HTMLNamespace)namespace; +- (instancetype)initWithTagName:(NSString *)tagName attributes:(NSDictionary *)attributes; +- (instancetype)initWithTagName:(NSString *)tagName attributes:(NSDictionary *)attributes namespace:(HTMLNamespace)namespace; @end diff --git a/HTMLKit/HTMLElement.m b/HTMLKit/HTMLElement.m index e3d2a61..1c9ff5a 100644 --- a/HTMLKit/HTMLElement.m +++ b/HTMLKit/HTMLElement.m @@ -7,6 +7,13 @@ // #import "HTMLElement.h" +#import "HTMLOrderedDictionary.h" + +@interface HTMLElement () +{ + HTMLOrderedDictionary *_attributes; +} +@end @implementation HTMLElement @@ -20,17 +27,20 @@ return [self initWithTagName:tagName attributes:nil]; } -- (instancetype)initWithTagName:(NSString *)tagName attributes:(id)attributes +- (instancetype)initWithTagName:(NSString *)tagName attributes:(NSDictionary *)attributes { return [self initWithTagName:tagName attributes:attributes namespace:HTMLNamespaceHTML]; } -- (instancetype)initWithTagName:(NSString *)tagName attributes:(id)attributes namespace:(HTMLNamespace)namespace +- (instancetype)initWithTagName:(NSString *)tagName attributes:(NSDictionary *)attributes namespace:(HTMLNamespace)namespace { self = [super initWithName:tagName type:HTMLNodeElement]; if (self) { _tagName = tagName; -#warning Attributes + _attributes = [HTMLOrderedDictionary new]; + if (attributes != nil) { + [_attributes addEntriesFromDictionary:attributes]; + } _namespace = namespace; } return self;