[ABANDONED] Mastodon iOS client.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.3 KiB

6 years ago
  1. //
  2. // AuthenticationManager.swift
  3. // elpha-ios
  4. //
  5. // Created by Dwayne Harris on 8/25/18.
  6. // Copyright © 2018 Elpha. All rights reserved.
  7. //
  8. import CoreData
  9. import Foundation
  10. import UIKit
  11. class AuthenticationManager {
  12. static let shared = AuthenticationManager()
  13. var sessionCount: Int {
  14. get {
  15. let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
  16. let request = NSFetchRequest<Session>(entityName: "Session")
  17. do {
  18. return try context.count(for: request)
  19. } catch {
  20. print("Error counting Sessions")
  21. print("\(error)")
  22. return 0
  23. }
  24. }
  25. }
  26. var selectedSession: Session? {
  27. get {
  28. let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
  29. let request = NSFetchRequest<Session>(entityName: "Session")
  30. request.predicate = NSPredicate(format: "selected = YES")
  31. do {
  32. let results = try context.fetch(request)
  33. return results.first
  34. } catch {
  35. print("Error fetching Session")
  36. print("\(error)")
  37. return nil
  38. }
  39. }
  40. }
  41. private init() {}
  42. }