Skip to content

Instantly share code, notes, and snippets.

@vikdenic
Created September 27, 2017 16:54
Show Gist options
  • Save vikdenic/e4f33fe8b4f1fb5006a5185ae417e894 to your computer and use it in GitHub Desktop.
Save vikdenic/e4f33fe8b4f1fb5006a5185ae417e894 to your computer and use it in GitHub Desktop.
EmojiItem.swift 9/27/17 12pm
//
// EmojiItem.swift
// SpokinModel
//
// Created by Kevin McQuown on 9/21/17.
// Copyright © 2017 Spokin. All rights reserved.
//
import Foundation
public class EmojiItem {
public var gender: Gender!
public var colorCode: String!
public var color: UIColor?
public var styleCode: String!
public var isSelected = false
init(dict: [String: Any]) {
if let colorCode = dict["color"] as? String {
self.colorCode = colorCode
}
if let styleCode = dict["style"] as? String {
self.styleCode = styleCode
}
if let colorHexString = dict["colorHex"] as? String {
self.color = UIColor(hex: colorHexString)
}
}
}
public class EmojiItemCategory {
public var name: String!
public var displayName: String!
public var genderString: String!
public var emojiItems = [EmojiItem]()
init(dict: [String: Any], genderString: String) {
self.name = dict["name"] as? String
self.genderString = genderString
self.displayName = dict["displayName"] as? String
var setFirstItemAsSelected = false
for subItemDict in (dict["subItems"] as! [[String : Any]]) {
let emojiItem = EmojiItem(dict: subItemDict)
emojiItem.gender = Gender(rawValue: self.genderString)
if setFirstItemAsSelected == false {
emojiItem.isSelected = true
setFirstItemAsSelected = true
}
emojiItems.append(emojiItem)
}
}
}
extension UIColor {
convenience init(hex: String) {
let scanner = Scanner(string: hex)
scanner.scanLocation = 0
var rgbValue: UInt64 = 0
scanner.scanHexInt64(&rgbValue)
let r = (rgbValue & 0xff0000) >> 16
let g = (rgbValue & 0xff00) >> 8
let b = rgbValue & 0xff
self.init(
red: CGFloat(r) / 0xff,
green: CGFloat(g) / 0xff,
blue: CGFloat(b) / 0xff, alpha: 1
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment