Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file removed Lesson11.zip
Binary file not shown.
4 changes: 4 additions & 0 deletions Lesson12/Lesson12.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
33A7740523E8150F00EB4880 /* WeatherDefaultLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33A7740423E8150F00EB4880 /* WeatherDefaultLoader.swift */; };
33A7740923E82DC500EB4880 /* WeatherAlamofireLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33A7740823E82DC500EB4880 /* WeatherAlamofireLoader.swift */; };
33A7740B23E82E7500EB4880 /* AlamofireViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33A7740A23E82E7500EB4880 /* AlamofireViewController.swift */; };
33BDFEA023E99156003AE604 /* RealmPersistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33BDFE9F23E99156003AE604 /* RealmPersistence.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -50,6 +51,7 @@
33A7740423E8150F00EB4880 /* WeatherDefaultLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherDefaultLoader.swift; sourceTree = "<group>"; };
33A7740823E82DC500EB4880 /* WeatherAlamofireLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherAlamofireLoader.swift; sourceTree = "<group>"; };
33A7740A23E82E7500EB4880 /* AlamofireViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlamofireViewController.swift; sourceTree = "<group>"; };
33BDFE9F23E99156003AE604 /* RealmPersistence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RealmPersistence.swift; sourceTree = "<group>"; };
91C68B5163A7CA7C1287699C /* Pods_Lesson12.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Lesson12.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9B7523B53070EB53FD063DD0 /* Pods-Lesson12.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Lesson12.debug.xcconfig"; path = "Target Support Files/Pods-Lesson12/Pods-Lesson12.debug.xcconfig"; sourceTree = "<group>"; };
C1392FDE9539F4D5F49419A4 /* Pods-Lesson12.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Lesson12.release.xcconfig"; path = "Target Support Files/Pods-Lesson12/Pods-Lesson12.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -99,6 +101,7 @@
3368995D23E4748C0082F091 /* DefaultViewController.swift */,
3368995F23E475FD0082F091 /* WeatherTableViewCell.swift */,
33A7740A23E82E7500EB4880 /* AlamofireViewController.swift */,
33BDFE9F23E99156003AE604 /* RealmPersistence.swift */,
);
path = Lesson12;
sourceTree = "<group>";
Expand Down Expand Up @@ -253,6 +256,7 @@
3368995E23E4748C0082F091 /* DefaultViewController.swift in Sources */,
3396C6AC23E470A400DF9AD8 /* AppDelegate.swift in Sources */,
3396C6AE23E470A400DF9AD8 /* SceneDelegate.swift in Sources */,
33BDFEA023E99156003AE604 /* RealmPersistence.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 2 additions & 0 deletions Lesson12/Lesson12/AlamofireViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class AlamofireViewController: UIViewController, DTTableViewManageable {
super.viewDidLoad()

manager.register(WeatherTableViewCell.self)
nameCityLabel.text = "Loading..."
manager.memoryStorage.setItems(RealmPersistence.storage.getSaveDatabase())

WeatherAlamofireLoader().loadWeather { [unowned self] nameCity, weather in
self.nameCityLabel.text = nameCity
Expand Down
2 changes: 1 addition & 1 deletion Lesson12/Lesson12/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15705" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15705" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="jdS-fW-zDw">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/>
Expand Down
3 changes: 3 additions & 0 deletions Lesson12/Lesson12/DefaultViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class DefaultViewController: UIViewController, DTTableViewManageable {
super.viewDidLoad()

manager.register(WeatherTableViewCell.self)
nameCityLabel.text = "Loading..."
manager.memoryStorage.setItems(RealmPersistence.storage.getSaveDatabase())
RealmPersistence.storage.clearDatabase()

WeatherDefaultLoader().loadWeather { [unowned self] nameCity, weather in
self.nameCityLabel.text = nameCity
Expand Down
1 change: 1 addition & 0 deletions Lesson12/Lesson12/Loaders/WeatherAlamofireLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class WeatherAlamofireLoader {
cityName = city["name"] as! String
}

RealmPersistence.storage.replaceSaveDatabase(database: weather)

DispatchQueue.main.async {
completion(cityName, weather)
Expand Down
1 change: 1 addition & 0 deletions Lesson12/Lesson12/Loaders/WeatherDefaultLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class WeatherDefaultLoader {
cityName = city["name"] as! String
}

RealmPersistence.storage.replaceSaveDatabase(database: weather)

DispatchQueue.main.async {
completion(cityName, weather)
Expand Down
45 changes: 45 additions & 0 deletions Lesson12/Lesson12/RealmPersistence.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// RealmPersistence.swift
// Lesson12
//
// Created by Михаил Беленко on 04.02.2020.
// Copyright © 2020 Михаил Беленко. All rights reserved.
//

import RealmSwift

class RealmPersistence {

static var storage = RealmPersistence()

var realm = try! Realm()

func addEntry(entry: WeatherTableViewCellModel) {
try! realm.write {
realm.add(entry)
}
}

func replaceSaveDatabase(database: [WeatherTableViewCellModel]) {
clearDatabase()
for entry in database {
addEntry(entry: entry)
}
}

func getSaveDatabase() -> [WeatherTableViewCellModel] {
var database: [WeatherTableViewCellModel] = []
for entry in realm.objects(WeatherTableViewCellModel.self) {
database.append(entry)
}
return database
}

func clearDatabase() {
let database = realm.objects(WeatherTableViewCellModel.self)

try! realm.write {
realm.delete(database)
}
}
}
16 changes: 12 additions & 4 deletions Lesson12/Lesson12/WeatherTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import UIKit
import DTModelStorage
import SnapKit
import RealmSwift

class WeatherTableViewCell: UITableViewCell, ModelTransfer {

Expand Down Expand Up @@ -78,10 +79,10 @@ class WeatherTableViewCell: UITableViewCell, ModelTransfer {

}

struct WeatherTableViewCellModel {
let dt: String
let tempMin: Double
let tempMax: Double
class WeatherTableViewCellModel: Object {
@objc dynamic var dt: String
@objc dynamic var tempMin: Double
@objc dynamic var tempMax: Double

init?(data: NSDictionary) {
guard let main = data["main"] as? NSDictionary,
Expand All @@ -96,4 +97,11 @@ struct WeatherTableViewCellModel {
self.tempMin = tempMin
self.tempMax = tempMax
}

required init() {
self.dt = ""
self.tempMin = 0.0
self.tempMax = 0.0
super.init()
}
}
1 change: 1 addition & 0 deletions Lesson12/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ target 'Lesson12' do
# Pods for Lesson12
pod 'DTTableViewManager'
pod 'SnapKit', '~> 5.0.0'
pod 'RealmSwift'

end
12 changes: 11 additions & 1 deletion Lesson12/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,33 @@ PODS:
- DTModelStorage/Core (8.0.0)
- DTTableViewManager (7.0.0):
- DTModelStorage (~> 8.0.0)
- Realm (4.3.1):
- Realm/Headers (= 4.3.1)
- Realm/Headers (4.3.1)
- RealmSwift (4.3.1):
- Realm (= 4.3.1)
- SnapKit (5.0.1)

DEPENDENCIES:
- DTTableViewManager
- RealmSwift
- SnapKit (~> 5.0.0)

SPEC REPOS:
trunk:
- DTModelStorage
- DTTableViewManager
- Realm
- RealmSwift
- SnapKit

SPEC CHECKSUMS:
DTModelStorage: 3b86a1e37496532bbd74cadc5b9310238d5ba780
DTTableViewManager: 0ada743292338c2e7b5494f41544afc9d3055fbb
Realm: 31dc40934081ef740f60feedc46d88473cbfeb40
RealmSwift: b5199e9a41f67b99f51acf6874a6166f5fbe93d1
SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb

PODFILE CHECKSUM: 15554f5265c6da081e8095229ca4d102df061a46
PODFILE CHECKSUM: 449a2a07f00ced4688fc3cfec25ae2fabb124a77

COCOAPODS: 1.8.4
12 changes: 11 additions & 1 deletion Lesson12/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading