Skip to content

Instantly share code, notes, and snippets.

View RPallas92's full-sized avatar

Ricardo Pallas RPallas92

View GitHub Profile
enum Event {
case addTodo(Todo)
case toggleTodo(Todo)
case setVisibilityFilter(VisibilityFilter)
}
func reduce(state: State, event: Event) -> State {
switch event {
case .addTodo(let todo):
var newState = state
newState.todos = state.todos + [todo]
return newState
case .toggleTodo(let todo):
var newState = state
newState.todos = state.todos.map { t in
var newTodo = t
func loginWithFacebook() -> AsyncResult<Context, String, GenericError> {
return AsyncResult.unfoldTT{ context, continuation in
let loginManager = LoginManager()
loginManager.logIn([ .publicProfile ], viewController: self) { loginResult in
switch loginResult {
case .Failed(let error):
continuation(Result.failure(error))
case .Cancelled:
continuation(Result.failure(LoginCancelledError()))
case .Success(let grantedPermissions, let declinedPermissions, let accessToken):
enum Event {
case addTodo(Todo)
case toggleTodo(Todo)
case setVisibilityFilter(VisibilityFilter)
case storeTodos()
case todosStored(Bool)
}
struct State {
var todos: [Todo]
class CounterViewController: UIViewController {
@IBOutlet weak var label: UILabel?
@IBOutlet weak var minus: UIButton?
@IBOutlet weak var plus: UIButton?
override func viewDidLoad() {
super.viewDidLoad()
typealias State = Int
protocol BaseContext {
var cloudKitApiKey: String {get}
var todosDataSource: TodosDataSource {get}
}
class AppContext: BaseContext {
var cloudKitApiKey = "sjsfAJ&76sdgjhs3434JHS3"
var todosDataSource: TodosDataSource = TodosCloudKitDataSource()
}
class TodosListContext: AppContext {