Skip to content

Instantly share code, notes, and snippets.

View jaumevn's full-sized avatar

Jaume Viñas Navas jaumevn

View GitHub Profile
struct Device: Codable {
var name: String
var manufacturer: String
}
struct User: Encodable {
var name: String
var username: String
var phoneNumber: String
var devices: [Device]
struct Device: Codable {
var name: String
var manufacturer: String
}
struct User: Encodable {
var name: String
var username: String
var phoneNumber: String
var devices: [Device]
func decode(data: Data) throws -> User? {
do {
let decoder = JSONDecoder()
let user = try decoder.decode(User.self, from: data)
return user
} catch let error {
print(error)
return nil
}
}
struct Device: Codable {
var name: String
var manufacturer: String
}
struct User: Codable {
var name: String
var username: String
var phoneNumber: String
var devices: [Device]
struct User: Codable {
var name: String
var username: String
var phoneNumber: String
}
@jaumevn
jaumevn / parsing-json.swift
Last active October 3, 2019 10:51
Parsing JSON - Encode
struct User {
var name: String
var username: String
var phoneNumber: String
}
@jaumevn
jaumevn / compression.swift
Last active May 17, 2021 16:57
Video Compression in Swift
func compress(videoPath : String, exportVideoPath : String, renderSize : CGSize, completion : (Bool) -> ()) {
let videoUrl = NSURL(fileURLWithPath: videoPath)
if (!existsFileAtUrl(videoUrl)) {
completion(false)
return
}
let videoAssetUrl = AVURLAsset(URL: videoUrl, options: nil)