This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by Kordian Ledzion on 15.03.2017. | |
// Copyright © 2017 Wolf Development. All rights reserved. | |
// | |
// Part of the code for HDAugumentedReality usage in one of my projects. | |
// It's showing AR pins with name and distance to locations loaded | |
import UIKit | |
import CoreLocation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Animoji { | |
case iPhoneX(String, Data) | |
case notiPhoneX(String) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Animoji { | |
fileprivate struct Serialization: Codable { | |
private var emoji: String? | |
private var expression: Data? | |
fileprivate init(animoji: Animoji) { | |
switch animoji { | |
case let .iPhoneX(emoji, expression): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Animoji: Encodable { | |
func encode(to encoder: Encoder) throws { | |
try Animoji.Serialization(animoji: self).encode(to: encoder) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let expr = "sexy gaze" | |
let jsonEncoder = JSONEncoder() | |
jsonEncoder.outputFormatting = .prettyPrinted | |
var animoji = Animoji.iPhoneX("💩", expr.data(using: .utf8)!) | |
var data = try jsonEncoder.encode(animoji) | |
var json = String(data: data, encoding: .utf8)! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"emoji" : "💩", | |
"expression" : "c2V4eSBnYXpl" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileprivate struct Serialization: Codable { | |
private struct iPhoneXData: Codable { | |
let emoji: String | |
let expression: Data | |
} | |
private var iPhoneX: iPhoneXData? | |
private var notiPhoneX: String? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"iPhoneX" : { | |
"emoji" : "💩", | |
"expression" : "c2V4eSBnYXpl" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Animoji: Codable { | |
func encode(to encoder: Encoder) throws { | |
try Animoji.Serialization(animoji: self).encode(to: encoder) | |
} | |
init(from decoder: Decoder) throws { | |
self = try Animoji.Serialization(from: decoder).animoji() | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let jsonDecoder = JSONDecoder() | |
var result = try jsonDecoder.decode(Animoji.self, from: data) |