-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alcala, Jose Luis
authored and
Alcala, Jose Luis
committed
Nov 23, 2017
1 parent
e38b850
commit 8683d51
Showing
13 changed files
with
182 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 5 additions & 3 deletions
8
Example/SwifttorExample/Pods/Swifttor/Swifttor/ActorSystem.swift
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
38 changes: 27 additions & 11 deletions
38
Example/SwifttorExample/Pods/Swifttor/Swifttor/Future.swift
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// Model.swift | ||
// SwifttorExample | ||
// | ||
// Created by Alcala, Jose Luis on 11/23/17. | ||
// Copyright © 2017 Alcala, Jose Luis. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Model:Codable{ | ||
let origin:String | ||
} |
39 changes: 39 additions & 0 deletions
39
Example/SwifttorExample/SwifttorExample/NetworkActor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// NetworkActor.swift | ||
// SwifttorExample | ||
// | ||
// Created by Alcala, Jose Luis on 11/23/17. | ||
// Copyright © 2017 Alcala, Jose Luis. All rights reserved. | ||
// | ||
|
||
import Swifttor | ||
import Foundation | ||
enum NetWorkMessages{ | ||
case fetchFromNetwork(url:URL) | ||
} | ||
|
||
struct NetworkActor: ActorAsk { | ||
|
||
typealias ResultType = Result<Data,String> | ||
|
||
typealias MessageType = NetWorkMessages | ||
|
||
func reiciveAsk(message: NetWorkMessages,completion:@escaping (Result<Data,String>)->()) { | ||
switch message { | ||
case .fetchFromNetwork(let url): | ||
perfomNetWorkCall(url: url, completion: completion) | ||
} | ||
} | ||
|
||
|
||
func perfomNetWorkCall(url:URL,completion:@escaping (Result<Data,String>)->()){ | ||
let session = URLSession(configuration: .ephemeral) | ||
session.dataTask(with: url, completionHandler: { (data, response, err) in | ||
if let dat = data{ | ||
completion(Result.success(result: dat)) | ||
}else{ | ||
completion(Result.failure(error: "error happend")) | ||
} | ||
}).resume() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// ParserActor.swift | ||
// SwifttorExample | ||
// | ||
// Created by Alcala, Jose Luis on 11/23/17. | ||
// Copyright © 2017 Alcala, Jose Luis. All rights reserved. | ||
// | ||
|
||
import Swifttor | ||
|
||
enum ParserkMessages{ | ||
case parseToModel(data:Data) | ||
} | ||
|
||
struct ParserActor: ActorAsk { | ||
|
||
typealias ResultType = Result<Model,String> | ||
typealias MessageType = ParserkMessages | ||
|
||
func reiciveAsk(message: Result<Data,String>, completion: @escaping (Result<Model, String>) -> ()) { | ||
switch message { | ||
case .parseToModel(let data): | ||
if let result = try? JSONDecoder().decode(Model.self, from: data){ | ||
completion(Result.success(result: result)) | ||
}else{ | ||
completion(Result.failure(error: "Cannot parse")) | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters