-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLikeIt.swift
55 lines (41 loc) · 1.38 KB
/
LikeIt.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// LikeIt.swift
// Music ++
//
// Created by QUANG on 1/22/17.
// Copyright © 2017 Q.U.A.N.G. All rights reserved.
//
import os.log
import MediaPlayer
class LikeIt: NSObject, NSCoding {
//MARK: Types
struct PropertyKey {
static let ID = "ID"
static let liked = "liked"
}
//MARK: Properties
var ID: MPMediaEntityPersistentID
var liked: Bool
//MARK: Archiving Paths
static let DocumentsDirectory = FileManager().urls(for: .documentDirectory, in: .userDomainMask).first!
static let ArchiveURL = DocumentsDirectory.appendingPathComponent("LikeIt")
//MARK: Initialization
init?(ID: MPMediaEntityPersistentID, liked: Bool) {
self.ID = ID
self.liked = liked
}
//MARK: NSCoding
func encode(with aCoder: NSCoder) {
aCoder.encode(ID, forKey: PropertyKey.ID)
aCoder.encode(liked, forKey: PropertyKey.liked)
}
required convenience init?(coder aDecoder: NSCoder) {
guard let ID = aDecoder.decodeObject(forKey: PropertyKey.ID) as? MPMediaEntityPersistentID else {
os_log("Unable to decode ID.", log: OSLog.default, type: .debug)
return nil
}
let liked = aDecoder.decodeBool(forKey: PropertyKey.liked)
// Must call designated initializer.
self.init(ID: ID, liked: liked)
}
}