Skip to content

Commit

Permalink
Merge pull request #5 from readdle/fix/fix-url-session-behaviour-task…
Browse files Browse the repository at this point in the history
…-fatal

URLSession fixes
  • Loading branch information
albertaleksieiev authored Apr 2, 2019
2 parents 26f6fb4 + 9e954e0 commit 3fffd22
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Foundation/NSString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ func NSLocalizedString(_ key: String,
bundle: Bundle = Bundle.main,
value: String = "",
comment: String) -> String {
return bundle.localizedString(forKey: key, value: value, table: tableName)
#if os(Android)
return key
#else
return bundle.localizedString(forKey: key, value: value, table: tableName)
#endif
}

#if os(OSX) || os(iOS)
Expand Down
4 changes: 4 additions & 0 deletions Foundation/URLSession/TaskRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,8 @@ extension URLSession._TaskRegistry {
}
return b
}

func containsBehaviour(for task: URLSessionTask) -> Bool {
return behaviours[task.taskIdentifier] != nil
}
}
4 changes: 4 additions & 0 deletions Foundation/URLSession/URLSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,10 @@ internal extension URLSession {
}

func behaviour(for task: URLSessionTask) -> _TaskBehaviour {
guard taskRegistry.containsBehaviour(for: task) else {
return .noDelegate
}

switch taskRegistry.behaviour(for: task) {
case .dataCompletionHandler(let c): return .dataCompletionHandler(c)
case .downloadCompletionHandler(let c): return .downloadCompletionHandler(c)
Expand Down

0 comments on commit 3fffd22

Please sign in to comment.