├── README.md ├── TableViewExtension.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── erencanevren.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── erencanevren.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── TableViewExtension.xcscheme │ └── xcschememanagement.plist └── TableViewExtension ├── AppDelegate.swift ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── CustomTableViewCell.swift ├── CustomTableViewCell.xib ├── HeaderView.swift ├── HeaderView.xib ├── Info.plist ├── SecondTableViewCell.swift ├── SecondTableViewCell.xib ├── TableView+Extension.swift └── ViewController.swift /README.md: -------------------------------------------------------------------------------- 1 | # TableViewExtension 2 | 3 | When we are working with UITableView with code or Nibs we always have to write lots of code for to tableview do its job. This extension helps you write more swifty way to do so. 4 | 5 | ## Usage 6 | 7 | You can register a UITableViewCell, HeaderFooterView as simple as like; 8 | ```swift 9 | tableView.reuse(CustomTableViewCell.self, fromNib: true) // fromNib is a optional. Default value is false. 10 | ``` 11 | You can use this method to dequeue your cell or header view; 12 | ```swift 13 | tableView.dequeue(indexPath, fromNib: true) 14 | ``` 15 | 16 | Here is full the implementation 17 | 18 | ```swift 19 | class ViewController: UIViewController { 20 | 21 | @IBOutlet weak var tableView: UITableView! 22 | 23 | override func viewDidLoad() { 24 | super.viewDidLoad() 25 | 26 | tableView 27 | .reuse(InfoCell.self) // Without nib file 28 | .reuse(CustomTableViewCell.self, fromNib: true) // With nib file 29 | .registerHeaderFooter(HeaderView.self, fromNib: true) 30 | } 31 | } 32 | 33 | extension ViewController: UITableViewDelegate, UITableViewDataSource { 34 | func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 35 | return 10 36 | } 37 | 38 | func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 39 | if indexPath.row % 2 == 0 { 40 | let infoCell: InfoCell = tableView.dequeue(indexPath) 41 | return infoCell 42 | } else { 43 | let secondCell: SecondTableViewCell = tableView.dequeue(indexPath, fromNib: true) 44 | return secondCell 45 | } 46 | } 47 | 48 | func numberOfSectionsInTableView(tableView: UITableView) -> Int { 49 | return 2 50 | } 51 | 52 | func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 53 | let sectionHeaderView: HeaderView? = tableView.dequeueHeaderFooter(fromNib: true) 54 | 55 | return sectionHeaderView 56 | } 57 | } 58 | 59 | ``` 60 | -------------------------------------------------------------------------------- /TableViewExtension.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 529EBECA1D78625E0041704B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529EBEC91D78625E0041704B /* AppDelegate.swift */; }; 11 | 529EBECC1D78625E0041704B /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529EBECB1D78625E0041704B /* ViewController.swift */; }; 12 | 529EBECF1D78625E0041704B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 529EBECD1D78625E0041704B /* Main.storyboard */; }; 13 | 529EBED11D78625E0041704B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 529EBED01D78625E0041704B /* Assets.xcassets */; }; 14 | 529EBED41D78625E0041704B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 529EBED21D78625E0041704B /* LaunchScreen.storyboard */; }; 15 | 529EBEDC1D78628F0041704B /* TableViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529EBEDB1D78628F0041704B /* TableViewExtension.swift */; }; 16 | 529EBEDF1D7866390041704B /* CustomTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529EBEDD1D7866390041704B /* CustomTableViewCell.swift */; }; 17 | 529EBEE01D7866390041704B /* CustomTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 529EBEDE1D7866390041704B /* CustomTableViewCell.xib */; }; 18 | 52DC43741D786BA300EE3971 /* HeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52DC43731D786BA300EE3971 /* HeaderView.swift */; }; 19 | 52DC43771D786C8000EE3971 /* HeaderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 52DC43761D786C8000EE3971 /* HeaderView.xib */; }; 20 | 52DC437C1D786D9300EE3971 /* SecondTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52DC437A1D786D9300EE3971 /* SecondTableViewCell.swift */; }; 21 | 52DC437D1D786D9300EE3971 /* SecondTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 52DC437B1D786D9300EE3971 /* SecondTableViewCell.xib */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXFileReference section */ 25 | 529EBEC61D78625E0041704B /* TableViewExtension.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TableViewExtension.app; sourceTree = BUILT_PRODUCTS_DIR; }; 26 | 529EBEC91D78625E0041704B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 27 | 529EBECB1D78625E0041704B /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 28 | 529EBECE1D78625E0041704B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 29 | 529EBED01D78625E0041704B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 30 | 529EBED31D78625E0041704B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 31 | 529EBED51D78625E0041704B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | 529EBEDB1D78628F0041704B /* TableViewExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewExtension.swift; sourceTree = ""; }; 33 | 529EBEDD1D7866390041704B /* CustomTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomTableViewCell.swift; sourceTree = ""; }; 34 | 529EBEDE1D7866390041704B /* CustomTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CustomTableViewCell.xib; sourceTree = ""; }; 35 | 52DC43731D786BA300EE3971 /* HeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeaderView.swift; sourceTree = ""; }; 36 | 52DC43761D786C8000EE3971 /* HeaderView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HeaderView.xib; sourceTree = ""; }; 37 | 52DC437A1D786D9300EE3971 /* SecondTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecondTableViewCell.swift; sourceTree = ""; }; 38 | 52DC437B1D786D9300EE3971 /* SecondTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SecondTableViewCell.xib; sourceTree = ""; }; 39 | /* End PBXFileReference section */ 40 | 41 | /* Begin PBXFrameworksBuildPhase section */ 42 | 529EBEC31D78625E0041704B /* Frameworks */ = { 43 | isa = PBXFrameworksBuildPhase; 44 | buildActionMask = 2147483647; 45 | files = ( 46 | ); 47 | runOnlyForDeploymentPostprocessing = 0; 48 | }; 49 | /* End PBXFrameworksBuildPhase section */ 50 | 51 | /* Begin PBXGroup section */ 52 | 529EBEBD1D78625E0041704B = { 53 | isa = PBXGroup; 54 | children = ( 55 | 529EBEC81D78625E0041704B /* TableViewExtension */, 56 | 529EBEC71D78625E0041704B /* Products */, 57 | ); 58 | sourceTree = ""; 59 | }; 60 | 529EBEC71D78625E0041704B /* Products */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | 529EBEC61D78625E0041704B /* TableViewExtension.app */, 64 | ); 65 | name = Products; 66 | sourceTree = ""; 67 | }; 68 | 529EBEC81D78625E0041704B /* TableViewExtension */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 529EBEC91D78625E0041704B /* AppDelegate.swift */, 72 | 529EBECB1D78625E0041704B /* ViewController.swift */, 73 | 529EBEDB1D78628F0041704B /* TableViewExtension.swift */, 74 | 529EBECD1D78625E0041704B /* Main.storyboard */, 75 | 52DC43751D786BAA00EE3971 /* Header */, 76 | 52DC43721D786B8500EE3971 /* Cell */, 77 | 529EBED01D78625E0041704B /* Assets.xcassets */, 78 | 529EBED21D78625E0041704B /* LaunchScreen.storyboard */, 79 | 529EBED51D78625E0041704B /* Info.plist */, 80 | ); 81 | path = TableViewExtension; 82 | sourceTree = ""; 83 | }; 84 | 52DC43721D786B8500EE3971 /* Cell */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 529EBEDD1D7866390041704B /* CustomTableViewCell.swift */, 88 | 529EBEDE1D7866390041704B /* CustomTableViewCell.xib */, 89 | 52DC437A1D786D9300EE3971 /* SecondTableViewCell.swift */, 90 | 52DC437B1D786D9300EE3971 /* SecondTableViewCell.xib */, 91 | ); 92 | name = Cell; 93 | sourceTree = ""; 94 | }; 95 | 52DC43751D786BAA00EE3971 /* Header */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | 52DC43731D786BA300EE3971 /* HeaderView.swift */, 99 | 52DC43761D786C8000EE3971 /* HeaderView.xib */, 100 | ); 101 | name = Header; 102 | sourceTree = ""; 103 | }; 104 | /* End PBXGroup section */ 105 | 106 | /* Begin PBXNativeTarget section */ 107 | 529EBEC51D78625E0041704B /* TableViewExtension */ = { 108 | isa = PBXNativeTarget; 109 | buildConfigurationList = 529EBED81D78625E0041704B /* Build configuration list for PBXNativeTarget "TableViewExtension" */; 110 | buildPhases = ( 111 | 529EBEC21D78625E0041704B /* Sources */, 112 | 529EBEC31D78625E0041704B /* Frameworks */, 113 | 529EBEC41D78625E0041704B /* Resources */, 114 | ); 115 | buildRules = ( 116 | ); 117 | dependencies = ( 118 | ); 119 | name = TableViewExtension; 120 | productName = TableViewExtension; 121 | productReference = 529EBEC61D78625E0041704B /* TableViewExtension.app */; 122 | productType = "com.apple.product-type.application"; 123 | }; 124 | /* End PBXNativeTarget section */ 125 | 126 | /* Begin PBXProject section */ 127 | 529EBEBE1D78625E0041704B /* Project object */ = { 128 | isa = PBXProject; 129 | attributes = { 130 | LastSwiftUpdateCheck = 0730; 131 | LastUpgradeCheck = 0730; 132 | ORGANIZATIONNAME = dnb; 133 | TargetAttributes = { 134 | 529EBEC51D78625E0041704B = { 135 | CreatedOnToolsVersion = 7.3.1; 136 | }; 137 | }; 138 | }; 139 | buildConfigurationList = 529EBEC11D78625E0041704B /* Build configuration list for PBXProject "TableViewExtension" */; 140 | compatibilityVersion = "Xcode 3.2"; 141 | developmentRegion = English; 142 | hasScannedForEncodings = 0; 143 | knownRegions = ( 144 | en, 145 | Base, 146 | ); 147 | mainGroup = 529EBEBD1D78625E0041704B; 148 | productRefGroup = 529EBEC71D78625E0041704B /* Products */; 149 | projectDirPath = ""; 150 | projectRoot = ""; 151 | targets = ( 152 | 529EBEC51D78625E0041704B /* TableViewExtension */, 153 | ); 154 | }; 155 | /* End PBXProject section */ 156 | 157 | /* Begin PBXResourcesBuildPhase section */ 158 | 529EBEC41D78625E0041704B /* Resources */ = { 159 | isa = PBXResourcesBuildPhase; 160 | buildActionMask = 2147483647; 161 | files = ( 162 | 529EBED41D78625E0041704B /* LaunchScreen.storyboard in Resources */, 163 | 52DC437D1D786D9300EE3971 /* SecondTableViewCell.xib in Resources */, 164 | 52DC43771D786C8000EE3971 /* HeaderView.xib in Resources */, 165 | 529EBED11D78625E0041704B /* Assets.xcassets in Resources */, 166 | 529EBEE01D7866390041704B /* CustomTableViewCell.xib in Resources */, 167 | 529EBECF1D78625E0041704B /* Main.storyboard in Resources */, 168 | ); 169 | runOnlyForDeploymentPostprocessing = 0; 170 | }; 171 | /* End PBXResourcesBuildPhase section */ 172 | 173 | /* Begin PBXSourcesBuildPhase section */ 174 | 529EBEC21D78625E0041704B /* Sources */ = { 175 | isa = PBXSourcesBuildPhase; 176 | buildActionMask = 2147483647; 177 | files = ( 178 | 52DC43741D786BA300EE3971 /* HeaderView.swift in Sources */, 179 | 529EBEDC1D78628F0041704B /* TableViewExtension.swift in Sources */, 180 | 529EBECC1D78625E0041704B /* ViewController.swift in Sources */, 181 | 529EBEDF1D7866390041704B /* CustomTableViewCell.swift in Sources */, 182 | 529EBECA1D78625E0041704B /* AppDelegate.swift in Sources */, 183 | 52DC437C1D786D9300EE3971 /* SecondTableViewCell.swift in Sources */, 184 | ); 185 | runOnlyForDeploymentPostprocessing = 0; 186 | }; 187 | /* End PBXSourcesBuildPhase section */ 188 | 189 | /* Begin PBXVariantGroup section */ 190 | 529EBECD1D78625E0041704B /* Main.storyboard */ = { 191 | isa = PBXVariantGroup; 192 | children = ( 193 | 529EBECE1D78625E0041704B /* Base */, 194 | ); 195 | name = Main.storyboard; 196 | sourceTree = ""; 197 | }; 198 | 529EBED21D78625E0041704B /* LaunchScreen.storyboard */ = { 199 | isa = PBXVariantGroup; 200 | children = ( 201 | 529EBED31D78625E0041704B /* Base */, 202 | ); 203 | name = LaunchScreen.storyboard; 204 | sourceTree = ""; 205 | }; 206 | /* End PBXVariantGroup section */ 207 | 208 | /* Begin XCBuildConfiguration section */ 209 | 529EBED61D78625E0041704B /* Debug */ = { 210 | isa = XCBuildConfiguration; 211 | buildSettings = { 212 | ALWAYS_SEARCH_USER_PATHS = NO; 213 | CLANG_ANALYZER_NONNULL = YES; 214 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 215 | CLANG_CXX_LIBRARY = "libc++"; 216 | CLANG_ENABLE_MODULES = YES; 217 | CLANG_ENABLE_OBJC_ARC = YES; 218 | CLANG_WARN_BOOL_CONVERSION = YES; 219 | CLANG_WARN_CONSTANT_CONVERSION = YES; 220 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 221 | CLANG_WARN_EMPTY_BODY = YES; 222 | CLANG_WARN_ENUM_CONVERSION = YES; 223 | CLANG_WARN_INT_CONVERSION = YES; 224 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 225 | CLANG_WARN_UNREACHABLE_CODE = YES; 226 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 227 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 228 | COPY_PHASE_STRIP = NO; 229 | DEBUG_INFORMATION_FORMAT = dwarf; 230 | ENABLE_STRICT_OBJC_MSGSEND = YES; 231 | ENABLE_TESTABILITY = YES; 232 | GCC_C_LANGUAGE_STANDARD = gnu99; 233 | GCC_DYNAMIC_NO_PIC = NO; 234 | GCC_NO_COMMON_BLOCKS = YES; 235 | GCC_OPTIMIZATION_LEVEL = 0; 236 | GCC_PREPROCESSOR_DEFINITIONS = ( 237 | "DEBUG=1", 238 | "$(inherited)", 239 | ); 240 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 241 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 242 | GCC_WARN_UNDECLARED_SELECTOR = YES; 243 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 244 | GCC_WARN_UNUSED_FUNCTION = YES; 245 | GCC_WARN_UNUSED_VARIABLE = YES; 246 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 247 | MTL_ENABLE_DEBUG_INFO = YES; 248 | ONLY_ACTIVE_ARCH = YES; 249 | SDKROOT = iphoneos; 250 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 251 | TARGETED_DEVICE_FAMILY = "1,2"; 252 | }; 253 | name = Debug; 254 | }; 255 | 529EBED71D78625E0041704B /* Release */ = { 256 | isa = XCBuildConfiguration; 257 | buildSettings = { 258 | ALWAYS_SEARCH_USER_PATHS = NO; 259 | CLANG_ANALYZER_NONNULL = YES; 260 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 261 | CLANG_CXX_LIBRARY = "libc++"; 262 | CLANG_ENABLE_MODULES = YES; 263 | CLANG_ENABLE_OBJC_ARC = YES; 264 | CLANG_WARN_BOOL_CONVERSION = YES; 265 | CLANG_WARN_CONSTANT_CONVERSION = YES; 266 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 267 | CLANG_WARN_EMPTY_BODY = YES; 268 | CLANG_WARN_ENUM_CONVERSION = YES; 269 | CLANG_WARN_INT_CONVERSION = YES; 270 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 271 | CLANG_WARN_UNREACHABLE_CODE = YES; 272 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 273 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 274 | COPY_PHASE_STRIP = NO; 275 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 276 | ENABLE_NS_ASSERTIONS = NO; 277 | ENABLE_STRICT_OBJC_MSGSEND = YES; 278 | GCC_C_LANGUAGE_STANDARD = gnu99; 279 | GCC_NO_COMMON_BLOCKS = YES; 280 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 281 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 282 | GCC_WARN_UNDECLARED_SELECTOR = YES; 283 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 284 | GCC_WARN_UNUSED_FUNCTION = YES; 285 | GCC_WARN_UNUSED_VARIABLE = YES; 286 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 287 | MTL_ENABLE_DEBUG_INFO = NO; 288 | SDKROOT = iphoneos; 289 | TARGETED_DEVICE_FAMILY = "1,2"; 290 | VALIDATE_PRODUCT = YES; 291 | }; 292 | name = Release; 293 | }; 294 | 529EBED91D78625E0041704B /* Debug */ = { 295 | isa = XCBuildConfiguration; 296 | buildSettings = { 297 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 298 | INFOPLIST_FILE = TableViewExtension/Info.plist; 299 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 300 | PRODUCT_BUNDLE_IDENTIFIER = com.dnb.TableViewExtension; 301 | PRODUCT_NAME = "$(TARGET_NAME)"; 302 | }; 303 | name = Debug; 304 | }; 305 | 529EBEDA1D78625E0041704B /* Release */ = { 306 | isa = XCBuildConfiguration; 307 | buildSettings = { 308 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 309 | INFOPLIST_FILE = TableViewExtension/Info.plist; 310 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 311 | PRODUCT_BUNDLE_IDENTIFIER = com.dnb.TableViewExtension; 312 | PRODUCT_NAME = "$(TARGET_NAME)"; 313 | }; 314 | name = Release; 315 | }; 316 | /* End XCBuildConfiguration section */ 317 | 318 | /* Begin XCConfigurationList section */ 319 | 529EBEC11D78625E0041704B /* Build configuration list for PBXProject "TableViewExtension" */ = { 320 | isa = XCConfigurationList; 321 | buildConfigurations = ( 322 | 529EBED61D78625E0041704B /* Debug */, 323 | 529EBED71D78625E0041704B /* Release */, 324 | ); 325 | defaultConfigurationIsVisible = 0; 326 | defaultConfigurationName = Release; 327 | }; 328 | 529EBED81D78625E0041704B /* Build configuration list for PBXNativeTarget "TableViewExtension" */ = { 329 | isa = XCConfigurationList; 330 | buildConfigurations = ( 331 | 529EBED91D78625E0041704B /* Debug */, 332 | 529EBEDA1D78625E0041704B /* Release */, 333 | ); 334 | defaultConfigurationIsVisible = 0; 335 | defaultConfigurationName = Release; 336 | }; 337 | /* End XCConfigurationList section */ 338 | }; 339 | rootObject = 529EBEBE1D78625E0041704B /* Project object */; 340 | } 341 | -------------------------------------------------------------------------------- /TableViewExtension.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TableViewExtension.xcodeproj/project.xcworkspace/xcuserdata/erencanevren.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serhatsezer/TableViewExtension/a90dcf478274f623358b3e80afdbe825d85af86b/TableViewExtension.xcodeproj/project.xcworkspace/xcuserdata/erencanevren.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /TableViewExtension.xcodeproj/xcuserdata/erencanevren.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /TableViewExtension.xcodeproj/xcuserdata/erencanevren.xcuserdatad/xcschemes/TableViewExtension.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /TableViewExtension.xcodeproj/xcuserdata/erencanevren.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | TableViewExtension.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 529EBEC51D78625E0041704B 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /TableViewExtension/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // TableViewExtension 4 | // 5 | // Created by Serhat Sezer on 01/09/16. 6 | // Copyright © 2016 dnb. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /TableViewExtension/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /TableViewExtension/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 | -------------------------------------------------------------------------------- /TableViewExtension/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 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /TableViewExtension/CustomTableViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomTableViewCell.swift 3 | // TableViewExtension 4 | // 5 | // Created by Serhat Sezer on 01/09/16. 6 | // Copyright © 2016 dnb. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class CustomTableViewCell: UITableViewCell { 12 | 13 | override func awakeFromNib() { 14 | super.awakeFromNib() 15 | // Initialization code 16 | } 17 | 18 | override func setSelected(selected: Bool, animated: Bool) { 19 | super.setSelected(selected, animated: animated) 20 | 21 | // Configure the view for the selected state 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /TableViewExtension/CustomTableViewCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /TableViewExtension/HeaderView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HeaderView.swift 3 | // TableViewExtension 4 | // 5 | // Created by Serhat Sezer on 01/09/16. 6 | // Copyright © 2016 dnb. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class HeaderView: UITableViewHeaderFooterView { 12 | } 13 | -------------------------------------------------------------------------------- /TableViewExtension/HeaderView.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /TableViewExtension/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /TableViewExtension/SecondTableViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SecondTableViewCell.swift 3 | // TableViewExtension 4 | // 5 | // Created by Serhat Sezer on 01/09/16. 6 | // Copyright © 2016 dnb. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SecondTableViewCell: UITableViewCell { 12 | 13 | override func awakeFromNib() { 14 | super.awakeFromNib() 15 | // Initialization code 16 | } 17 | 18 | override func setSelected(selected: Bool, animated: Bool) { 19 | super.setSelected(selected, animated: animated) 20 | 21 | // Configure the view for the selected state 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /TableViewExtension/SecondTableViewCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /TableViewExtension/TableView+Extension.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | protocol Reusable: class { 4 | static var reuseIdentifier: String { get } 5 | } 6 | 7 | extension Reusable { 8 | static var reuseIdentifier: String { 9 | return String(describing: self) 10 | } 11 | } 12 | 13 | extension UITableViewCell: Reusable { } 14 | extension UITableViewHeaderFooterView: Reusable { } 15 | extension UICollectionViewCell: Reusable { } 16 | 17 | extension UITableView { 18 | 19 | // Cells 20 | func reuse(cellClass: Reusable.Type, fromNib: Bool = false) -> UITableView { 21 | if fromNib { 22 | let nib = UINib(nibName: cellClass.reuseIdentifier, bundle: nil) 23 | self.register(nib, forCellReuseIdentifier: cellClass.reuseIdentifier) 24 | } else { 25 | self.register(cellClass, forCellReuseIdentifier: cellClass.reuseIdentifier) 26 | } 27 | 28 | return self 29 | } 30 | 31 | func dequeue(indexPath: IndexPath, fromNib: Bool = false) -> T where T: Reusable { 32 | return self.dequeueReusableCell(withIdentifier: T.reuseIdentifier, for: indexPath) as! T 33 | } 34 | 35 | // HeaderFooterViews 36 | func registerHeaderFooter(headerFooterViewClass: Reusable.Type, fromNib: Bool = false) -> UITableView { 37 | if fromNib { 38 | let nib = UINib(nibName: headerFooterViewClass.reuseIdentifier, bundle: nil) 39 | self.register(nib, forHeaderFooterViewReuseIdentifier: headerFooterViewClass.reuseIdentifier) 40 | } else { 41 | self.register(headerFooterViewClass, forHeaderFooterViewReuseIdentifier: headerFooterViewClass.reuseIdentifier) 42 | } 43 | 44 | return self 45 | } 46 | 47 | func dequeHeaderFooter(fromNib: Bool = false) -> T? where T: Reusable { 48 | return self.dequeueReusableHeaderFooterView(withIdentifier: T.reuseIdentifier) as? T 49 | } 50 | } 51 | 52 | extension UICollectionView { 53 | func reuse(cellClass: Reusable.Type, fromNib: Bool = false) -> UICollectionView { 54 | if fromNib { 55 | let nib = UINib(nibName: cellClass.reuseIdentifier, bundle: nil) 56 | self.register(nib, forCellWithReuseIdentifier: cellClass.reuseIdentifier) 57 | } else { 58 | self.register(cellClass, forCellWithReuseIdentifier: cellClass.reuseIdentifier) 59 | } 60 | 61 | return self 62 | } 63 | 64 | func dequeue(indexPath: IndexPath, fromNib: Bool = false) -> T where T: Reusable { 65 | self.(cellClass: T.self, fromNib: fromNib) 66 | return self.dequeueReusableCell(withReuseIdentifier: T.reuseIdentifier, for: indexPath ) as! T 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /TableViewExtension/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // TableViewExtension 4 | // 5 | // Created by Serhat Sezer on 01/09/16. 6 | // Copyright © 2016 dnb. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | @IBOutlet weak var tableView: UITableView! 14 | 15 | override func viewDidLoad() { 16 | super.viewDidLoad() 17 | 18 | tableView 19 | .registerReusable(CustomTableViewCell.self, fromNib: true) 20 | .registerReusable(SecondTableViewCell.self, fromNib: true) 21 | .registerReusableHeaderFooterClass(HeaderView.self, fromNib: true) 22 | } 23 | } 24 | 25 | extension ViewController: UITableViewDelegate, UITableViewDataSource { 26 | func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 27 | return 10 28 | } 29 | 30 | func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 31 | if indexPath.row % 2 == 0 { 32 | let cell: CustomTableViewCell = tableView.dequeueReusable(indexPath, fromNib: true) 33 | return cell 34 | } else { 35 | let cell: SecondTableViewCell = tableView.dequeueReusable(indexPath, fromNib: true) 36 | return cell 37 | } 38 | } 39 | 40 | func numberOfSectionsInTableView(tableView: UITableView) -> Int { 41 | return 2 42 | } 43 | 44 | func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 45 | let sectionHeaderView: HeaderView? = tableView.dequeueReusableHeaderFooterView(fromNib: true) 46 | 47 | return sectionHeaderView 48 | } 49 | } 50 | 51 | --------------------------------------------------------------------------------