├── .gitignore ├── LICENSE.txt ├── Preview.png ├── README.md ├── Screenshots ├── 1.jpeg ├── 2.jpeg └── 3.jpeg ├── Sidebar.xcodeproj ├── project.pbxproj └── xcshareddata │ └── xcschemes │ └── Sidebar.xcscheme └── Sidebar ├── AppDelegate.swift ├── Assets.xcassets ├── AccentColor.colorset │ └── Contents.json ├── AppIcon.appiconset │ └── Contents.json └── Contents.json ├── Base.lproj └── LaunchScreen.storyboard ├── Compact ├── BrowseViewController.swift ├── LibraryViewController.swift ├── ListenNowViewController.swift ├── RadioViewController.swift ├── SearchViewController.swift └── TabBarController.swift ├── Info.plist ├── SceneDelegate.swift └── SidebarViewController.swift /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/xcode,macos 3 | 4 | ### macOS ### 5 | # General 6 | .DS_Store 7 | .AppleDouble 8 | .LSOverride 9 | 10 | # Icon must end with two \r 11 | Icon 12 | 13 | # Thumbnails 14 | ._* 15 | 16 | # Files that might appear in the root of a volume 17 | .DocumentRevisions-V100 18 | .fseventsd 19 | .Spotlight-V100 20 | .TemporaryItems 21 | .Trashes 22 | .VolumeIcon.icns 23 | .com.apple.timemachine.donotpresent 24 | 25 | # Directories potentially created on remote AFP share 26 | .AppleDB 27 | .AppleDesktop 28 | Network Trash Folder 29 | Temporary Items 30 | .apdisk 31 | 32 | ### Xcode ### 33 | # Xcode 34 | # 35 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 36 | 37 | ## User settings 38 | xcuserdata/ 39 | 40 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 41 | *.xcscmblueprint 42 | *.xccheckout 43 | 44 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 45 | build/ 46 | DerivedData/ 47 | *.moved-aside 48 | *.pbxuser 49 | !default.pbxuser 50 | *.mode1v3 51 | !default.mode1v3 52 | *.mode2v3 53 | !default.mode2v3 54 | *.perspectivev3 55 | !default.perspectivev3 56 | 57 | ### Xcode Patch ### 58 | *.xcodeproj/* 59 | !*.xcodeproj/project.pbxproj 60 | !*.xcodeproj/xcshareddata/ 61 | !*.xcworkspace/contents.xcworkspacedata 62 | /*.gcno 63 | 64 | 65 | # End of https://www.gitignore.io/api/xcode,macos -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apple, iPhone, iMac, iPad Pro, Apple Pencil, Apple Watch, App Store, TestFlight, Siri, and SiriKit are trademarks of Apple, Inc. 2 | 3 | The following license applies to the source code, and other elements of this package: 4 | 5 | Copyright © 2020 Apple Inc. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | 13 | -------------------------------------------------------------------------------- /Preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosatanaka/sidebar-ios14/611b38cb5af1c7e2c505c038155a3d596357492d/Preview.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sidebar iOS 14 2 | 3 | This is a sample project demonstrating how to implement the new Sidebar UI on an iPad app using Swift. It tries to mimic the UI of the new Music app on iPadOS 14.0: 4 | 5 | ![Preview.png](Preview.png) 6 | 7 | It contains just the code required to create the UI, and it was based on the Apple's sample project [Implementing Modern Collection Views](https://developer.apple.com/documentation/uikit/views_and_controls/collection_views/implementing_modern_collection_views). 8 | 9 | ## Multiplatform with SwiftUI 10 | 11 | Check out [this repository](https://github.com/marcosatanaka/multiplatform-sidebar-swiftui) to see how to do this for a multiplatform app (iOS, iPadOS, macOS) built with SwiftUI. 12 | 13 | ## TO-DO 14 | 15 | - [ ] Maintain the selection when contracting/expanding a section. 16 | - [ ] Restore the state of a view controller when changing between regular and compact mode. 17 | - [x] Revert to tab bar based navigation on compact layouts, and on the iPhone. 18 | 19 | ## Known bugs 20 | 21 | Starting the app in compact mode, and then changing it to regular mode causes the following error: 22 | 23 | ``` 24 | Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unexpected view controller change in Secondary column for expanding ' 25 | ``` 26 | 27 | I have a [question for this on the Apple Developer Forums](https://developer.apple.com/forums/thread/653562), I'm not sure if this is a bug in the API, or if I'm using it incorrectly. 28 | 29 | ## Documentation links 30 | 31 | - [Human Interface Guidelines for the Sidebar](https://developer.apple.com/design/human-interface-guidelines/ios/bars/sidebars/) 32 | - [Updated UISplitViewController documentation](https://developer.apple.com/documentation/uikit/uisplitviewcontroller) 33 | 34 | ## WWDC20 videos 35 | 36 | - [Design for iPad](https://developer.apple.com/videos/play/wwdc2020/10206/) 37 | - [Build for iPad](https://developer.apple.com/videos/play/wwdc2020/10105/) 38 | - [Advances in UICollectionView](https://developer.apple.com/videos/play/wwdc2020/10097/) 39 | - [Advances in diffable data sources](https://developer.apple.com/videos/play/wwdc2020/10045/) 40 | - [Lists in UICollectionView](https://developer.apple.com/videos/play/wwdc2020/10026/) 41 | - [Modern cell configuration](https://developer.apple.com/videos/play/wwdc2020/10027/) 42 | -------------------------------------------------------------------------------- /Screenshots/1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosatanaka/sidebar-ios14/611b38cb5af1c7e2c505c038155a3d596357492d/Screenshots/1.jpeg -------------------------------------------------------------------------------- /Screenshots/2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosatanaka/sidebar-ios14/611b38cb5af1c7e2c505c038155a3d596357492d/Screenshots/2.jpeg -------------------------------------------------------------------------------- /Screenshots/3.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcosatanaka/sidebar-ios14/611b38cb5af1c7e2c505c038155a3d596357492d/Screenshots/3.jpeg -------------------------------------------------------------------------------- /Sidebar.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 6C08665124A2FB91009174A0 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C08665024A2FB91009174A0 /* AppDelegate.swift */; }; 11 | 6C08665324A2FB91009174A0 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C08665224A2FB91009174A0 /* SceneDelegate.swift */; }; 12 | 6C08665A24A2FB94009174A0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6C08665924A2FB94009174A0 /* Assets.xcassets */; }; 13 | 6C08665D24A2FB94009174A0 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6C08665B24A2FB94009174A0 /* LaunchScreen.storyboard */; }; 14 | 6C08666724A2FC0B009174A0 /* SidebarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C08666524A2FC0B009174A0 /* SidebarViewController.swift */; }; 15 | B143594F24A4C35600D6C950 /* TabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B143594E24A4C35600D6C950 /* TabBarController.swift */; }; 16 | B143595224A4C40400D6C950 /* ListenNowViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B143595124A4C40400D6C950 /* ListenNowViewController.swift */; }; 17 | B143595424A4C41400D6C950 /* BrowseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B143595324A4C41400D6C950 /* BrowseViewController.swift */; }; 18 | B143595624A4C41D00D6C950 /* RadioViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B143595524A4C41D00D6C950 /* RadioViewController.swift */; }; 19 | B143595824A4C42400D6C950 /* LibraryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B143595724A4C42400D6C950 /* LibraryViewController.swift */; }; 20 | B143595A24A4C42A00D6C950 /* SearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B143595924A4C42A00D6C950 /* SearchViewController.swift */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXFileReference section */ 24 | 6C08664D24A2FB91009174A0 /* Sidebar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Sidebar.app; sourceTree = BUILT_PRODUCTS_DIR; }; 25 | 6C08665024A2FB91009174A0 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 26 | 6C08665224A2FB91009174A0 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 27 | 6C08665924A2FB94009174A0 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28 | 6C08665C24A2FB94009174A0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | 6C08665E24A2FB94009174A0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 6C08666524A2FC0B009174A0 /* SidebarViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SidebarViewController.swift; sourceTree = ""; }; 31 | B143594E24A4C35600D6C950 /* TabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarController.swift; sourceTree = ""; }; 32 | B143595124A4C40400D6C950 /* ListenNowViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListenNowViewController.swift; sourceTree = ""; }; 33 | B143595324A4C41400D6C950 /* BrowseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowseViewController.swift; sourceTree = ""; }; 34 | B143595524A4C41D00D6C950 /* RadioViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioViewController.swift; sourceTree = ""; }; 35 | B143595724A4C42400D6C950 /* LibraryViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibraryViewController.swift; sourceTree = ""; }; 36 | B143595924A4C42A00D6C950 /* SearchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchViewController.swift; sourceTree = ""; }; 37 | /* End PBXFileReference section */ 38 | 39 | /* Begin PBXFrameworksBuildPhase section */ 40 | 6C08664A24A2FB91009174A0 /* Frameworks */ = { 41 | isa = PBXFrameworksBuildPhase; 42 | buildActionMask = 2147483647; 43 | files = ( 44 | ); 45 | runOnlyForDeploymentPostprocessing = 0; 46 | }; 47 | /* End PBXFrameworksBuildPhase section */ 48 | 49 | /* Begin PBXGroup section */ 50 | 6C08664424A2FB90009174A0 = { 51 | isa = PBXGroup; 52 | children = ( 53 | 6C08664F24A2FB91009174A0 /* Sidebar */, 54 | 6C08664E24A2FB91009174A0 /* Products */, 55 | ); 56 | sourceTree = ""; 57 | }; 58 | 6C08664E24A2FB91009174A0 /* Products */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 6C08664D24A2FB91009174A0 /* Sidebar.app */, 62 | ); 63 | name = Products; 64 | sourceTree = ""; 65 | }; 66 | 6C08664F24A2FB91009174A0 /* Sidebar */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 6C08665024A2FB91009174A0 /* AppDelegate.swift */, 70 | 6C08665224A2FB91009174A0 /* SceneDelegate.swift */, 71 | 6C08666524A2FC0B009174A0 /* SidebarViewController.swift */, 72 | B143595024A4C3EE00D6C950 /* Compact */, 73 | 6C08665924A2FB94009174A0 /* Assets.xcassets */, 74 | 6C08665B24A2FB94009174A0 /* LaunchScreen.storyboard */, 75 | 6C08665E24A2FB94009174A0 /* Info.plist */, 76 | ); 77 | path = Sidebar; 78 | sourceTree = ""; 79 | }; 80 | B143595024A4C3EE00D6C950 /* Compact */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | B143594E24A4C35600D6C950 /* TabBarController.swift */, 84 | B143595124A4C40400D6C950 /* ListenNowViewController.swift */, 85 | B143595324A4C41400D6C950 /* BrowseViewController.swift */, 86 | B143595524A4C41D00D6C950 /* RadioViewController.swift */, 87 | B143595724A4C42400D6C950 /* LibraryViewController.swift */, 88 | B143595924A4C42A00D6C950 /* SearchViewController.swift */, 89 | ); 90 | path = Compact; 91 | sourceTree = ""; 92 | }; 93 | /* End PBXGroup section */ 94 | 95 | /* Begin PBXNativeTarget section */ 96 | 6C08664C24A2FB91009174A0 /* Sidebar */ = { 97 | isa = PBXNativeTarget; 98 | buildConfigurationList = 6C08666124A2FB94009174A0 /* Build configuration list for PBXNativeTarget "Sidebar" */; 99 | buildPhases = ( 100 | 6C08664924A2FB91009174A0 /* Sources */, 101 | 6C08664A24A2FB91009174A0 /* Frameworks */, 102 | 6C08664B24A2FB91009174A0 /* Resources */, 103 | ); 104 | buildRules = ( 105 | ); 106 | dependencies = ( 107 | ); 108 | name = Sidebar; 109 | productName = Sidebar; 110 | productReference = 6C08664D24A2FB91009174A0 /* Sidebar.app */; 111 | productType = "com.apple.product-type.application"; 112 | }; 113 | /* End PBXNativeTarget section */ 114 | 115 | /* Begin PBXProject section */ 116 | 6C08664524A2FB90009174A0 /* Project object */ = { 117 | isa = PBXProject; 118 | attributes = { 119 | LastSwiftUpdateCheck = 1200; 120 | LastUpgradeCheck = 1200; 121 | TargetAttributes = { 122 | 6C08664C24A2FB91009174A0 = { 123 | CreatedOnToolsVersion = 12.0; 124 | }; 125 | }; 126 | }; 127 | buildConfigurationList = 6C08664824A2FB90009174A0 /* Build configuration list for PBXProject "Sidebar" */; 128 | compatibilityVersion = "Xcode 9.3"; 129 | developmentRegion = en; 130 | hasScannedForEncodings = 0; 131 | knownRegions = ( 132 | en, 133 | Base, 134 | ); 135 | mainGroup = 6C08664424A2FB90009174A0; 136 | productRefGroup = 6C08664E24A2FB91009174A0 /* Products */; 137 | projectDirPath = ""; 138 | projectRoot = ""; 139 | targets = ( 140 | 6C08664C24A2FB91009174A0 /* Sidebar */, 141 | ); 142 | }; 143 | /* End PBXProject section */ 144 | 145 | /* Begin PBXResourcesBuildPhase section */ 146 | 6C08664B24A2FB91009174A0 /* Resources */ = { 147 | isa = PBXResourcesBuildPhase; 148 | buildActionMask = 2147483647; 149 | files = ( 150 | 6C08665D24A2FB94009174A0 /* LaunchScreen.storyboard in Resources */, 151 | 6C08665A24A2FB94009174A0 /* Assets.xcassets in Resources */, 152 | ); 153 | runOnlyForDeploymentPostprocessing = 0; 154 | }; 155 | /* End PBXResourcesBuildPhase section */ 156 | 157 | /* Begin PBXSourcesBuildPhase section */ 158 | 6C08664924A2FB91009174A0 /* Sources */ = { 159 | isa = PBXSourcesBuildPhase; 160 | buildActionMask = 2147483647; 161 | files = ( 162 | B143595A24A4C42A00D6C950 /* SearchViewController.swift in Sources */, 163 | 6C08665124A2FB91009174A0 /* AppDelegate.swift in Sources */, 164 | B143595624A4C41D00D6C950 /* RadioViewController.swift in Sources */, 165 | 6C08665324A2FB91009174A0 /* SceneDelegate.swift in Sources */, 166 | B143594F24A4C35600D6C950 /* TabBarController.swift in Sources */, 167 | B143595224A4C40400D6C950 /* ListenNowViewController.swift in Sources */, 168 | 6C08666724A2FC0B009174A0 /* SidebarViewController.swift in Sources */, 169 | B143595824A4C42400D6C950 /* LibraryViewController.swift in Sources */, 170 | B143595424A4C41400D6C950 /* BrowseViewController.swift in Sources */, 171 | ); 172 | runOnlyForDeploymentPostprocessing = 0; 173 | }; 174 | /* End PBXSourcesBuildPhase section */ 175 | 176 | /* Begin PBXVariantGroup section */ 177 | 6C08665B24A2FB94009174A0 /* LaunchScreen.storyboard */ = { 178 | isa = PBXVariantGroup; 179 | children = ( 180 | 6C08665C24A2FB94009174A0 /* Base */, 181 | ); 182 | name = LaunchScreen.storyboard; 183 | sourceTree = ""; 184 | }; 185 | /* End PBXVariantGroup section */ 186 | 187 | /* Begin XCBuildConfiguration section */ 188 | 6C08665F24A2FB94009174A0 /* Debug */ = { 189 | isa = XCBuildConfiguration; 190 | buildSettings = { 191 | ALWAYS_SEARCH_USER_PATHS = NO; 192 | CLANG_ANALYZER_NONNULL = YES; 193 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 194 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 195 | CLANG_CXX_LIBRARY = "libc++"; 196 | CLANG_ENABLE_MODULES = YES; 197 | CLANG_ENABLE_OBJC_ARC = YES; 198 | CLANG_ENABLE_OBJC_WEAK = YES; 199 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 200 | CLANG_WARN_BOOL_CONVERSION = YES; 201 | CLANG_WARN_COMMA = YES; 202 | CLANG_WARN_CONSTANT_CONVERSION = YES; 203 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 204 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 205 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 206 | CLANG_WARN_EMPTY_BODY = YES; 207 | CLANG_WARN_ENUM_CONVERSION = YES; 208 | CLANG_WARN_INFINITE_RECURSION = YES; 209 | CLANG_WARN_INT_CONVERSION = YES; 210 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 211 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 212 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 213 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 214 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 215 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 216 | CLANG_WARN_STRICT_PROTOTYPES = YES; 217 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 218 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 219 | CLANG_WARN_UNREACHABLE_CODE = YES; 220 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 221 | COPY_PHASE_STRIP = NO; 222 | DEBUG_INFORMATION_FORMAT = dwarf; 223 | ENABLE_STRICT_OBJC_MSGSEND = YES; 224 | ENABLE_TESTABILITY = YES; 225 | GCC_C_LANGUAGE_STANDARD = gnu11; 226 | GCC_DYNAMIC_NO_PIC = NO; 227 | GCC_NO_COMMON_BLOCKS = YES; 228 | GCC_OPTIMIZATION_LEVEL = 0; 229 | GCC_PREPROCESSOR_DEFINITIONS = ( 230 | "DEBUG=1", 231 | "$(inherited)", 232 | ); 233 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 234 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 235 | GCC_WARN_UNDECLARED_SELECTOR = YES; 236 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 237 | GCC_WARN_UNUSED_FUNCTION = YES; 238 | GCC_WARN_UNUSED_VARIABLE = YES; 239 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 240 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 241 | MTL_FAST_MATH = YES; 242 | ONLY_ACTIVE_ARCH = YES; 243 | SDKROOT = iphoneos; 244 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 245 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 246 | }; 247 | name = Debug; 248 | }; 249 | 6C08666024A2FB94009174A0 /* Release */ = { 250 | isa = XCBuildConfiguration; 251 | buildSettings = { 252 | ALWAYS_SEARCH_USER_PATHS = NO; 253 | CLANG_ANALYZER_NONNULL = YES; 254 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 255 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 256 | CLANG_CXX_LIBRARY = "libc++"; 257 | CLANG_ENABLE_MODULES = YES; 258 | CLANG_ENABLE_OBJC_ARC = YES; 259 | CLANG_ENABLE_OBJC_WEAK = YES; 260 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 261 | CLANG_WARN_BOOL_CONVERSION = YES; 262 | CLANG_WARN_COMMA = YES; 263 | CLANG_WARN_CONSTANT_CONVERSION = YES; 264 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 265 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 266 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 267 | CLANG_WARN_EMPTY_BODY = YES; 268 | CLANG_WARN_ENUM_CONVERSION = YES; 269 | CLANG_WARN_INFINITE_RECURSION = YES; 270 | CLANG_WARN_INT_CONVERSION = YES; 271 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 272 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 273 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 274 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 275 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 276 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 277 | CLANG_WARN_STRICT_PROTOTYPES = YES; 278 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 279 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 280 | CLANG_WARN_UNREACHABLE_CODE = YES; 281 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 282 | COPY_PHASE_STRIP = NO; 283 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 284 | ENABLE_NS_ASSERTIONS = NO; 285 | ENABLE_STRICT_OBJC_MSGSEND = YES; 286 | GCC_C_LANGUAGE_STANDARD = gnu11; 287 | GCC_NO_COMMON_BLOCKS = YES; 288 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 289 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 290 | GCC_WARN_UNDECLARED_SELECTOR = YES; 291 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 292 | GCC_WARN_UNUSED_FUNCTION = YES; 293 | GCC_WARN_UNUSED_VARIABLE = YES; 294 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 295 | MTL_ENABLE_DEBUG_INFO = NO; 296 | MTL_FAST_MATH = YES; 297 | SDKROOT = iphoneos; 298 | SWIFT_COMPILATION_MODE = wholemodule; 299 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 300 | VALIDATE_PRODUCT = YES; 301 | }; 302 | name = Release; 303 | }; 304 | 6C08666224A2FB94009174A0 /* Debug */ = { 305 | isa = XCBuildConfiguration; 306 | buildSettings = { 307 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 308 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 309 | CODE_SIGN_STYLE = Automatic; 310 | DEVELOPMENT_TEAM = SJF85Q6EJ9; 311 | INFOPLIST_FILE = Sidebar/Info.plist; 312 | LD_RUNPATH_SEARCH_PATHS = ( 313 | "$(inherited)", 314 | "@executable_path/Frameworks", 315 | ); 316 | PRODUCT_BUNDLE_IDENTIFIER = br.com.marcosatanaka.Sidebar; 317 | PRODUCT_NAME = "$(TARGET_NAME)"; 318 | SWIFT_VERSION = 5.0; 319 | TARGETED_DEVICE_FAMILY = "1,2"; 320 | }; 321 | name = Debug; 322 | }; 323 | 6C08666324A2FB94009174A0 /* Release */ = { 324 | isa = XCBuildConfiguration; 325 | buildSettings = { 326 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 327 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 328 | CODE_SIGN_STYLE = Automatic; 329 | DEVELOPMENT_TEAM = SJF85Q6EJ9; 330 | INFOPLIST_FILE = Sidebar/Info.plist; 331 | LD_RUNPATH_SEARCH_PATHS = ( 332 | "$(inherited)", 333 | "@executable_path/Frameworks", 334 | ); 335 | PRODUCT_BUNDLE_IDENTIFIER = br.com.marcosatanaka.Sidebar; 336 | PRODUCT_NAME = "$(TARGET_NAME)"; 337 | SWIFT_VERSION = 5.0; 338 | TARGETED_DEVICE_FAMILY = "1,2"; 339 | }; 340 | name = Release; 341 | }; 342 | /* End XCBuildConfiguration section */ 343 | 344 | /* Begin XCConfigurationList section */ 345 | 6C08664824A2FB90009174A0 /* Build configuration list for PBXProject "Sidebar" */ = { 346 | isa = XCConfigurationList; 347 | buildConfigurations = ( 348 | 6C08665F24A2FB94009174A0 /* Debug */, 349 | 6C08666024A2FB94009174A0 /* Release */, 350 | ); 351 | defaultConfigurationIsVisible = 0; 352 | defaultConfigurationName = Release; 353 | }; 354 | 6C08666124A2FB94009174A0 /* Build configuration list for PBXNativeTarget "Sidebar" */ = { 355 | isa = XCConfigurationList; 356 | buildConfigurations = ( 357 | 6C08666224A2FB94009174A0 /* Debug */, 358 | 6C08666324A2FB94009174A0 /* Release */, 359 | ); 360 | defaultConfigurationIsVisible = 0; 361 | defaultConfigurationName = Release; 362 | }; 363 | /* End XCConfigurationList section */ 364 | }; 365 | rootObject = 6C08664524A2FB90009174A0 /* Project object */; 366 | } 367 | -------------------------------------------------------------------------------- /Sidebar.xcodeproj/xcshareddata/xcschemes/Sidebar.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 45 | 51 | 52 | 53 | 54 | 60 | 62 | 68 | 69 | 70 | 71 | 73 | 74 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /Sidebar/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | @UIApplicationMain 4 | class AppDelegate: UIResponder, UIApplicationDelegate { 5 | 6 | 7 | 8 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 9 | // Override point for customization after application launch. 10 | return true 11 | } 12 | 13 | // MARK: UISceneSession Lifecycle 14 | 15 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 16 | // Called when a new scene session is being created. 17 | // Use this method to select a configuration to create the new scene with. 18 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 19 | } 20 | 21 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 22 | // Called when the user discards a scene session. 23 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 24 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 25 | } 26 | 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Sidebar/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Sidebar/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Sidebar/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Sidebar/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 | -------------------------------------------------------------------------------- /Sidebar/Compact/BrowseViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import os.log 3 | 4 | class BrowseViewController: UIViewController { 5 | 6 | override func viewDidLoad() { 7 | super.viewDidLoad() 8 | view.backgroundColor = .systemBackground 9 | navigationController?.navigationBar.prefersLargeTitles = true 10 | title = "Browse" 11 | } 12 | 13 | override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { 14 | super.viewWillTransition(to: size, with: coordinator) 15 | os_log("BrowseViewController (%p) will transition to width %f", self, size.width) 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Sidebar/Compact/LibraryViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import os.log 3 | 4 | class LibraryViewController: UIViewController { 5 | 6 | override func viewDidLoad() { 7 | super.viewDidLoad() 8 | view.backgroundColor = .systemBackground 9 | navigationController?.navigationBar.prefersLargeTitles = true 10 | title = "Library" 11 | } 12 | 13 | override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { 14 | super.viewWillTransition(to: size, with: coordinator) 15 | os_log("LibraryViewController (%p) will transition to width %f", self, size.width) 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Sidebar/Compact/ListenNowViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import os.log 3 | 4 | class ListenNowViewController: UIViewController { 5 | 6 | override func viewDidLoad() { 7 | super.viewDidLoad() 8 | view.backgroundColor = .systemBackground 9 | navigationController?.navigationBar.prefersLargeTitles = true 10 | title = "Listen Now" 11 | } 12 | 13 | override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { 14 | super.viewWillTransition(to: size, with: coordinator) 15 | os_log("ListenNowViewController (%p) will transition to width %f", self, size.width) 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Sidebar/Compact/RadioViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import os.log 3 | 4 | class RadioViewController: UIViewController { 5 | 6 | override func viewDidLoad() { 7 | super.viewDidLoad() 8 | view.backgroundColor = .systemBackground 9 | navigationController?.navigationBar.prefersLargeTitles = true 10 | title = "Radio" 11 | } 12 | 13 | override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { 14 | super.viewWillTransition(to: size, with: coordinator) 15 | os_log("RadioViewController (%p) will transition to width %f", self, size.width) 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Sidebar/Compact/SearchViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import os.log 3 | 4 | class SearchViewController: UIViewController { 5 | 6 | override func viewDidLoad() { 7 | super.viewDidLoad() 8 | view.backgroundColor = .systemBackground 9 | navigationController?.navigationBar.prefersLargeTitles = true 10 | title = "Search" 11 | } 12 | 13 | override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { 14 | super.viewWillTransition(to: size, with: coordinator) 15 | os_log("SearchViewController (%p) will transition to width %f", self, size.width) 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Sidebar/Compact/TabBarController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class TabBarController: UITabBarController { 4 | 5 | private lazy var listenNowViewController = makeListenNowViewController() 6 | private lazy var browseViewController = makeBrowseViewController() 7 | private lazy var radioViewController = makeRadioViewController() 8 | private lazy var libraryViewController = makeLibraryViewController() 9 | private lazy var searchViewController = makeSearchViewController() 10 | 11 | override func viewDidLoad() { 12 | super.viewDidLoad() 13 | viewControllers = [listenNowViewController, 14 | browseViewController, 15 | radioViewController, 16 | libraryViewController, 17 | searchViewController] 18 | } 19 | 20 | override func viewWillAppear(_ animated: Bool) { 21 | super.viewWillAppear(animated) 22 | selectedIndex = 0 23 | } 24 | 25 | } 26 | 27 | private extension TabBarController { 28 | 29 | private func makeListenNowViewController() -> UINavigationController { 30 | let vc = ListenNowViewController() 31 | vc.tabBarItem = UITabBarItem(title: "Listen Now", 32 | image: UIImage(systemName: "play.circle.fill"), 33 | tag: 0) 34 | return UINavigationController(rootViewController: vc) 35 | } 36 | 37 | private func makeBrowseViewController() -> UINavigationController { 38 | let vc = BrowseViewController() 39 | vc.tabBarItem = UITabBarItem(title: "Browse", 40 | image: UIImage(systemName: "square.grid.2x2.fill"), 41 | tag: 1) 42 | return UINavigationController(rootViewController: vc) 43 | } 44 | 45 | private func makeRadioViewController() -> UINavigationController { 46 | let vc = RadioViewController() 47 | vc.tabBarItem = UITabBarItem(title: "Radio", 48 | image: UIImage(systemName: "dot.radiowaves.left.and.right"), 49 | tag: 2) 50 | return UINavigationController(rootViewController: vc) 51 | } 52 | 53 | private func makeLibraryViewController() -> UINavigationController { 54 | let vc = LibraryViewController() 55 | vc.tabBarItem = UITabBarItem(title: "Library", 56 | image: UIImage(systemName: "rectangle.stack.fill"), 57 | tag: 3) 58 | return UINavigationController(rootViewController: vc) 59 | } 60 | 61 | private func makeSearchViewController() -> UINavigationController { 62 | let vc = SearchViewController() 63 | vc.tabBarItem = UITabBarItem(title: "Search", 64 | image: UIImage(systemName: "magnifyingglass"), 65 | tag: 4) 66 | return UINavigationController(rootViewController: vc) 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /Sidebar/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | 37 | 38 | 39 | 40 | UIApplicationSupportsIndirectInputEvents 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIRequiredDeviceCapabilities 45 | 46 | armv7 47 | 48 | UISupportedInterfaceOrientations 49 | 50 | UIInterfaceOrientationPortrait 51 | UIInterfaceOrientationLandscapeLeft 52 | UIInterfaceOrientationLandscapeRight 53 | 54 | UISupportedInterfaceOrientations~ipad 55 | 56 | UIInterfaceOrientationPortrait 57 | UIInterfaceOrientationPortraitUpsideDown 58 | UIInterfaceOrientationLandscapeLeft 59 | UIInterfaceOrientationLandscapeRight 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /Sidebar/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 4 | 5 | var window: UIWindow? 6 | 7 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 8 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 9 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 10 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 11 | if let windowScene = scene as? UIWindowScene { 12 | let window = UIWindow(windowScene: windowScene) 13 | let splitViewController = UISplitViewController(style: .doubleColumn) 14 | splitViewController.preferredDisplayMode = .oneBesideSecondary 15 | splitViewController.presentsWithGesture = false 16 | splitViewController.preferredSplitBehavior = .tile 17 | 18 | splitViewController.setViewController(SidebarViewController(), for: .primary) 19 | splitViewController.setViewController(TabBarController(), for: .compact) 20 | 21 | window.rootViewController = splitViewController 22 | self.window = window 23 | window.makeKeyAndVisible() 24 | } 25 | } 26 | 27 | func sceneDidDisconnect(_ scene: UIScene) { 28 | // Called as the scene is being released by the system. 29 | // This occurs shortly after the scene enters the background, or when its session is discarded. 30 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 31 | // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). 32 | } 33 | 34 | func sceneDidBecomeActive(_ scene: UIScene) { 35 | // Called when the scene has moved from an inactive state to an active state. 36 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 37 | } 38 | 39 | func sceneWillResignActive(_ scene: UIScene) { 40 | // Called when the scene will move from an active state to an inactive state. 41 | // This may occur due to temporary interruptions (ex. an incoming phone call). 42 | } 43 | 44 | func sceneWillEnterForeground(_ scene: UIScene) { 45 | // Called as the scene transitions from the background to the foreground. 46 | // Use this method to undo the changes made on entering the background. 47 | } 48 | 49 | func sceneDidEnterBackground(_ scene: UIScene) { 50 | // Called as the scene transitions from the foreground to the background. 51 | // Use this method to save data, release shared resources, and store enough scene-specific state information 52 | // to restore the scene back to its current state. 53 | } 54 | 55 | 56 | } 57 | 58 | -------------------------------------------------------------------------------- /Sidebar/SidebarViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class SidebarViewController: UIViewController { 4 | 5 | private var dataSource: UICollectionViewDiffableDataSource! = nil 6 | private var collectionView: UICollectionView! = nil 7 | private var secondaryViewControllers = [UINavigationController(rootViewController: ListenNowViewController()), 8 | UINavigationController(rootViewController: BrowseViewController()), 9 | UINavigationController(rootViewController: RadioViewController()), 10 | UINavigationController(rootViewController: SearchViewController())] 11 | 12 | override func viewDidLoad() { 13 | super.viewDidLoad() 14 | navigationItem.title = "Music" 15 | navigationController?.navigationBar.prefersLargeTitles = true 16 | configureHierarchy() 17 | configureDataSource() 18 | addNavigationButtons() 19 | setInitialSecondaryView() 20 | } 21 | 22 | private func setInitialSecondaryView() { 23 | collectionView.selectItem(at: IndexPath(row: 0, section: 0), 24 | animated: false, 25 | scrollPosition: UICollectionView.ScrollPosition.centeredVertically) 26 | splitViewController?.setViewController(secondaryViewControllers[0], for: .secondary) 27 | } 28 | 29 | private func addNavigationButtons() { 30 | navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Edit", style: .plain, target: self, action: nil) 31 | } 32 | } 33 | 34 | // MARK: - Layout 35 | 36 | extension SidebarViewController { 37 | 38 | private func createLayout() -> UICollectionViewLayout { 39 | return UICollectionViewCompositionalLayout { section, layoutEnvironment in 40 | var config = UICollectionLayoutListConfiguration(appearance: .sidebar) 41 | config.headerMode = section == 0 ? .none : .firstItemInSection 42 | return NSCollectionLayoutSection.list(using: config, layoutEnvironment: layoutEnvironment) 43 | } 44 | } 45 | 46 | } 47 | 48 | // MARK: - Data 49 | 50 | extension SidebarViewController { 51 | 52 | private func configureHierarchy() { 53 | collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: createLayout()) 54 | collectionView.delegate = self 55 | 56 | collectionView.translatesAutoresizingMaskIntoConstraints = false 57 | view.addSubview(collectionView) 58 | NSLayoutConstraint.activate([ 59 | collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor), 60 | collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor), 61 | collectionView.topAnchor.constraint(equalTo: view.topAnchor), 62 | collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor) 63 | ]) 64 | } 65 | 66 | private func configureDataSource() { 67 | // Configuring cells 68 | 69 | let headerRegistration = UICollectionView.CellRegistration { (cell, indexPath, item) in 70 | var content = cell.defaultContentConfiguration() 71 | content.text = item.title 72 | cell.contentConfiguration = content 73 | cell.accessories = [.outlineDisclosure()] 74 | } 75 | 76 | let cellRegistration = UICollectionView.CellRegistration { (cell, indexPath, item) in 77 | var content = cell.defaultContentConfiguration() 78 | content.text = item.title 79 | content.image = item.image 80 | cell.contentConfiguration = content 81 | cell.accessories = [] 82 | } 83 | 84 | // Creating the datasource 85 | 86 | dataSource = UICollectionViewDiffableDataSource(collectionView: collectionView) { 87 | (collectionView: UICollectionView, indexPath: IndexPath, item: Item) -> UICollectionViewCell? in 88 | if indexPath.item == 0 && indexPath.section != 0 { 89 | return collectionView.dequeueConfiguredReusableCell(using: headerRegistration, for: indexPath, item: item) 90 | } else { 91 | return collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: item) 92 | } 93 | } 94 | 95 | // Creating and applying snapshots 96 | 97 | let sections: [Section] = [.tabs, .library, .playlists] 98 | var snapshot = NSDiffableDataSourceSnapshot() 99 | snapshot.appendSections(sections) 100 | dataSource.apply(snapshot, animatingDifferences: false) 101 | 102 | for section in sections { 103 | switch section { 104 | case .tabs: 105 | var sectionSnapshot = NSDiffableDataSourceSectionSnapshot() 106 | sectionSnapshot.append(tabsItems) 107 | dataSource.apply(sectionSnapshot, to: section) 108 | case .library: 109 | let headerItem = Item(title: section.rawValue, image: nil) 110 | var sectionSnapshot = NSDiffableDataSourceSectionSnapshot() 111 | sectionSnapshot.append([headerItem]) 112 | sectionSnapshot.append(libraryItems, to: headerItem) 113 | sectionSnapshot.expand([headerItem]) 114 | dataSource.apply(sectionSnapshot, to: section) 115 | case .playlists: 116 | let headerItem = Item(title: section.rawValue, image: nil) 117 | var sectionSnapshot = NSDiffableDataSourceSectionSnapshot() 118 | sectionSnapshot.append([headerItem]) 119 | sectionSnapshot.append(playlistItems, to: headerItem) 120 | sectionSnapshot.expand([headerItem]) 121 | dataSource.apply(sectionSnapshot, to: section) 122 | } 123 | } 124 | } 125 | 126 | } 127 | 128 | // MARK: - UICollectionViewDelegate 129 | 130 | extension SidebarViewController: UICollectionViewDelegate { 131 | 132 | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 133 | guard indexPath.section == 0 else { return } 134 | splitViewController?.setViewController(secondaryViewControllers[indexPath.row], for: .secondary) 135 | } 136 | 137 | } 138 | 139 | // MARK: - Structs and sample data 140 | 141 | struct Item: Hashable { 142 | let title: String? 143 | let image: UIImage? 144 | private let identifier = UUID() 145 | } 146 | 147 | let tabsItems = [Item(title: "Listen Now", image: UIImage(systemName: "play.circle")), 148 | Item(title: "Browse", image: UIImage(systemName: "square.grid.2x2")), 149 | Item(title: "Radio", image: UIImage(systemName: "dot.radiowaves.left.and.right")), 150 | Item(title: "Search", image: UIImage(systemName: "magnifyingglass"))] 151 | 152 | let libraryItems = [Item(title: "Recently Added", image: UIImage(systemName: "clock")), 153 | Item(title: "Artists", image: UIImage(systemName: "music.mic")), 154 | Item(title: "Albums", image: UIImage(systemName: "rectangle.stack")), 155 | Item(title: "Songs", image: UIImage(systemName: "music.note")), 156 | Item(title: "Music Videos", image: UIImage(systemName: "tv.music.note")), 157 | Item(title: "TV & Movies", image: UIImage(systemName: "tv"))] 158 | 159 | let playlistItems = [Item(title: "All Playlists", image: UIImage(systemName: "music.note.list")), 160 | Item(title: "Replay 2015", image: UIImage(systemName: "music.note.list")), 161 | Item(title: "Replay 2016", image: UIImage(systemName: "music.note.list")), 162 | Item(title: "Replay 2017", image: UIImage(systemName: "music.note.list")), 163 | Item(title: "Replay 2018", image: UIImage(systemName: "music.note.list")), 164 | Item(title: "Replay 2019", image: UIImage(systemName: "music.note.list")),] 165 | 166 | enum Section: String { 167 | case tabs 168 | case library = "Library" 169 | case playlists = "Playlists" 170 | } 171 | --------------------------------------------------------------------------------