Notes
Notes - notes.io |
'archivedData(withRootObject:)' was deprecated in iOS 12.0: Use +archivedDataWithRootObject:requiringSecureCoding:error: instead
//
// ViewController.swift
// test
//
// Created by Sidhant Sarkar on 09/05/19.
// Copyright © 2019 Sidhant Sarkar. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let parent = dataBase()
var nsDictionary: NSDictionary?
if let path = Bundle.main.path(forResource: "datas", ofType: "plist"){
nsDictionary = NSDictionary(contentsOfFile: path)
}
var userArr : [Users] = []
for user in nsDictionary?["Users"] as! [AnyObject]{
let newUser: Users = Users(adminRights: user["adminRights"]!! as! Bool, id: user["id"]!! as! Int);
userArr.append(newUser);
}
var userNamePassArr: [userBase] = []
for data in nsDictionary?["Everything"] as! [AnyObject]{
let newData: userBase = userBase(name: data["name"]!! as! String, password: data["password"]!! as! String);
userNamePassArr.append(newData);
}
parent.userBase=userNamePassArr;
parent.users=userArr;
print(parent.view());
let enteries: NSArray = []
enteries.adding(parent);
// let file = "data.bin"
// let documents = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
// let filePath = (documents?.appendingPathComponent(file))!
print(enteries);
do {
// let parentData = try NSKeyedArchiver.archivedData(withRootObject: parent,requiringSecureCoding: false);
// print(parentData);
let data: [NSData] = [try NSKeyedArchiver .archivedData(withRootObject: parent) as NSData]
print(data[0]);
let mainD: Data = data[0] as Data;
// let printe r = try NSKeyedUnarchiver.unarchivedObject(ofClass: dataBase.self, from: data[0] as Data);
// print(printer!);
// let test = try NSKeyedUnarchiver.unarchivedObject(ofClass: dataBase.self, from: data[0] as Data);
// print(test);
if(!mainD.isEmpty){
print(mainD);
let resultData = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data[0] as Data) as! dataBase;
print(resultData);
}
// let readData = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(parentData) as? dataBase;
// print(readData!.view());
} catch{
print(error)
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Users</key>
<array>
<dict>
<key>adminRights</key>
<true/>
<key>id</key>
<integer>123</integer>
</dict>
<dict>
<key>adminRights</key>
<false/>
<key>id</key>
<integer>125</integer>
</dict>
</array>
<key>Everything</key>
<array>
<dict>
<key>name</key>
<string>Temp</string>
<key>password</key>
<string>test</string>
</dict>
<dict>
<key>name</key>
<string>Temp2</string>
<key>password</key>
<string>test</string>
</dict>
</array>
</dict>
</plist>
//
// users.swift
// test
//
// Created by Sidhant Sarkar on 09/05/19.
// Copyright © 2019 Sidhant Sarkar. All rights reserved.
//
import Foundation
class Users: NSObject,NSCoding {
// static var supportsSecureCoding: Bool{
// return true;
// }
func encode(with aCoder: NSCoder) {
aCoder.encodeConditionalObject(adminRight, forKey: "adminRight")
aCoder.encodeConditionalObject(id, forKey: "id")
}
required convenience init?(coder aDecoder: NSCoder) {
let adminRight = aDecoder.decodeObject(forKey: "adminRight") as? Bool ?? aDecoder.decodeBool(forKey: "adminRight");
guard let id = aDecoder.decodeObject(forKey: "id") as? Int else { return nil }
self.init(adminRights: adminRight, id: id);
}
let adminRight: Bool
let id: Int
init(adminRights: Bool, id: Int){
self.adminRight = adminRights;
self.id = id;
}
override var description: String {
return "User: (id) - adminRights: (adminRight)"
}
}
//
// AllData.swift
// test
//
// Created by Sidhant Sarkar on 09/05/19.
// Copyright © 2019 Sidhant Sarkar. All rights reserved.
//
import Foundation
class userBase: NSObject,NSCoding {
// static var supportsSecureCoding: Bool{
// return true;
// }
func encode(with aCoder: NSCoder) {
aCoder.encodeConditionalObject(name, forKey: "name")
aCoder.encodeConditionalObject(password, forKey: "password")
}
required convenience init?(coder aDecoder: NSCoder) {
guard let name = aDecoder.decodeObject(forKey: "name") as? String,
let password = aDecoder.decodeObject(forKey: "password") as? String else{
return nil
}
self.init(name: name, password: password);
}
let name: String
let password: String
init(name: String, password: String){
self.name = name;
self.password = password;
}
override var description: String {
return "User: (name) - (password)"
}
}
//
// parent.swift
// test
//
// Created by Sidhant Sarkar on 09/05/19.
// Copyright © 2019 Sidhant Sarkar. All rights reserved.
//
import Foundation
class dataBase: NSObject,NSCoding {
// static var supportsSecureCoding: Bool {
// return true;
// };
func encode(with aCoder: NSCoder) {
aCoder.encodeConditionalObject(users, forKey: "users")
aCoder.encodeConditionalObject(userBase, forKey: "userBase")
}
required convenience init?(coder aDecoder: NSCoder) {
guard let user = aDecoder.decodeObject(forKey: "users") as? [Users],
let userBase = aDecoder.decodeObject(forKey: "userBase") as? [userBase] else {
return nil
}
self.init(users: user, userBase: userBase)
}
var users: [Users] = []
var userBase: [userBase] = []
override init() {
super.init()
}
init(users: [Users], userBase: [userBase]){
super.init()
self.users = users;
self.userBase = userBase;
}
func view(){
for user in users{
if(user.adminRight){
print(user.id);
for users in userBase{
print(users.description)
}
}
}
}
}
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team