{"id":16203294,"url":"https://github.com/sschmid/floc-commands","last_synced_at":"2025-03-19T07:30:47.505Z","repository":{"id":56911463,"uuid":"10946791","full_name":"sschmid/Floc-Commands","owner":"sschmid","description":"A collection of commands with fluent API for Objective-C.","archived":false,"fork":false,"pushed_at":"2013-07-17T21:46:08.000Z","size":512,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-28T16:18:12.432Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sschmid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-06-25T18:41:24.000Z","updated_at":"2023-07-03T16:50:07.000Z","dependencies_parsed_at":"2022-08-21T03:20:18.730Z","dependency_job_id":null,"html_url":"https://github.com/sschmid/Floc-Commands","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sschmid%2FFloc-Commands","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sschmid%2FFloc-Commands/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sschmid%2FFloc-Commands/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sschmid%2FFloc-Commands/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sschmid","download_url":"https://codeload.github.com/sschmid/Floc-Commands/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243976655,"owners_count":20377695,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T09:53:40.406Z","updated_at":"2025-03-19T07:30:46.658Z","avatar_url":"https://github.com/sschmid.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Floc Commands\n![Floc Commands Logo](http://sschmid.com/Dev/iOS/Libs/Floc-Commands/Floc-Commands-128.png)\n[![Build Status](https://travis-ci.org/sschmid/Floc-Commands.png?branch=master)](https://travis-ci.org/sschmid/Floc-Commands)\n\n## Description\nFloc Commands is a neat collection of easy-to-use commands for Objective-C.\nA command usually contains a small part of synchronous or asynchronous logic and can be chained or nested\nas much as you like. Floc Commands comes with a bunch of handy commands such as:\n\n* Sequence Command (executes commands one after another)\n* Parallel Command (executes commands all at once)\n* Interception Command (executes commands depending on the target command's execution result)\n* Block Command (executes a block)\n* Master Slave Command (cancels the slave command as soon the master command did execute)\n* Repeat Command (executes a command n times)\n* Retry Command (retries to execute a command n times, if an error occoured)\n\nAll commands are sublcasses of `FLCommand`, which is designed to be used both synchronously or asynchronously.\n\n## How to use Floc Commands\nTo get started, create a subclass of `FLCommand` and override `execute`. When a command finishes execution,\nit must always call `didExecuteWithError:`. If it executed successfully without any errors, you pass `nil` as an argument\nor you can use `didExecute` for convenience. Assign a delegate to respond to `commandWillExecute:`,\n`command:didExecuteWithError:` or `commandCancelled:`.\n\n## Fluent API and macros\nFloc Commands comes with some nice categories and macros to enable cool stuff like:\n\n```objective-c\nFLSQ(dowloadImage, convertImage, applyFilter, upload).stopsOnError(YES).retry(3)\n        .intercept(showSuccessAlert, showErrorAlert)\n        .slave(playJeopardyTheme.repeat(-1)).keepAlive.execute;\n```\nIn this example `FLSQ` (macro for `FLSequenceCommand`) executes all asynchronous commands one after another and will\nretry to execute all commands if any errors occour. If the sequence fails, `showErrorAlert` will be executed,\nelse `showSuccessAlert`. `playJeopardyTheme` will repeat forever (`-1`) and will be executed along with the sequence and\ngets cancelled, as soon as asynchronous operation is completed. Since we do not have a strong pointer to the command, we\ncall `keepAlive` to ensure the command will not be deallocated before it's completed. The lifecycle of the command will\nbe managed for you.\n\n```objective-c\nFLBC(^(FLBlockCommand *command) {\n    NSLog(@\"na\");\n    [command performSelector:@selector(didExecute) withObject:nil afterDelay:0.2];\n}).repeat(16).flseq(FLBC(^(FLBlockCommand *command) {\n    NSLog(@\"Batman!\");\n    [command performSelector:@selector(didExecute) withObject:nil afterDelay:0.2];\n})).repeat(-1).keepAlive.execute;\n```\nThis example creates a `FLBlockCommand` which repeats 16x followed by another `FLBlockCommand`. The sequence will repeat forever (`-1`)\n\nThere are handy macros for each command type. Check them out!\nSee [FLCommand+Floc.h](https://github.com/sschmid/Floc-Commands/blob/master/Floc-Commands/Classes/Additions/FLCommand%2BFloc.h)\n\n## Potential pitfalls\nWhen working with asynchronous commands, you should keep a strong pointer to it, because otherwise it may be\ndeallocated before it finishes. Alternatively you can call `keepAlive`, so the lifecycle of the command will be\nmanaged for you.\n\nRequestDataCommand might take several seconds to complete, so it's a good idea to assign in to a property to keep\nthe command alive.\n\n```objective-c\nself.requestCommand = [[[RequesteDataCommand alloc] init] execute];\n\n// or\n[[RequesteDataCommand alloc] init].keepAlive.execute;\n```\n\n## Examples\n\n#### Synchronous FLCommand\n\n```objective-c\n@implementation HelloWorldCommand\n\n- (void)execute {\n    [super execute];\n\n    NSLog(@\"Hello world!\");\n\n    [self didExecute];\n}\n\n@end\n```\n\n#### Asynchronous FLCommand\n\n```objective-c\n@implementation SendDataCommand\n\n- (void)execute {\n    [super execute];\n\n      // This may take a few seconds...\n      [self.service sendData:data onComplete:^(NSError *error) {\n          [self didExecuteWithError:error];\n      }];\n}\n\n- (void)cancel {\n    [self.service closeConnection];\n    [super cancel];\n}\n\n@end\n```\n\n#### FLSequenceCommand\nExecutes commands one at a time.\nAvailable options:\n* `stopOnError` will stop, when an error occoured\n* `cancelOnCancel` will cancel, when a sub command got cancelled\n\n```objective-c\n[[FLSequenceCommand alloc] initWithCommands:@[c1, c2, c3, c4]];\n```\n\n#### FLParallelCommand\nExecutes commands all at once.\nAvailable options:\n* `stopOnError` will stop, when an error occoured\n* `cancelOnCancel` will cancel, when a sub command got cancelled\n\n```objective-c\n[[FLPrallelCommand alloc] initWithCommands:@[c1, c2, c3, c4]];\n```\n\n#### FLInterceptionCommand\nExecutes target command. The success commands gets executed when no errors occoured,\nelse error command.\nAvailable options:\n* `cancelOnCancel` will cancel, when a sub command got cancelled\n* `forwardTargetError` will forward the target error via `command:didExecuteWithError:`\n\n```objective-c\nself.postCommand = [[FLInterceptionCommand alloc] initWithTarget:sendDataCommand\n                                                         success:hideSpinnerCommand\n                                                           error:showErrorAlertCommand];\n[self.postCommand execute];\n```\n\n#### Synchronous FLBlockCommand\n\n```objective-c\n[[FLBlockCommand alloc] initWithBlock:^(FLBlockCommand *command) {\n    NSLog(@\"Hello world!\");\n    [command didExecute];\n}];\n```\n\n#### Asynchronous FLBlockCommand\n\n```objective-c\nFLBlockCommand *delayCommand = [[FLBlockCommand alloc] initWithBlock:^(FLBlockCommand *command) {\n    [command performSelector:@selector(didExecute) withObject:nil afterDelay:1];\n}];\n```\n\n#### FLMasterSlaveCommand\nExecutes both commands at the same time and will cancel slave, as soon as the master command did execute.\nAvailable options:\n* `forwardMasterError` will forward the matser error via `command:didExecuteWithError:`\n\n```objective-c\n[[FLMasterSlaveCommand alloc] initWithMaster:doHeavyTaskCommand slave:playJeopardyMusicCommand];\n```\n\n... and more (`FLRepeatCommand`, `FLRetryCommand`, `FLDelayCommand`)\n\n## Install Floc Commands\nYou find the source files you need in Floc-Commands/Classes.\n\n## CocoaPods\nInstall [CocoaPods] and add the Floc Commands reference to your Podfile\n\n```\nplatform :ios, '5.0'\n  pod 'Floc-Commands'\nend\n```\n\n#### Install Floc Commands\n\n```\n$ cd path/to/project\n$ pod install\n```\n\nOpen the created Xcode Workspace file.\n\n[CocoaPods]: http://cocoapods.org\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsschmid%2Ffloc-commands","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsschmid%2Ffloc-commands","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsschmid%2Ffloc-commands/lists"}