Skip to content

Commit

Permalink
Fix trackers list out of bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Nov 22, 2024
1 parent ec6c70a commit 4bb1d10
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private extension TorrentTrackersViewModel {

var newTrackers: [TrackerCellViewModel] = []
var trackerListChanged = false
for tracker in torrentHandle.trackers {
for tracker in torrentHandle.snapshot.trackers {
if let oldTracker = trackers.first(where: { $0.url == tracker.trackerUrl }) {
oldTracker.update(with: tracker)
newTrackers.append(oldTracker)
Expand Down
9 changes: 5 additions & 4 deletions iTorrent/Utils/NSUserDefaultItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ private extension NSUserDefaultItem {
return try? NSKeyedUnarchiver.unarchivedObject(ofClass: Value.self, from: data)
}

static func setValue(_ value: Value, for key: String) {
do {
let data = try NSKeyedArchiver.archivedData(withRootObject: value, requiringSecureCoding: true)
static func setValue(_ value: Value?, for key: String) {
if let value, let data = try? NSKeyedArchiver.archivedData(withRootObject: value, requiringSecureCoding: true) {
userDefaults.set(data, forKey: key)
} catch {}
} else {
userDefaults.set(nil, forKey: key)
}
}
}
9 changes: 4 additions & 5 deletions iTorrent/Utils/UserDefaultItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ private extension UserDefaultItem {
static var userDefaults: UserDefaults { .itorrentGroup }

static func value(for key: String) -> Value? {
guard let decoded = userDefaults.data(forKey: key),
let res = try? JSONDecoder().decode(Value.self, from: decoded)
guard let data = userDefaults.data(forKey: key)
else { return nil }
return res
return try? JSONDecoder().decode(Value.self, from: data)
}

static func setValue(_ value: Value?, for key: String) {
if let value, let encodedData: Data = try? JSONEncoder().encode(value) {
userDefaults.set(encodedData, forKey: key)
if let value, let data: Data = try? JSONEncoder().encode(value) {
userDefaults.set(data, forKey: key)
} else {
userDefaults.set(nil, forKey: key)
}
Expand Down

0 comments on commit 4bb1d10

Please sign in to comment.