├── .gitignore ├── LICENSE ├── Podfile ├── README.md ├── RxSwiftiOS.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── RxSwiftiOS.xcworkspace └── contents.xcworkspacedata └── RxSwiftiOS ├── AppDelegate.swift ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json ├── Contents.json └── blank.imageset │ ├── Contents.json │ └── blank.png ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── CombineViewController.swift ├── Info.plist ├── NewRepoViewController.swift ├── PresentViewController.swift ├── Repo.swift ├── SearchGitHubViewController.swift ├── SourceControlAPI.swift ├── UnidirectionalViewController.swift ├── Update.swift ├── User.swift └── UserCell.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | ## Playgrounds 31 | timeline.xctimeline 32 | playground.xcworkspace 33 | 34 | # Swift Package Manager 35 | # 36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 37 | # Packages/ 38 | .build/ 39 | 40 | # CocoaPods 41 | # 42 | # We recommend against adding the Pods directory to your .gitignore. However 43 | # you should judge for yourself, the pros and cons are mentioned at: 44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 45 | # 46 | # Pods/ 47 | 48 | # Carthage 49 | # 50 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 51 | # Carthage/Checkouts 52 | 53 | Carthage/Build 54 | 55 | # fastlane 56 | # 57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 58 | # screenshots whenever they are needed. 59 | # For more information about the recommended setup visit: 60 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/Preview.html 64 | fastlane/screenshots 65 | fastlane/test_output 66 | Pods 67 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Marin Todorov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | use_frameworks! 2 | 3 | target 'RxSwiftiOS' do 4 | pod 'RxSwift', '~> 3.1' 5 | pod 'RxCocoa', '~> 3.1' 6 | pod 'Unbox', '~> 2.3' 7 | pod 'RealmSwift', '~> 2.7' 8 | pod 'RxRealm', '~> 0.6' 9 | pod 'RxRealmDataSources', '~> 0.2' 10 | end 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Sample code from my dotSwift 2017 talk in Paris. Clone and install CocoaPods, then run the app. 2 | -------------------------------------------------------------------------------- /RxSwiftiOS.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 34C9F45614410FEA28D3FAEA /* Pods_RxSwiftiOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C49D8FF82AB94B7479F3BC23 /* Pods_RxSwiftiOS.framework */; }; 11 | 9C4F3ED01E338FE500B6428E /* Repo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C4F3ECF1E338FE500B6428E /* Repo.swift */; }; 12 | 9C4F3ED41E33912100B6428E /* PresentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C4F3ED31E33912100B6428E /* PresentViewController.swift */; }; 13 | 9C4F3ED61E33914900B6428E /* NewRepoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C4F3ED51E33914900B6428E /* NewRepoViewController.swift */; }; 14 | 9C8C1A841E33620B00A6AF51 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C8C1A831E33620B00A6AF51 /* AppDelegate.swift */; }; 15 | 9C8C1A861E33620B00A6AF51 /* SearchGitHubViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C8C1A851E33620B00A6AF51 /* SearchGitHubViewController.swift */; }; 16 | 9C8C1A891E33620B00A6AF51 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9C8C1A871E33620B00A6AF51 /* Main.storyboard */; }; 17 | 9C8C1A8B1E33620B00A6AF51 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9C8C1A8A1E33620B00A6AF51 /* Assets.xcassets */; }; 18 | 9C8C1A8E1E33620B00A6AF51 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9C8C1A8C1E33620B00A6AF51 /* LaunchScreen.storyboard */; }; 19 | 9C941A6B1E34AF15006DB1FE /* SourceControlAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C941A6A1E34AF15006DB1FE /* SourceControlAPI.swift */; }; 20 | 9C941A6D1E34B1D9006DB1FE /* UnidirectionalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C941A6C1E34B1D9006DB1FE /* UnidirectionalViewController.swift */; }; 21 | 9C941A6F1E34B284006DB1FE /* Update.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C941A6E1E34B284006DB1FE /* Update.swift */; }; 22 | 9CE561C01ECD969500886A9D /* CombineViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CE561BF1ECD969500886A9D /* CombineViewController.swift */; }; 23 | 9CE561C21ECD980D00886A9D /* UserCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CE561C11ECD980D00886A9D /* UserCell.swift */; }; 24 | 9CE561C41ECD98D600886A9D /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CE561C31ECD98D600886A9D /* User.swift */; }; 25 | /* End PBXBuildFile section */ 26 | 27 | /* Begin PBXFileReference section */ 28 | 9C4F3ECF1E338FE500B6428E /* Repo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Repo.swift; sourceTree = ""; }; 29 | 9C4F3ED31E33912100B6428E /* PresentViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PresentViewController.swift; sourceTree = ""; }; 30 | 9C4F3ED51E33914900B6428E /* NewRepoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NewRepoViewController.swift; sourceTree = ""; }; 31 | 9C8C1A801E33620A00A6AF51 /* RxSwiftiOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RxSwiftiOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; 32 | 9C8C1A831E33620B00A6AF51 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 33 | 9C8C1A851E33620B00A6AF51 /* SearchGitHubViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchGitHubViewController.swift; sourceTree = ""; }; 34 | 9C8C1A881E33620B00A6AF51 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 35 | 9C8C1A8A1E33620B00A6AF51 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 36 | 9C8C1A8D1E33620B00A6AF51 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 37 | 9C8C1A8F1E33620B00A6AF51 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 38 | 9C8C1A951E33621A00A6AF51 /* Podfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Podfile; path = ../Podfile; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 39 | 9C941A6A1E34AF15006DB1FE /* SourceControlAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SourceControlAPI.swift; sourceTree = ""; }; 40 | 9C941A6C1E34B1D9006DB1FE /* UnidirectionalViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnidirectionalViewController.swift; sourceTree = ""; }; 41 | 9C941A6E1E34B284006DB1FE /* Update.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Update.swift; sourceTree = ""; }; 42 | 9CE561BF1ECD969500886A9D /* CombineViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CombineViewController.swift; sourceTree = ""; }; 43 | 9CE561C11ECD980D00886A9D /* UserCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserCell.swift; sourceTree = ""; }; 44 | 9CE561C31ECD98D600886A9D /* User.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = ""; }; 45 | A1BBBBAB7C049E850CA78160 /* Pods-RxSwiftiOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RxSwiftiOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-RxSwiftiOS/Pods-RxSwiftiOS.debug.xcconfig"; sourceTree = ""; }; 46 | C49D8FF82AB94B7479F3BC23 /* Pods_RxSwiftiOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RxSwiftiOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 47 | D713662B95F31539A6E7266E /* Pods-RxSwiftiOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RxSwiftiOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-RxSwiftiOS/Pods-RxSwiftiOS.release.xcconfig"; sourceTree = ""; }; 48 | /* End PBXFileReference section */ 49 | 50 | /* Begin PBXFrameworksBuildPhase section */ 51 | 9C8C1A7D1E33620A00A6AF51 /* Frameworks */ = { 52 | isa = PBXFrameworksBuildPhase; 53 | buildActionMask = 2147483647; 54 | files = ( 55 | 34C9F45614410FEA28D3FAEA /* Pods_RxSwiftiOS.framework in Frameworks */, 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | /* End PBXFrameworksBuildPhase section */ 60 | 61 | /* Begin PBXGroup section */ 62 | 9C4F3ECE1E338FD700B6428E /* 1. SearchGitHub */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | 9C8C1A851E33620B00A6AF51 /* SearchGitHubViewController.swift */, 66 | 9C4F3ECF1E338FE500B6428E /* Repo.swift */, 67 | ); 68 | name = "1. SearchGitHub"; 69 | sourceTree = ""; 70 | }; 71 | 9C4F3ED11E3390D500B6428E /* 2. PresentViewController */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | 9C4F3ED31E33912100B6428E /* PresentViewController.swift */, 75 | 9C4F3ED51E33914900B6428E /* NewRepoViewController.swift */, 76 | ); 77 | name = "2. PresentViewController"; 78 | sourceTree = ""; 79 | }; 80 | 9C4F3ED21E3390F800B6428E /* Assets */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | 9C8C1A871E33620B00A6AF51 /* Main.storyboard */, 84 | 9C8C1A8A1E33620B00A6AF51 /* Assets.xcassets */, 85 | 9C8C1A8C1E33620B00A6AF51 /* LaunchScreen.storyboard */, 86 | 9C8C1A8F1E33620B00A6AF51 /* Info.plist */, 87 | ); 88 | name = Assets; 89 | sourceTree = ""; 90 | }; 91 | 9C4F3ED71E33A15D00B6428E /* 3. Unidirectional Data Flow */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 9C941A6A1E34AF15006DB1FE /* SourceControlAPI.swift */, 95 | 9C941A6C1E34B1D9006DB1FE /* UnidirectionalViewController.swift */, 96 | 9C941A6E1E34B284006DB1FE /* Update.swift */, 97 | ); 98 | name = "3. Unidirectional Data Flow"; 99 | sourceTree = ""; 100 | }; 101 | 9C8C1A771E33620A00A6AF51 = { 102 | isa = PBXGroup; 103 | children = ( 104 | 9C8C1A821E33620A00A6AF51 /* RxSwiftiOS */, 105 | 9C8C1A811E33620A00A6AF51 /* Products */, 106 | C76976651CBFA1CCB13A8E08 /* Pods */, 107 | A01F6E59692B9587A51A115A /* Frameworks */, 108 | ); 109 | sourceTree = ""; 110 | }; 111 | 9C8C1A811E33620A00A6AF51 /* Products */ = { 112 | isa = PBXGroup; 113 | children = ( 114 | 9C8C1A801E33620A00A6AF51 /* RxSwiftiOS.app */, 115 | ); 116 | name = Products; 117 | sourceTree = ""; 118 | }; 119 | 9C8C1A821E33620A00A6AF51 /* RxSwiftiOS */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | 9C4F3ED21E3390F800B6428E /* Assets */, 123 | 9C4F3ECE1E338FD700B6428E /* 1. SearchGitHub */, 124 | 9C4F3ED11E3390D500B6428E /* 2. PresentViewController */, 125 | 9C4F3ED71E33A15D00B6428E /* 3. Unidirectional Data Flow */, 126 | 9CE561BE1ECD967700886A9D /* 4. CombineLatest */, 127 | 9C8C1A831E33620B00A6AF51 /* AppDelegate.swift */, 128 | 9C8C1A951E33621A00A6AF51 /* Podfile */, 129 | ); 130 | path = RxSwiftiOS; 131 | sourceTree = ""; 132 | }; 133 | 9CE561BE1ECD967700886A9D /* 4. CombineLatest */ = { 134 | isa = PBXGroup; 135 | children = ( 136 | 9CE561BF1ECD969500886A9D /* CombineViewController.swift */, 137 | 9CE561C11ECD980D00886A9D /* UserCell.swift */, 138 | 9CE561C31ECD98D600886A9D /* User.swift */, 139 | ); 140 | name = "4. CombineLatest"; 141 | sourceTree = ""; 142 | }; 143 | A01F6E59692B9587A51A115A /* Frameworks */ = { 144 | isa = PBXGroup; 145 | children = ( 146 | C49D8FF82AB94B7479F3BC23 /* Pods_RxSwiftiOS.framework */, 147 | ); 148 | name = Frameworks; 149 | sourceTree = ""; 150 | }; 151 | C76976651CBFA1CCB13A8E08 /* Pods */ = { 152 | isa = PBXGroup; 153 | children = ( 154 | A1BBBBAB7C049E850CA78160 /* Pods-RxSwiftiOS.debug.xcconfig */, 155 | D713662B95F31539A6E7266E /* Pods-RxSwiftiOS.release.xcconfig */, 156 | ); 157 | name = Pods; 158 | sourceTree = ""; 159 | }; 160 | /* End PBXGroup section */ 161 | 162 | /* Begin PBXNativeTarget section */ 163 | 9C8C1A7F1E33620A00A6AF51 /* RxSwiftiOS */ = { 164 | isa = PBXNativeTarget; 165 | buildConfigurationList = 9C8C1A921E33620B00A6AF51 /* Build configuration list for PBXNativeTarget "RxSwiftiOS" */; 166 | buildPhases = ( 167 | 107793AFC275A43D3A7E8439 /* [CP] Check Pods Manifest.lock */, 168 | 9C8C1A7C1E33620A00A6AF51 /* Sources */, 169 | 9C8C1A7D1E33620A00A6AF51 /* Frameworks */, 170 | 9C8C1A7E1E33620A00A6AF51 /* Resources */, 171 | 1D46237EB645E24949A20E6F /* [CP] Embed Pods Frameworks */, 172 | F664543B9CA914A0FA477411 /* [CP] Copy Pods Resources */, 173 | ); 174 | buildRules = ( 175 | ); 176 | dependencies = ( 177 | ); 178 | name = RxSwiftiOS; 179 | productName = RxSwiftiOS; 180 | productReference = 9C8C1A801E33620A00A6AF51 /* RxSwiftiOS.app */; 181 | productType = "com.apple.product-type.application"; 182 | }; 183 | /* End PBXNativeTarget section */ 184 | 185 | /* Begin PBXProject section */ 186 | 9C8C1A781E33620A00A6AF51 /* Project object */ = { 187 | isa = PBXProject; 188 | attributes = { 189 | LastSwiftUpdateCheck = 0820; 190 | LastUpgradeCheck = 0820; 191 | ORGANIZATIONNAME = "Underplot ltd"; 192 | TargetAttributes = { 193 | 9C8C1A7F1E33620A00A6AF51 = { 194 | CreatedOnToolsVersion = 8.2.1; 195 | DevelopmentTeam = 9MF8G8D9Y5; 196 | ProvisioningStyle = Automatic; 197 | }; 198 | }; 199 | }; 200 | buildConfigurationList = 9C8C1A7B1E33620A00A6AF51 /* Build configuration list for PBXProject "RxSwiftiOS" */; 201 | compatibilityVersion = "Xcode 3.2"; 202 | developmentRegion = English; 203 | hasScannedForEncodings = 0; 204 | knownRegions = ( 205 | en, 206 | Base, 207 | ); 208 | mainGroup = 9C8C1A771E33620A00A6AF51; 209 | productRefGroup = 9C8C1A811E33620A00A6AF51 /* Products */; 210 | projectDirPath = ""; 211 | projectRoot = ""; 212 | targets = ( 213 | 9C8C1A7F1E33620A00A6AF51 /* RxSwiftiOS */, 214 | ); 215 | }; 216 | /* End PBXProject section */ 217 | 218 | /* Begin PBXResourcesBuildPhase section */ 219 | 9C8C1A7E1E33620A00A6AF51 /* Resources */ = { 220 | isa = PBXResourcesBuildPhase; 221 | buildActionMask = 2147483647; 222 | files = ( 223 | 9C8C1A8E1E33620B00A6AF51 /* LaunchScreen.storyboard in Resources */, 224 | 9C8C1A8B1E33620B00A6AF51 /* Assets.xcassets in Resources */, 225 | 9C8C1A891E33620B00A6AF51 /* Main.storyboard in Resources */, 226 | ); 227 | runOnlyForDeploymentPostprocessing = 0; 228 | }; 229 | /* End PBXResourcesBuildPhase section */ 230 | 231 | /* Begin PBXShellScriptBuildPhase section */ 232 | 107793AFC275A43D3A7E8439 /* [CP] Check Pods Manifest.lock */ = { 233 | isa = PBXShellScriptBuildPhase; 234 | buildActionMask = 2147483647; 235 | files = ( 236 | ); 237 | inputPaths = ( 238 | ); 239 | name = "[CP] Check Pods Manifest.lock"; 240 | outputPaths = ( 241 | ); 242 | runOnlyForDeploymentPostprocessing = 0; 243 | shellPath = /bin/sh; 244 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; 245 | showEnvVarsInLog = 0; 246 | }; 247 | 1D46237EB645E24949A20E6F /* [CP] Embed Pods Frameworks */ = { 248 | isa = PBXShellScriptBuildPhase; 249 | buildActionMask = 2147483647; 250 | files = ( 251 | ); 252 | inputPaths = ( 253 | ); 254 | name = "[CP] Embed Pods Frameworks"; 255 | outputPaths = ( 256 | ); 257 | runOnlyForDeploymentPostprocessing = 0; 258 | shellPath = /bin/sh; 259 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-RxSwiftiOS/Pods-RxSwiftiOS-frameworks.sh\"\n"; 260 | showEnvVarsInLog = 0; 261 | }; 262 | F664543B9CA914A0FA477411 /* [CP] Copy Pods Resources */ = { 263 | isa = PBXShellScriptBuildPhase; 264 | buildActionMask = 2147483647; 265 | files = ( 266 | ); 267 | inputPaths = ( 268 | ); 269 | name = "[CP] Copy Pods Resources"; 270 | outputPaths = ( 271 | ); 272 | runOnlyForDeploymentPostprocessing = 0; 273 | shellPath = /bin/sh; 274 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-RxSwiftiOS/Pods-RxSwiftiOS-resources.sh\"\n"; 275 | showEnvVarsInLog = 0; 276 | }; 277 | /* End PBXShellScriptBuildPhase section */ 278 | 279 | /* Begin PBXSourcesBuildPhase section */ 280 | 9C8C1A7C1E33620A00A6AF51 /* Sources */ = { 281 | isa = PBXSourcesBuildPhase; 282 | buildActionMask = 2147483647; 283 | files = ( 284 | 9C4F3ED01E338FE500B6428E /* Repo.swift in Sources */, 285 | 9C941A6B1E34AF15006DB1FE /* SourceControlAPI.swift in Sources */, 286 | 9C941A6F1E34B284006DB1FE /* Update.swift in Sources */, 287 | 9C8C1A861E33620B00A6AF51 /* SearchGitHubViewController.swift in Sources */, 288 | 9C4F3ED41E33912100B6428E /* PresentViewController.swift in Sources */, 289 | 9C941A6D1E34B1D9006DB1FE /* UnidirectionalViewController.swift in Sources */, 290 | 9C4F3ED61E33914900B6428E /* NewRepoViewController.swift in Sources */, 291 | 9CE561C01ECD969500886A9D /* CombineViewController.swift in Sources */, 292 | 9CE561C21ECD980D00886A9D /* UserCell.swift in Sources */, 293 | 9C8C1A841E33620B00A6AF51 /* AppDelegate.swift in Sources */, 294 | 9CE561C41ECD98D600886A9D /* User.swift in Sources */, 295 | ); 296 | runOnlyForDeploymentPostprocessing = 0; 297 | }; 298 | /* End PBXSourcesBuildPhase section */ 299 | 300 | /* Begin PBXVariantGroup section */ 301 | 9C8C1A871E33620B00A6AF51 /* Main.storyboard */ = { 302 | isa = PBXVariantGroup; 303 | children = ( 304 | 9C8C1A881E33620B00A6AF51 /* Base */, 305 | ); 306 | name = Main.storyboard; 307 | sourceTree = ""; 308 | }; 309 | 9C8C1A8C1E33620B00A6AF51 /* LaunchScreen.storyboard */ = { 310 | isa = PBXVariantGroup; 311 | children = ( 312 | 9C8C1A8D1E33620B00A6AF51 /* Base */, 313 | ); 314 | name = LaunchScreen.storyboard; 315 | sourceTree = ""; 316 | }; 317 | /* End PBXVariantGroup section */ 318 | 319 | /* Begin XCBuildConfiguration section */ 320 | 9C8C1A901E33620B00A6AF51 /* Debug */ = { 321 | isa = XCBuildConfiguration; 322 | buildSettings = { 323 | ALWAYS_SEARCH_USER_PATHS = NO; 324 | CLANG_ANALYZER_NONNULL = YES; 325 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 326 | CLANG_CXX_LIBRARY = "libc++"; 327 | CLANG_ENABLE_MODULES = YES; 328 | CLANG_ENABLE_OBJC_ARC = YES; 329 | CLANG_WARN_BOOL_CONVERSION = YES; 330 | CLANG_WARN_CONSTANT_CONVERSION = YES; 331 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 332 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 333 | CLANG_WARN_EMPTY_BODY = YES; 334 | CLANG_WARN_ENUM_CONVERSION = YES; 335 | CLANG_WARN_INFINITE_RECURSION = YES; 336 | CLANG_WARN_INT_CONVERSION = YES; 337 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 338 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 339 | CLANG_WARN_UNREACHABLE_CODE = YES; 340 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 341 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 342 | COPY_PHASE_STRIP = NO; 343 | DEBUG_INFORMATION_FORMAT = dwarf; 344 | ENABLE_STRICT_OBJC_MSGSEND = YES; 345 | ENABLE_TESTABILITY = YES; 346 | GCC_C_LANGUAGE_STANDARD = gnu99; 347 | GCC_DYNAMIC_NO_PIC = NO; 348 | GCC_NO_COMMON_BLOCKS = YES; 349 | GCC_OPTIMIZATION_LEVEL = 0; 350 | GCC_PREPROCESSOR_DEFINITIONS = ( 351 | "DEBUG=1", 352 | "$(inherited)", 353 | ); 354 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 355 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 356 | GCC_WARN_UNDECLARED_SELECTOR = YES; 357 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 358 | GCC_WARN_UNUSED_FUNCTION = YES; 359 | GCC_WARN_UNUSED_VARIABLE = YES; 360 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 361 | MTL_ENABLE_DEBUG_INFO = YES; 362 | ONLY_ACTIVE_ARCH = YES; 363 | SDKROOT = iphoneos; 364 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 365 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 366 | }; 367 | name = Debug; 368 | }; 369 | 9C8C1A911E33620B00A6AF51 /* Release */ = { 370 | isa = XCBuildConfiguration; 371 | buildSettings = { 372 | ALWAYS_SEARCH_USER_PATHS = NO; 373 | CLANG_ANALYZER_NONNULL = YES; 374 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 375 | CLANG_CXX_LIBRARY = "libc++"; 376 | CLANG_ENABLE_MODULES = YES; 377 | CLANG_ENABLE_OBJC_ARC = YES; 378 | CLANG_WARN_BOOL_CONVERSION = YES; 379 | CLANG_WARN_CONSTANT_CONVERSION = YES; 380 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 381 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 382 | CLANG_WARN_EMPTY_BODY = YES; 383 | CLANG_WARN_ENUM_CONVERSION = YES; 384 | CLANG_WARN_INFINITE_RECURSION = YES; 385 | CLANG_WARN_INT_CONVERSION = YES; 386 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 387 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 388 | CLANG_WARN_UNREACHABLE_CODE = YES; 389 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 390 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 391 | COPY_PHASE_STRIP = NO; 392 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 393 | ENABLE_NS_ASSERTIONS = NO; 394 | ENABLE_STRICT_OBJC_MSGSEND = YES; 395 | GCC_C_LANGUAGE_STANDARD = gnu99; 396 | GCC_NO_COMMON_BLOCKS = YES; 397 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 398 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 399 | GCC_WARN_UNDECLARED_SELECTOR = YES; 400 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 401 | GCC_WARN_UNUSED_FUNCTION = YES; 402 | GCC_WARN_UNUSED_VARIABLE = YES; 403 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 404 | MTL_ENABLE_DEBUG_INFO = NO; 405 | SDKROOT = iphoneos; 406 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 407 | VALIDATE_PRODUCT = YES; 408 | }; 409 | name = Release; 410 | }; 411 | 9C8C1A931E33620B00A6AF51 /* Debug */ = { 412 | isa = XCBuildConfiguration; 413 | baseConfigurationReference = A1BBBBAB7C049E850CA78160 /* Pods-RxSwiftiOS.debug.xcconfig */; 414 | buildSettings = { 415 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 416 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 417 | DEVELOPMENT_TEAM = 9MF8G8D9Y5; 418 | INFOPLIST_FILE = RxSwiftiOS/Info.plist; 419 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 420 | PRODUCT_BUNDLE_IDENTIFIER = com.underplot.RxSwiftiOS; 421 | PRODUCT_NAME = "$(TARGET_NAME)"; 422 | SWIFT_VERSION = 3.0; 423 | }; 424 | name = Debug; 425 | }; 426 | 9C8C1A941E33620B00A6AF51 /* Release */ = { 427 | isa = XCBuildConfiguration; 428 | baseConfigurationReference = D713662B95F31539A6E7266E /* Pods-RxSwiftiOS.release.xcconfig */; 429 | buildSettings = { 430 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 431 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 432 | DEVELOPMENT_TEAM = 9MF8G8D9Y5; 433 | INFOPLIST_FILE = RxSwiftiOS/Info.plist; 434 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 435 | PRODUCT_BUNDLE_IDENTIFIER = com.underplot.RxSwiftiOS; 436 | PRODUCT_NAME = "$(TARGET_NAME)"; 437 | SWIFT_VERSION = 3.0; 438 | }; 439 | name = Release; 440 | }; 441 | /* End XCBuildConfiguration section */ 442 | 443 | /* Begin XCConfigurationList section */ 444 | 9C8C1A7B1E33620A00A6AF51 /* Build configuration list for PBXProject "RxSwiftiOS" */ = { 445 | isa = XCConfigurationList; 446 | buildConfigurations = ( 447 | 9C8C1A901E33620B00A6AF51 /* Debug */, 448 | 9C8C1A911E33620B00A6AF51 /* Release */, 449 | ); 450 | defaultConfigurationIsVisible = 0; 451 | defaultConfigurationName = Release; 452 | }; 453 | 9C8C1A921E33620B00A6AF51 /* Build configuration list for PBXNativeTarget "RxSwiftiOS" */ = { 454 | isa = XCConfigurationList; 455 | buildConfigurations = ( 456 | 9C8C1A931E33620B00A6AF51 /* Debug */, 457 | 9C8C1A941E33620B00A6AF51 /* Release */, 458 | ); 459 | defaultConfigurationIsVisible = 0; 460 | defaultConfigurationName = Release; 461 | }; 462 | /* End XCConfigurationList section */ 463 | }; 464 | rootObject = 9C8C1A781E33620A00A6AF51 /* Project object */; 465 | } 466 | -------------------------------------------------------------------------------- /RxSwiftiOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /RxSwiftiOS.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /RxSwiftiOS/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // RxSwiftiOS 4 | // 5 | // Created by Marin Todorov on 1/21/17. 6 | // Copyright © 2017 Underplot ltd. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | var window: UIWindow? 14 | } 15 | -------------------------------------------------------------------------------- /RxSwiftiOS/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | } 43 | ], 44 | "info" : { 45 | "version" : 1, 46 | "author" : "xcode" 47 | } 48 | } -------------------------------------------------------------------------------- /RxSwiftiOS/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /RxSwiftiOS/Assets.xcassets/blank.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "blank.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /RxSwiftiOS/Assets.xcassets/blank.imageset/blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/icanzilb/RxSwiftoniOS/6fd6e50d7645948d35f065c6b6d502a8e91881fe/RxSwiftiOS/Assets.xcassets/blank.imageset/blank.png -------------------------------------------------------------------------------- /RxSwiftiOS/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /RxSwiftiOS/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 176 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 233 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 287 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | -------------------------------------------------------------------------------- /RxSwiftiOS/CombineViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CombineViewController.swift 3 | // RxSwiftiOS 4 | // 5 | // Created by Marin Todorov on 5/18/17. 6 | // Copyright © 2017 Underplot ltd. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import RxSwift 11 | import RxCocoa 12 | 13 | extension UIImage { 14 | static func fromData(data: Data) -> UIImage { return UIImage(data: data)! } 15 | static let blank: Data = UIImagePNGRepresentation(UIImage(named: "blank")!)! 16 | } 17 | 18 | class CombineViewController: UIViewController { 19 | 20 | @IBOutlet var collectionView: UICollectionView! 21 | @IBOutlet var segment: UISegmentedControl! 22 | 23 | private var bag = DisposeBag() 24 | fileprivate var followers = Variable<[User]>([]) 25 | fileprivate var avatars = Variable<[UIImage]>([]) 26 | 27 | override func viewDidLoad() { 28 | super.viewDidLoad() 29 | 30 | didSelectSegment(segment) 31 | } 32 | 33 | 34 | @IBAction func didSelectSegment(_ sender: Any) { 35 | // reset UI 36 | bag = DisposeBag() 37 | followers.value = [] 38 | avatars.value = [] 39 | collectionView.reloadData() 40 | 41 | // fetch followers 42 | fetchFollowers() 43 | .bind(to: followers) 44 | .disposed(by: bag) 45 | 46 | // get an array of image observables 47 | let fetchedImages = [getAllAtOnce, getAsTheyCome][segment.selectedSegmentIndex]() 48 | 49 | // store images into avatars 50 | fetchedImages 51 | .bind(to: avatars) 52 | .disposed(by: bag) 53 | 54 | // reload collection 55 | fetchedImages 56 | .observeOn(MainScheduler.instance) 57 | .subscribe(onNext: {[weak self] _ in 58 | self?.collectionView.reloadData() 59 | }) 60 | .disposed(by: bag) 61 | } 62 | 63 | private func getAllAtOnce() -> Observable<[UIImage]> { 64 | // emit .next only when all images have been downloaded 65 | return followers.asObservable() 66 | .map { users -> [Observable] in 67 | return users.map { user in 68 | let request = URLRequest(url: URL(string: user.avatarUrl)!) 69 | return URLSession.shared.rx.data(request: request) 70 | .catchErrorJustReturn(UIImage.blank) 71 | } 72 | } 73 | .flatMap(Observable.combineLatest) 74 | .map { $0.map(UIImage.fromData) } 75 | .shareReplay(1) 76 | } 77 | 78 | private func getAsTheyCome() -> Observable<[UIImage]> { 79 | // emit .next when each of the images comes in 80 | return followers.asObservable() 81 | .map { users -> [Observable] in 82 | return users.map { user in 83 | let request = URLRequest(url: URL(string: user.avatarUrl)!) 84 | return URLSession.shared.rx.data(request: request) 85 | .startWith(UIImage.blank) 86 | .catchErrorJustReturn(UIImage.blank) 87 | } 88 | } 89 | .flatMap(Observable.combineLatest) 90 | .map { $0.map(UIImage.fromData) } 91 | .shareReplay(1) 92 | } 93 | 94 | private func fetchFollowers() -> Observable<[User]> { 95 | return Observable.just("https://api.github.com/users/icanzilb/followers") 96 | .map { url in 97 | let apiUrl = URLComponents(string: url)! 98 | return URLRequest(url: apiUrl.url!) 99 | } 100 | .flatMapLatest { request in 101 | return URLSession.shared.rx.json(request: request) 102 | .catchErrorJustReturn([]) 103 | } 104 | .map { json -> [User] in 105 | guard let users = json as? [JSONObject] else { 106 | return [] 107 | } 108 | return users.flatMap(User.init) 109 | } 110 | } 111 | } 112 | 113 | extension CombineViewController: UICollectionViewDataSource { 114 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 115 | print("\(followers.value.count) cells") 116 | return followers.value.count 117 | } 118 | 119 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 120 | let user = followers.value[indexPath.row] 121 | 122 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! UserCell 123 | cell.name!.text = user.login 124 | if self.avatars.value.count > indexPath.row { 125 | cell.photo.image = self.avatars.value[indexPath.row] 126 | } 127 | return cell 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /RxSwiftiOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /RxSwiftiOS/NewRepoViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NewRepoViewController.swift 3 | // RxSwiftiOS 4 | // 5 | // Created by Marin Todorov on 1/21/17. 6 | // Copyright © 2017 Underplot ltd. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | import RxSwift 12 | import RxCocoa 13 | 14 | class NewRepoViewController: UITableViewController { 15 | 16 | @IBOutlet var id: UITextField! 17 | @IBOutlet var name: UITextField! 18 | @IBOutlet var language: UITextField! 19 | @IBOutlet var saveButton: UIButton! 20 | 21 | private let bag = DisposeBag() 22 | private let repo = PublishSubject() 23 | 24 | lazy var repoObservable: Observable = { 25 | return self.repo.asObservable() 26 | }() 27 | 28 | override func viewDidLoad() { 29 | super.viewDidLoad() 30 | bindUI() 31 | } 32 | 33 | func bindUI() { 34 | // current repo data 35 | let currentRepo = Observable.combineLatest(id.rx.text, name.rx.text, language.rx.text) { id, name, lang -> Repo? in 36 | guard let id = id, let idInt = Int(id), 37 | let name = name, name.characters.count > 1, 38 | let lang = lang, lang.characters.count > 0 else { 39 | return nil 40 | } 41 | return Repo(idInt, name, lang) 42 | } 43 | .shareReplay(1) 44 | 45 | // toggle save button 46 | currentRepo 47 | .map { $0 != nil } 48 | .bindTo(saveButton.rx.isEnabled) 49 | .addDisposableTo(bag) 50 | 51 | // emit repo when saved 52 | saveButton.rx.tap 53 | .withLatestFrom(currentRepo) 54 | .subscribe(onNext: {[weak self] repo in 55 | if let repo = repo { 56 | self?.repo.onNext(repo) 57 | self?.repo.onCompleted() 58 | } 59 | }) 60 | .addDisposableTo(bag) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /RxSwiftiOS/PresentViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PresentViewController.swift 3 | // RxSwiftiOS 4 | // 5 | // Created by Marin Todorov on 1/21/17. 6 | // Copyright © 2017 Underplot ltd. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import RxSwift 11 | import RxCocoa 12 | 13 | private let initialRepos = [ 14 | Repo(1, "EasyAnimation", "Swift"), 15 | Repo(2, "Unbox", "Swift"), 16 | Repo(3, "RxSwift", "Swift") 17 | ] 18 | 19 | class PresentViewController: UITableViewController { 20 | 21 | private let repos = Variable<[Repo]>(initialRepos) 22 | private let bag = DisposeBag() 23 | 24 | override func viewDidLoad() { 25 | super.viewDidLoad() 26 | 27 | tableView.dataSource = nil 28 | bindUI() 29 | } 30 | 31 | func bindUI() { 32 | // display data 33 | repos.asObservable() 34 | .bindTo(tableView.rx.items) { (tableView, row, repo) in 35 | let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")! 36 | cell.textLabel!.text = repo.name 37 | cell.detailTextLabel?.text = repo.language 38 | return cell 39 | } 40 | .addDisposableTo(bag) 41 | 42 | // present view controller, observe output 43 | navigationItem.rightBarButtonItem!.rx.tap 44 | .throttle(0.5, latest: false, scheduler: MainScheduler.instance) 45 | .flatMapFirst {[weak self] _ -> Observable in 46 | if let addVC = self?.storyboard?.instantiateViewController(withIdentifier: "NewRepoViewController") as? NewRepoViewController { 47 | self?.navigationController?.pushViewController(addVC, animated: true) 48 | return addVC.repoObservable 49 | } 50 | return Observable.never() 51 | } 52 | .subscribe(onNext: {[weak self] repo in 53 | self?.repos.value.append(repo) 54 | _ = self?.navigationController?.popViewController(animated: true) 55 | }) 56 | .addDisposableTo(bag) 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /RxSwiftiOS/Repo.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Repo.swift 3 | // RxSwiftiOS 4 | // 5 | // Created by Marin Todorov on 1/21/17. 6 | // Copyright © 2017 Underplot ltd. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | struct Repo { 12 | let id: Int 13 | let name: String 14 | let language: String 15 | 16 | init?(object: [String: Any]) { 17 | guard let id = object["id"] as? Int, 18 | let name = object["name"] as? String, 19 | let language = object["language"] as? String else { 20 | return nil 21 | } 22 | self.id = id 23 | self.name = name 24 | self.language = language 25 | } 26 | 27 | init(_ id: Int, _ name: String, _ language: String) { 28 | self.id = id 29 | self.name = name 30 | self.language = language 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /RxSwiftiOS/SearchGitHubViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // RxSwiftiOS 4 | // 5 | // Created by Marin Todorov on 1/21/17. 6 | // Copyright © 2017 Underplot ltd. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Unbox 11 | 12 | import RxSwift 13 | import RxCocoa 14 | 15 | class SearchGitHubViewController: UIViewController { 16 | 17 | @IBOutlet var tableView: UITableView! 18 | @IBOutlet var searchBar: UISearchBar! 19 | 20 | private let bag = DisposeBag() 21 | private let repos = Variable<[Repo]>([]) 22 | 23 | override func viewDidLoad() { 24 | super.viewDidLoad() 25 | bindUI() 26 | } 27 | 28 | func bindUI() { 29 | // observe text, form request, bind table view to result 30 | searchBar.rx.text 31 | .orEmpty 32 | .filter { query in 33 | return query.characters.count > 2 34 | } 35 | .debounce(0.5, scheduler: MainScheduler.instance) 36 | .map { query in 37 | var apiUrl = URLComponents(string: "https://api.github.com/search/repositories")! 38 | apiUrl.queryItems = [URLQueryItem(name: "q", value: query)] 39 | return URLRequest(url: apiUrl.url!) 40 | } 41 | .flatMapLatest { request in 42 | return URLSession.shared.rx.json(request: request) 43 | .catchErrorJustReturn([]) 44 | } 45 | .map { json -> [Repo] in 46 | guard let json = json as? [String: Any], 47 | let items = json["items"] as? [[String: Any]] else { 48 | return [] 49 | } 50 | return items.flatMap(Repo.init) 51 | } 52 | .bind(to: tableView.rx.items) { tableView, row, repo in 53 | let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")! 54 | cell.textLabel!.text = repo.name 55 | cell.detailTextLabel?.text = repo.language 56 | return cell 57 | } 58 | .addDisposableTo(bag) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /RxSwiftiOS/SourceControlAPI.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SourceControlAPI.swift 3 | // RxSwiftiOS 4 | // 5 | // Created by Marin Todorov on 1/22/17. 6 | // Copyright © 2017 Underplot ltd. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import RxSwift 11 | 12 | class SourceControlAPI { 13 | 14 | private static let names = ["Joshua", "Keenan", "Alexandra", "Omaya"] 15 | private static let actions = ["comitted", "pushed", "forked"] 16 | private static let repos = ["Project AlphaBeta", "Corp website", "Project Synergy", "Singularity"] 17 | 18 | static func updates() -> Observable<[String: Any]> { 19 | return Observable.create {observer in 20 | let timer = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true) { timer in 21 | DispatchQueue.global(qos: .background).async { 22 | let json = ["name": names.sample, "action": actions.sample, "repo": repos.sample] 23 | observer.onNext(json) 24 | } 25 | } 26 | timer.fire() 27 | 28 | return Disposables.create { 29 | timer.invalidate() 30 | } 31 | } 32 | } 33 | } 34 | 35 | extension Array { 36 | fileprivate var sample: Element { 37 | return self[Int(arc4random_uniform(UInt32(count)))] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /RxSwiftiOS/UnidirectionalViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UnidirectionalViewController.swift 3 | // RxSwiftiOS 4 | // 5 | // Created by Marin Todorov on 1/22/17. 6 | // Copyright © 2017 Underplot ltd. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import RealmSwift 11 | 12 | import RxSwift 13 | import RxCocoa 14 | import RxRealm 15 | import RxRealmDataSources 16 | 17 | class UnidirectionalViewController: UIViewController { 18 | 19 | @IBOutlet var tableView: UITableView! 20 | 21 | private let bag = DisposeBag() 22 | 23 | override func viewDidLoad() { 24 | super.viewDidLoad() 25 | bindUI() 26 | } 27 | 28 | func bindUI() { 29 | 30 | // store data 31 | SourceControlAPI.updates() 32 | .observeOn(SerialDispatchQueueScheduler(qos: .background)) 33 | .map(Update.fromOrEmpty) 34 | .subscribe(Realm.rx.add()) 35 | .addDisposableTo(bag) 36 | 37 | // display data 38 | let dataSource = RxTableViewRealmDataSource(cellIdentifier: "Cell", cellType: UITableViewCell.self) {cell, ip, update in 39 | cell.detailTextLabel!.text = "[" + update.ago + "] " + update.name + " " + update.action 40 | cell.textLabel?.text = "Repo: " + update.repo 41 | } 42 | dataSource.headerTitle = "Source Control Activity" 43 | 44 | let realm = try! Realm() 45 | let updates = realm.objects(Update.self).sorted(byKeyPath: "date", ascending: false) 46 | 47 | Observable.changeset(from: updates) 48 | .bindTo(tableView.rx.realmChanges(dataSource)) 49 | .addDisposableTo(bag) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /RxSwiftiOS/Update.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Update.swift 3 | // RxSwiftiOS 4 | // 5 | // Created by Marin Todorov on 1/22/17. 6 | // Copyright © 2017 Underplot ltd. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import RealmSwift 11 | 12 | class Update: Object { 13 | 14 | // data properties 15 | dynamic var id = UUID().uuidString 16 | dynamic var date = Date() 17 | 18 | dynamic var name = "" 19 | dynamic var action = "" 20 | dynamic var repo = "" 21 | 22 | var ago: String { 23 | return formatter.string(from: date) 24 | } 25 | 26 | private lazy var formatter: DateFormatter = { 27 | let f = DateFormatter() 28 | f.timeStyle = .medium 29 | f.dateStyle = .long 30 | f.doesRelativeDateFormatting = true 31 | return f 32 | }() 33 | 34 | override static func primaryKey() -> String? { 35 | return "id" 36 | } 37 | 38 | static func from(object: Any) -> Update? { 39 | guard let data = object as? [String: Any], 40 | let name = data["name"] as? String, 41 | let action = data["action"] as? String, 42 | let repo = data["repo"] as? String else { 43 | return nil 44 | } 45 | 46 | let update = Update() 47 | update.name = name 48 | update.action = action 49 | update.repo = repo 50 | return update 51 | } 52 | 53 | static func fromOrEmpty(object: Any) -> Update { 54 | return from(object: object) ?? Update() 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /RxSwiftiOS/User.swift: -------------------------------------------------------------------------------- 1 | // 2 | // User.swift 3 | // RxSwiftiOS 4 | // 5 | // Created by Marin Todorov on 5/18/17. 6 | // Copyright © 2017 Underplot ltd. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | typealias JSONObject = [String: Any] 12 | 13 | struct User { 14 | let id: Int 15 | let login: String 16 | let avatarUrl: String 17 | 18 | init?(object: JSONObject) { 19 | guard let id = object["id"] as? Int, 20 | let login = object["login"] as? String, 21 | let avatarUrl = object["avatar_url"] as? String else { 22 | return nil 23 | } 24 | self.id = id 25 | self.login = login 26 | self.avatarUrl = avatarUrl 27 | } 28 | 29 | init(_ id: Int, _ login: String, _ avatarUrl: String) { 30 | self.id = id 31 | self.login = login 32 | self.avatarUrl = avatarUrl 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /RxSwiftiOS/UserCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UserCell.swift 3 | // RxSwiftiOS 4 | // 5 | // Created by Marin Todorov on 5/18/17. 6 | // Copyright © 2017 Underplot ltd. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class UserCell: UICollectionViewCell { 12 | 13 | @IBOutlet var name: UILabel! 14 | @IBOutlet var photo: UIImageView! 15 | 16 | } 17 | --------------------------------------------------------------------------------