View Codable9block.swift
let jsonDecoder = JSONDecoder() | |
var result = try jsonDecoder.decode(Animoji.self, from: data) |
View Codable8block.swift
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() | |
} |
View Codable7block.json
{ | |
"iPhoneX" : { | |
"emoji" : "💩", | |
"expression" : "c2V4eSBnYXpl" | |
} | |
} |
View Codable6block.swift
fileprivate struct Serialization: Codable { | |
private struct iPhoneXData: Codable { | |
let emoji: String | |
let expression: Data | |
} | |
private var iPhoneX: iPhoneXData? | |
private var notiPhoneX: String? |
View Codable5block.json
{ | |
"emoji" : "💩", | |
"expression" : "c2V4eSBnYXpl" | |
} |
View Codable4block.swift
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)! |
View Codable3block.swift
extension Animoji: Encodable { | |
func encode(to encoder: Encoder) throws { | |
try Animoji.Serialization(animoji: self).encode(to: encoder) | |
} | |
} |
View Codable2block.swift
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): |
View Codable1block.swift
enum Animoji { | |
case iPhoneX(String, Data) | |
case notiPhoneX(String) | |
} |
View HDAugumentedRealityExampleUsage.swift
// | |
// 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 |