Skip to content

Commit

Permalink
New api
Browse files Browse the repository at this point in the history
  • Loading branch information
Alcala, Jose Luis authored and Alcala, Jose Luis committed Nov 23, 2017
1 parent e38b850 commit 8683d51
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Example/SwifttorExample/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ EXTERNAL SOURCES:

CHECKOUT OPTIONS:
Swifttor:
:commit: 999302b5a6ebcd776cfc417c7311ba01d5c48053
:commit: e38b8500900f0ace7a1929407ac5bed8bea7e9b5
:git: https://github.com/josete89/swifttor.git

SPEC CHECKSUMS:
Expand Down
2 changes: 1 addition & 1 deletion Example/SwifttorExample/Pods/Manifest.lock

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

7 changes: 3 additions & 4 deletions Example/SwifttorExample/Pods/Swifttor/Swifttor/Actor.swift

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

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

38 changes: 27 additions & 11 deletions Example/SwifttorExample/Pods/Swifttor/Swifttor/Future.swift

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

12 changes: 12 additions & 0 deletions Example/SwifttorExample/SwifttorExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
03A9D3A4D0AC69805744ADDB /* Pods_SwifttorExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5C00D26609ED77AEBACAA827 /* Pods_SwifttorExample.framework */; };
B5708FEC7AA4B8152CD1097F /* Pods_SwifttorExampleUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 49E9846B6F961486DA9D1B04 /* Pods_SwifttorExampleUITests.framework */; };
D8150D151FC6CA5800E84EFF /* ParserActor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8150D141FC6CA5800E84EFF /* ParserActor.swift */; };
D89045041FC5F59800DC6AA3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89045031FC5F59800DC6AA3 /* AppDelegate.swift */; };
D89045061FC5F59800DC6AA3 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89045051FC5F59800DC6AA3 /* ViewController.swift */; };
D89045091FC5F59800DC6AA3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D89045071FC5F59800DC6AA3 /* Main.storyboard */; };
Expand All @@ -17,6 +18,8 @@
D89045191FC5F59900DC6AA3 /* SwifttorExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89045181FC5F59900DC6AA3 /* SwifttorExampleTests.swift */; };
D89045241FC5F59900DC6AA3 /* SwifttorExampleUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89045231FC5F59900DC6AA3 /* SwifttorExampleUITests.swift */; };
D89045321FC5F70D00DC6AA3 /* MainActor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89045311FC5F70D00DC6AA3 /* MainActor.swift */; };
D89045341FC6C34900DC6AA3 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89045331FC6C34900DC6AA3 /* Model.swift */; };
D89045361FC6C3D500DC6AA3 /* NetworkActor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89045351FC6C3D500DC6AA3 /* NetworkActor.swift */; };
DAA8354DF87B48D66C463535 /* Pods_SwifttorExampleTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1B73DF7353300151FA650774 /* Pods_SwifttorExampleTests.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -46,6 +49,7 @@
621BDE24AAD48B52E860F1CE /* Pods-SwifttorExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwifttorExampleTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-SwifttorExampleTests/Pods-SwifttorExampleTests.release.xcconfig"; sourceTree = "<group>"; };
B7810D5EA23F8FF9029DA795 /* Pods-SwifttorExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwifttorExampleTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SwifttorExampleTests/Pods-SwifttorExampleTests.debug.xcconfig"; sourceTree = "<group>"; };
BC26DC9D0C325DCF1D10D4D4 /* Pods-SwifttorExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwifttorExample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SwifttorExample/Pods-SwifttorExample.debug.xcconfig"; sourceTree = "<group>"; };
D8150D141FC6CA5800E84EFF /* ParserActor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParserActor.swift; sourceTree = "<group>"; };
D89045001FC5F59800DC6AA3 /* SwifttorExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwifttorExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
D89045031FC5F59800DC6AA3 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
D89045051FC5F59800DC6AA3 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand All @@ -60,6 +64,8 @@
D89045231FC5F59900DC6AA3 /* SwifttorExampleUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwifttorExampleUITests.swift; sourceTree = "<group>"; };
D89045251FC5F59900DC6AA3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D89045311FC5F70D00DC6AA3 /* MainActor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainActor.swift; sourceTree = "<group>"; };
D89045331FC6C34900DC6AA3 /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = "<group>"; };
D89045351FC6C3D500DC6AA3 /* NetworkActor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkActor.swift; sourceTree = "<group>"; };
F98F9FEEBB507B4B82801AB0 /* Pods-SwifttorExampleUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwifttorExampleUITests.release.xcconfig"; path = "Pods/Target Support Files/Pods-SwifttorExampleUITests/Pods-SwifttorExampleUITests.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -146,6 +152,9 @@
D890450C1FC5F59800DC6AA3 /* LaunchScreen.storyboard */,
D890450F1FC5F59800DC6AA3 /* Info.plist */,
D89045311FC5F70D00DC6AA3 /* MainActor.swift */,
D89045331FC6C34900DC6AA3 /* Model.swift */,
D89045351FC6C3D500DC6AA3 /* NetworkActor.swift */,
D8150D141FC6CA5800E84EFF /* ParserActor.swift */,
);
path = SwifttorExample;
sourceTree = "<group>";
Expand Down Expand Up @@ -462,8 +471,11 @@
buildActionMask = 2147483647;
files = (
D89045321FC5F70D00DC6AA3 /* MainActor.swift in Sources */,
D89045361FC6C3D500DC6AA3 /* NetworkActor.swift in Sources */,
D89045061FC5F59800DC6AA3 /* ViewController.swift in Sources */,
D89045041FC5F59800DC6AA3 /* AppDelegate.swift in Sources */,
D8150D151FC6CA5800E84EFF /* ParserActor.swift in Sources */,
D89045341FC6C34900DC6AA3 /* Model.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down
5 changes: 5 additions & 0 deletions Example/SwifttorExample/SwifttorExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand Down
30 changes: 13 additions & 17 deletions Example/SwifttorExample/SwifttorExample/MainActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,28 @@

import Swifttor

enum MainActorMessages {
case displayInfo(callback:(Model) -> (),data:Model)
case refreshStuffWithData(callback:(String) -> (),data:String)
case refreshStuff(callbac:() -> ())
}


struct MainActor<T>: ActorTell {


struct MainActor: ActorTell {

typealias MessageType = MainActorMessages
var name:String {
return "etes"
}

var queue: DispatchQueue {
return DispatchQueue.main
}

enum MainActorMessages {
case refreshStuffWithData(callback:(T) -> (),data:T)
case refreshStuff(callbac:() -> ())
}


func reiciveTell(message: MainActor.MainActorMessages) {
func reiciveTell(message: MainActorMessages) {
switch message {
case .refreshStuffWithData(let callback,let data):
callback(data)
case .refreshStuff(let callback):
callback()
case .refreshStuffWithData(let callback, let data):
case .displayInfo(let callback,let data):
callback(data)
}

}

}
13 changes: 13 additions & 0 deletions Example/SwifttorExample/SwifttorExample/Model.swift
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 Example/SwifttorExample/SwifttorExample/NetworkActor.swift
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()
}
}
31 changes: 31 additions & 0 deletions Example/SwifttorExample/SwifttorExample/ParserActor.swift
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"))
}
}
}

}
28 changes: 27 additions & 1 deletion Example/SwifttorExample/SwifttorExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,38 @@ import UIKit
import Swifttor
class ViewController: UIViewController {

let actorRef = ActorSystem.


override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let actorRef = ActorSystem.actorOf(actorType: MainActor.self)


let networkActor = ActorSystem.actorOf(actorType: NetworkActor.self)
let parserActor = ActorSystem.actorOf(actorType: ParserActor.self)
networkActor.ask(.fetchFromNetwork(url: URL(string: "https://httpbin.org/ip")!)) >>> parserActor.ask

res.onResult(callback: { r in
switch r{
case .success(result: let res):
parserActor.ask(ParserkMessages.parseToModel(data: res)).onResult(callback: { res1 in
switch res1{
case .success( let res2):
actorRef.tell(MainActorMessages.refreshStuffWithData(callback: { input in
print(input)
}, data: res2.origin))
case .failure(let error):
actorRef.tell(MainActorMessages.refreshStuffWithData(callback: { input in
print(input)
}, data: error))
}

})
case .failure(error: let err):
print("hack")
}
})

}

Expand Down

0 comments on commit 8683d51

Please sign in to comment.