├── .gitignore ├── README.md ├── Weather.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata └── Weather ├── Application Delegate └── AppDelegate.swift ├── Configuration └── Configuration.swift ├── Managers └── DataManager.swift ├── Models ├── Day.swift └── Location.swift ├── Protocols └── JSONDecodable.swift ├── Resources └── Assets.xcassets │ └── AppIcon.appiconset │ └── Contents.json ├── Storyboards ├── LaunchScreen.storyboard └── Main.storyboard ├── Supporting Files └── Info.plist ├── Table View Cells └── DayTableViewCell.swift └── View Controllers └── ViewController.swift /.gitignore: -------------------------------------------------------------------------------- 1 | ######################### 2 | # .gitignore file for Xcode4 / OS X Source projects 3 | # 4 | # NB: if you are storing "built" products, this WILL NOT WORK, 5 | # and you should use a different .gitignore (or none at all) 6 | # This file is for SOURCE projects, where there are many extra 7 | # files that we want to exclude 8 | # 9 | # For updates, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects 10 | ######################### 11 | 12 | ##### 13 | # OS X temporary files that should never be committed 14 | 15 | .DS_Store 16 | *.swp 17 | *.lock 18 | profile 19 | 20 | 21 | #### 22 | # Xcode temporary files that should never be committed 23 | # 24 | # NB: NIB/XIB files still exist even on Storyboard projects, so we want this... 25 | 26 | *~.nib 27 | 28 | 29 | #### 30 | # Xcode build files - 31 | # 32 | # NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "DerivedData" 33 | 34 | DerivedData/ 35 | 36 | # NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "build" 37 | 38 | build/ 39 | 40 | 41 | ##### 42 | # Xcode private settings (window sizes, bookmarks, breakpoints, custom executables, smart groups) 43 | # 44 | # This is complicated: 45 | # 46 | # SOMETIMES you need to put this file in version control. 47 | # Apple designed it poorly - if you use "custom executables", they are 48 | # saved in this file. 49 | # 99% of projects do NOT use those, so they do NOT want to version control this file. 50 | # ..but if you're in the 1%, comment out the line "*.pbxuser" 51 | 52 | *.pbxuser 53 | *.mode1v3 54 | *.mode2v3 55 | *.perspectivev3 56 | # NB: also, whitelist the default ones, some projects need to use these 57 | !default.pbxuser 58 | !default.mode1v3 59 | !default.mode2v3 60 | !default.perspectivev3 61 | 62 | 63 | #### 64 | # Xcode 4 - semi-personal settings, often included in workspaces 65 | # 66 | # You can safely ignore the xcuserdata files - but do NOT ignore the files next to them 67 | # 68 | 69 | xcuserdata 70 | 71 | #### 72 | # XCode 4 workspaces - more detailed 73 | # 74 | # Workspaces are important! They are a core feature of Xcode - don't exclude them :) 75 | # 76 | # Workspace layout is quite spammy. For reference: 77 | # 78 | # (root)/ 79 | # (project-name).xcodeproj/ 80 | # project.pbxproj 81 | # project.xcworkspace/ 82 | # contents.xcworkspacedata 83 | # xcuserdata/ 84 | # (your name)/xcuserdatad/ 85 | # xcuserdata/ 86 | # (your name)/xcuserdatad/ 87 | # 88 | # 89 | # 90 | # Xcode 4 workspaces - SHARED 91 | # 92 | # This is UNDOCUMENTED (google: "developer.apple.com xcshareddata" - 0 results 93 | # But if you're going to kill personal workspaces, at least keep the shared ones... 94 | # 95 | # 96 | !xcshareddata 97 | 98 | #### 99 | # XCode 4 build-schemes 100 | # 101 | # PRIVATE ones are stored inside xcuserdata 102 | !xcschemes 103 | 104 | #### 105 | # Xcode 4 - Deprecated classes 106 | # 107 | # Allegedly, if you manually "deprecate" your classes, they get moved here. 108 | # 109 | # We're using source-control, so this is a "feature" that we do not want! 110 | 111 | *.moved-aside 112 | 113 | # CocoaPods 114 | /Pods 115 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Simple Weather Client 2 | 3 | #### Author: Bart Jacobs 4 | 5 | This application shows how to fetch and display weather data from the [Forecast](https://forecast.io/) API. This project is used to jump start several tutorials I have written on [Cocoacasts](https://cocoacasts.com/). 6 | 7 | If you would like to build and run the project, be sure to add a valid API key to the project in **Configuration.swift**. You can create a free developer account at [Forecast](https://developer.forecast.io). 8 | 9 | **Read more tutorials on [Cocoacasts](https://cocoacasts.com/)**. 10 | -------------------------------------------------------------------------------- /Weather.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | CCD80D6B1D7C316C00CD04D3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCD80D6A1D7C316C00CD04D3 /* AppDelegate.swift */; }; 11 | CCD80D6E1D7C318C00CD04D3 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCD80D6D1D7C318C00CD04D3 /* ViewController.swift */; }; 12 | CCD80D711D7C31B800CD04D3 /* DayTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCD80D701D7C31B800CD04D3 /* DayTableViewCell.swift */; }; 13 | CCD80D741D7C31D100CD04D3 /* Day.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCD80D731D7C31D100CD04D3 /* Day.swift */; }; 14 | CCD80D781D7C320B00CD04D3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CCD80D761D7C320B00CD04D3 /* LaunchScreen.storyboard */; }; 15 | CCD80D791D7C320B00CD04D3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CCD80D771D7C320B00CD04D3 /* Main.storyboard */; }; 16 | CCD80D7C1D7C322E00CD04D3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CCD80D7B1D7C322E00CD04D3 /* Assets.xcassets */; }; 17 | CCD80D821D7C329F00CD04D3 /* JSONDecodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCD80D811D7C329F00CD04D3 /* JSONDecodable.swift */; }; 18 | CCD80D841D7C32E600CD04D3 /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCD80D831D7C32E600CD04D3 /* Location.swift */; }; 19 | CCD80D871D7C347C00CD04D3 /* DataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCD80D861D7C347C00CD04D3 /* DataManager.swift */; }; 20 | CCD80D8A1D7C34C600CD04D3 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCD80D891D7C34C600CD04D3 /* Configuration.swift */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXFileReference section */ 24 | CC76DB071D7B1B2B00995DEF /* Weather.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Weather.app; sourceTree = BUILT_PRODUCTS_DIR; }; 25 | CCD80D6A1D7C316C00CD04D3 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 26 | CCD80D6D1D7C318C00CD04D3 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 27 | CCD80D701D7C31B800CD04D3 /* DayTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DayTableViewCell.swift; sourceTree = ""; }; 28 | CCD80D731D7C31D100CD04D3 /* Day.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Day.swift; sourceTree = ""; }; 29 | CCD80D761D7C320B00CD04D3 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; 30 | CCD80D771D7C320B00CD04D3 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; 31 | CCD80D7B1D7C322E00CD04D3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 32 | CCD80D7E1D7C324600CD04D3 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 33 | CCD80D811D7C329F00CD04D3 /* JSONDecodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONDecodable.swift; sourceTree = ""; }; 34 | CCD80D831D7C32E600CD04D3 /* Location.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Location.swift; sourceTree = ""; }; 35 | CCD80D861D7C347C00CD04D3 /* DataManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataManager.swift; sourceTree = ""; }; 36 | CCD80D891D7C34C600CD04D3 /* Configuration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = ""; }; 37 | /* End PBXFileReference section */ 38 | 39 | /* Begin PBXFrameworksBuildPhase section */ 40 | CC76DB041D7B1B2B00995DEF /* Frameworks */ = { 41 | isa = PBXFrameworksBuildPhase; 42 | buildActionMask = 2147483647; 43 | files = ( 44 | ); 45 | runOnlyForDeploymentPostprocessing = 0; 46 | }; 47 | /* End PBXFrameworksBuildPhase section */ 48 | 49 | /* Begin PBXGroup section */ 50 | CC76DAFE1D7B1B2B00995DEF = { 51 | isa = PBXGroup; 52 | children = ( 53 | CC76DB091D7B1B2B00995DEF /* Weather */, 54 | CC76DB081D7B1B2B00995DEF /* Products */, 55 | ); 56 | sourceTree = ""; 57 | }; 58 | CC76DB081D7B1B2B00995DEF /* Products */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | CC76DB071D7B1B2B00995DEF /* Weather.app */, 62 | ); 63 | name = Products; 64 | sourceTree = ""; 65 | }; 66 | CC76DB091D7B1B2B00995DEF /* Weather */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | CCD80D691D7C314E00CD04D3 /* Application Delegate */, 70 | CCD80D6F1D7C319900CD04D3 /* Table View Cells */, 71 | CCD80D6C1D7C317000CD04D3 /* View Controllers */, 72 | CCD80D881D7C34AA00CD04D3 /* Configuration */, 73 | CCD80D751D7C31F900CD04D3 /* Storyboards */, 74 | CCD80D7A1D7C321100CD04D3 /* Resources */, 75 | CCD80D851D7C345D00CD04D3 /* Managers */, 76 | CCD80D801D7C327B00CD04D3 /* Protocols */, 77 | CCD80D721D7C31BD00CD04D3 /* Models */, 78 | CCD80D7D1D7C323200CD04D3 /* Supporting Files */, 79 | ); 80 | path = Weather; 81 | sourceTree = ""; 82 | }; 83 | CCD80D691D7C314E00CD04D3 /* Application Delegate */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | CCD80D6A1D7C316C00CD04D3 /* AppDelegate.swift */, 87 | ); 88 | path = "Application Delegate"; 89 | sourceTree = ""; 90 | }; 91 | CCD80D6C1D7C317000CD04D3 /* View Controllers */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | CCD80D6D1D7C318C00CD04D3 /* ViewController.swift */, 95 | ); 96 | path = "View Controllers"; 97 | sourceTree = ""; 98 | }; 99 | CCD80D6F1D7C319900CD04D3 /* Table View Cells */ = { 100 | isa = PBXGroup; 101 | children = ( 102 | CCD80D701D7C31B800CD04D3 /* DayTableViewCell.swift */, 103 | ); 104 | path = "Table View Cells"; 105 | sourceTree = ""; 106 | }; 107 | CCD80D721D7C31BD00CD04D3 /* Models */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | CCD80D731D7C31D100CD04D3 /* Day.swift */, 111 | CCD80D831D7C32E600CD04D3 /* Location.swift */, 112 | ); 113 | path = Models; 114 | sourceTree = ""; 115 | }; 116 | CCD80D751D7C31F900CD04D3 /* Storyboards */ = { 117 | isa = PBXGroup; 118 | children = ( 119 | CCD80D771D7C320B00CD04D3 /* Main.storyboard */, 120 | CCD80D761D7C320B00CD04D3 /* LaunchScreen.storyboard */, 121 | ); 122 | path = Storyboards; 123 | sourceTree = ""; 124 | }; 125 | CCD80D7A1D7C321100CD04D3 /* Resources */ = { 126 | isa = PBXGroup; 127 | children = ( 128 | CCD80D7B1D7C322E00CD04D3 /* Assets.xcassets */, 129 | ); 130 | path = Resources; 131 | sourceTree = ""; 132 | }; 133 | CCD80D7D1D7C323200CD04D3 /* Supporting Files */ = { 134 | isa = PBXGroup; 135 | children = ( 136 | CCD80D7E1D7C324600CD04D3 /* Info.plist */, 137 | ); 138 | path = "Supporting Files"; 139 | sourceTree = ""; 140 | }; 141 | CCD80D801D7C327B00CD04D3 /* Protocols */ = { 142 | isa = PBXGroup; 143 | children = ( 144 | CCD80D811D7C329F00CD04D3 /* JSONDecodable.swift */, 145 | ); 146 | path = Protocols; 147 | sourceTree = ""; 148 | }; 149 | CCD80D851D7C345D00CD04D3 /* Managers */ = { 150 | isa = PBXGroup; 151 | children = ( 152 | CCD80D861D7C347C00CD04D3 /* DataManager.swift */, 153 | ); 154 | path = Managers; 155 | sourceTree = ""; 156 | }; 157 | CCD80D881D7C34AA00CD04D3 /* Configuration */ = { 158 | isa = PBXGroup; 159 | children = ( 160 | CCD80D891D7C34C600CD04D3 /* Configuration.swift */, 161 | ); 162 | path = Configuration; 163 | sourceTree = ""; 164 | }; 165 | /* End PBXGroup section */ 166 | 167 | /* Begin PBXNativeTarget section */ 168 | CC76DB061D7B1B2B00995DEF /* Weather */ = { 169 | isa = PBXNativeTarget; 170 | buildConfigurationList = CC76DB191D7B1B2B00995DEF /* Build configuration list for PBXNativeTarget "Weather" */; 171 | buildPhases = ( 172 | CC76DB031D7B1B2B00995DEF /* Sources */, 173 | CC76DB041D7B1B2B00995DEF /* Frameworks */, 174 | CC76DB051D7B1B2B00995DEF /* Resources */, 175 | ); 176 | buildRules = ( 177 | ); 178 | dependencies = ( 179 | ); 180 | name = Weather; 181 | productName = Weather; 182 | productReference = CC76DB071D7B1B2B00995DEF /* Weather.app */; 183 | productType = "com.apple.product-type.application"; 184 | }; 185 | /* End PBXNativeTarget section */ 186 | 187 | /* Begin PBXProject section */ 188 | CC76DAFF1D7B1B2B00995DEF /* Project object */ = { 189 | isa = PBXProject; 190 | attributes = { 191 | LastSwiftUpdateCheck = 0800; 192 | LastUpgradeCheck = 0900; 193 | ORGANIZATIONNAME = Cocoacasts; 194 | TargetAttributes = { 195 | CC76DB061D7B1B2B00995DEF = { 196 | CreatedOnToolsVersion = 8.0; 197 | DevelopmentTeam = 2493UGBPKJ; 198 | LastSwiftMigration = 0900; 199 | ProvisioningStyle = Automatic; 200 | }; 201 | }; 202 | }; 203 | buildConfigurationList = CC76DB021D7B1B2B00995DEF /* Build configuration list for PBXProject "Weather" */; 204 | compatibilityVersion = "Xcode 3.2"; 205 | developmentRegion = English; 206 | hasScannedForEncodings = 0; 207 | knownRegions = ( 208 | en, 209 | Base, 210 | ); 211 | mainGroup = CC76DAFE1D7B1B2B00995DEF; 212 | productRefGroup = CC76DB081D7B1B2B00995DEF /* Products */; 213 | projectDirPath = ""; 214 | projectRoot = ""; 215 | targets = ( 216 | CC76DB061D7B1B2B00995DEF /* Weather */, 217 | ); 218 | }; 219 | /* End PBXProject section */ 220 | 221 | /* Begin PBXResourcesBuildPhase section */ 222 | CC76DB051D7B1B2B00995DEF /* Resources */ = { 223 | isa = PBXResourcesBuildPhase; 224 | buildActionMask = 2147483647; 225 | files = ( 226 | CCD80D781D7C320B00CD04D3 /* LaunchScreen.storyboard in Resources */, 227 | CCD80D7C1D7C322E00CD04D3 /* Assets.xcassets in Resources */, 228 | CCD80D791D7C320B00CD04D3 /* Main.storyboard in Resources */, 229 | ); 230 | runOnlyForDeploymentPostprocessing = 0; 231 | }; 232 | /* End PBXResourcesBuildPhase section */ 233 | 234 | /* Begin PBXSourcesBuildPhase section */ 235 | CC76DB031D7B1B2B00995DEF /* Sources */ = { 236 | isa = PBXSourcesBuildPhase; 237 | buildActionMask = 2147483647; 238 | files = ( 239 | CCD80D6E1D7C318C00CD04D3 /* ViewController.swift in Sources */, 240 | CCD80D821D7C329F00CD04D3 /* JSONDecodable.swift in Sources */, 241 | CCD80D6B1D7C316C00CD04D3 /* AppDelegate.swift in Sources */, 242 | CCD80D871D7C347C00CD04D3 /* DataManager.swift in Sources */, 243 | CCD80D741D7C31D100CD04D3 /* Day.swift in Sources */, 244 | CCD80D841D7C32E600CD04D3 /* Location.swift in Sources */, 245 | CCD80D8A1D7C34C600CD04D3 /* Configuration.swift in Sources */, 246 | CCD80D711D7C31B800CD04D3 /* DayTableViewCell.swift in Sources */, 247 | ); 248 | runOnlyForDeploymentPostprocessing = 0; 249 | }; 250 | /* End PBXSourcesBuildPhase section */ 251 | 252 | /* Begin XCBuildConfiguration section */ 253 | CC76DB171D7B1B2B00995DEF /* Debug */ = { 254 | isa = XCBuildConfiguration; 255 | buildSettings = { 256 | ALWAYS_SEARCH_USER_PATHS = NO; 257 | CLANG_ANALYZER_NONNULL = YES; 258 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 259 | CLANG_CXX_LIBRARY = "libc++"; 260 | CLANG_ENABLE_MODULES = YES; 261 | CLANG_ENABLE_OBJC_ARC = YES; 262 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 263 | CLANG_WARN_BOOL_CONVERSION = YES; 264 | CLANG_WARN_COMMA = YES; 265 | CLANG_WARN_CONSTANT_CONVERSION = YES; 266 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 267 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 268 | CLANG_WARN_EMPTY_BODY = YES; 269 | CLANG_WARN_ENUM_CONVERSION = YES; 270 | CLANG_WARN_INFINITE_RECURSION = YES; 271 | CLANG_WARN_INT_CONVERSION = YES; 272 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 273 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 274 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 275 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 276 | CLANG_WARN_STRICT_PROTOTYPES = YES; 277 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 278 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 279 | CLANG_WARN_UNREACHABLE_CODE = YES; 280 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 281 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 282 | COPY_PHASE_STRIP = NO; 283 | DEBUG_INFORMATION_FORMAT = dwarf; 284 | ENABLE_STRICT_OBJC_MSGSEND = YES; 285 | ENABLE_TESTABILITY = YES; 286 | GCC_C_LANGUAGE_STANDARD = gnu99; 287 | GCC_DYNAMIC_NO_PIC = NO; 288 | GCC_NO_COMMON_BLOCKS = YES; 289 | GCC_OPTIMIZATION_LEVEL = 0; 290 | GCC_PREPROCESSOR_DEFINITIONS = ( 291 | "DEBUG=1", 292 | "$(inherited)", 293 | ); 294 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 295 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 296 | GCC_WARN_UNDECLARED_SELECTOR = YES; 297 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 298 | GCC_WARN_UNUSED_FUNCTION = YES; 299 | GCC_WARN_UNUSED_VARIABLE = YES; 300 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 301 | MTL_ENABLE_DEBUG_INFO = YES; 302 | ONLY_ACTIVE_ARCH = YES; 303 | SDKROOT = iphoneos; 304 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 305 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 306 | }; 307 | name = Debug; 308 | }; 309 | CC76DB181D7B1B2B00995DEF /* Release */ = { 310 | isa = XCBuildConfiguration; 311 | buildSettings = { 312 | ALWAYS_SEARCH_USER_PATHS = NO; 313 | CLANG_ANALYZER_NONNULL = YES; 314 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 315 | CLANG_CXX_LIBRARY = "libc++"; 316 | CLANG_ENABLE_MODULES = YES; 317 | CLANG_ENABLE_OBJC_ARC = YES; 318 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 319 | CLANG_WARN_BOOL_CONVERSION = YES; 320 | CLANG_WARN_COMMA = YES; 321 | CLANG_WARN_CONSTANT_CONVERSION = YES; 322 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 323 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 324 | CLANG_WARN_EMPTY_BODY = YES; 325 | CLANG_WARN_ENUM_CONVERSION = YES; 326 | CLANG_WARN_INFINITE_RECURSION = YES; 327 | CLANG_WARN_INT_CONVERSION = YES; 328 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 329 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 330 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 331 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 332 | CLANG_WARN_STRICT_PROTOTYPES = YES; 333 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 334 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 335 | CLANG_WARN_UNREACHABLE_CODE = YES; 336 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 337 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 338 | COPY_PHASE_STRIP = NO; 339 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 340 | ENABLE_NS_ASSERTIONS = NO; 341 | ENABLE_STRICT_OBJC_MSGSEND = YES; 342 | GCC_C_LANGUAGE_STANDARD = gnu99; 343 | GCC_NO_COMMON_BLOCKS = YES; 344 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 345 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 346 | GCC_WARN_UNDECLARED_SELECTOR = YES; 347 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 348 | GCC_WARN_UNUSED_FUNCTION = YES; 349 | GCC_WARN_UNUSED_VARIABLE = YES; 350 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 351 | MTL_ENABLE_DEBUG_INFO = NO; 352 | SDKROOT = iphoneos; 353 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 354 | VALIDATE_PRODUCT = YES; 355 | }; 356 | name = Release; 357 | }; 358 | CC76DB1A1D7B1B2B00995DEF /* Debug */ = { 359 | isa = XCBuildConfiguration; 360 | buildSettings = { 361 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 362 | DEVELOPMENT_TEAM = 2493UGBPKJ; 363 | INFOPLIST_FILE = "$(SRCROOT)/Weather/Supporting Files/Info.plist"; 364 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 365 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 366 | PRODUCT_BUNDLE_IDENTIFIER = com.cocoacasts.Weather; 367 | PRODUCT_NAME = "$(TARGET_NAME)"; 368 | SWIFT_SWIFT3_OBJC_INFERENCE = Off; 369 | SWIFT_VERSION = 4.0; 370 | }; 371 | name = Debug; 372 | }; 373 | CC76DB1B1D7B1B2B00995DEF /* Release */ = { 374 | isa = XCBuildConfiguration; 375 | buildSettings = { 376 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 377 | DEVELOPMENT_TEAM = 2493UGBPKJ; 378 | INFOPLIST_FILE = "$(SRCROOT)/Weather/Supporting Files/Info.plist"; 379 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 380 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 381 | PRODUCT_BUNDLE_IDENTIFIER = com.cocoacasts.Weather; 382 | PRODUCT_NAME = "$(TARGET_NAME)"; 383 | SWIFT_SWIFT3_OBJC_INFERENCE = Off; 384 | SWIFT_VERSION = 4.0; 385 | }; 386 | name = Release; 387 | }; 388 | /* End XCBuildConfiguration section */ 389 | 390 | /* Begin XCConfigurationList section */ 391 | CC76DB021D7B1B2B00995DEF /* Build configuration list for PBXProject "Weather" */ = { 392 | isa = XCConfigurationList; 393 | buildConfigurations = ( 394 | CC76DB171D7B1B2B00995DEF /* Debug */, 395 | CC76DB181D7B1B2B00995DEF /* Release */, 396 | ); 397 | defaultConfigurationIsVisible = 0; 398 | defaultConfigurationName = Release; 399 | }; 400 | CC76DB191D7B1B2B00995DEF /* Build configuration list for PBXNativeTarget "Weather" */ = { 401 | isa = XCConfigurationList; 402 | buildConfigurations = ( 403 | CC76DB1A1D7B1B2B00995DEF /* Debug */, 404 | CC76DB1B1D7B1B2B00995DEF /* Release */, 405 | ); 406 | defaultConfigurationIsVisible = 0; 407 | defaultConfigurationName = Release; 408 | }; 409 | /* End XCConfigurationList section */ 410 | }; 411 | rootObject = CC76DAFF1D7B1B2B00995DEF /* Project object */; 412 | } 413 | -------------------------------------------------------------------------------- /Weather.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Weather/Application Delegate/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Weather 4 | // 5 | // Created by Bart Jacobs on 03/09/16. 6 | // Copyright © 2016 Cocoacasts. 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: [UIApplicationLaunchOptionsKey: Any]?) -> 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 invalidate graphics rendering callbacks. 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 active 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 | -------------------------------------------------------------------------------- /Weather/Configuration/Configuration.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Configuration.swift 3 | // Weather 4 | // 5 | // Created by Bart Jacobs on 04/09/16. 6 | // Copyright © 2016 Cocoacasts. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | enum API { 12 | 13 | static let APIKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 14 | static let BaseURL = URL(string: "https://api.darksky.net/forecast/")! 15 | 16 | static var AuthenticatedBaseURL: URL { 17 | return BaseURL.appendingPathComponent(APIKey) 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Weather/Managers/DataManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DataManager.swift 3 | // Weather 4 | // 5 | // Created by Bart Jacobs on 04/09/16. 6 | // Copyright © 2016 Cocoacasts. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | enum DataManagerError: Error { 12 | 13 | case Unknown 14 | case FailedRequest 15 | case InvalidResponse 16 | 17 | } 18 | 19 | final class DataManager { 20 | 21 | typealias WeatherDataCompletion = (Location?, DataManagerError?) -> () 22 | 23 | private let baseURL: URL 24 | 25 | // MARK: - Initialization 26 | 27 | init(baseURL: URL) { 28 | self.baseURL = baseURL 29 | } 30 | 31 | // MARK: - Requesting Data 32 | 33 | func weatherDataForLocation(latitude: Double, longitude: Double, completion: @escaping WeatherDataCompletion) { 34 | // Create URL 35 | let URL = baseURL.appendingPathComponent("\(latitude),\(longitude)") 36 | 37 | // Create Data Task 38 | URLSession.shared.dataTask(with: URL) { (data, response, error) in 39 | self.didFetchWeatherData(data: data, response: response, error: error, completion: completion) 40 | }.resume() 41 | } 42 | 43 | // MARK: - Helper Methods 44 | 45 | private func didFetchWeatherData(data: Data?, response: URLResponse?, error: Error?, completion: WeatherDataCompletion) { 46 | if let _ = error { 47 | completion(nil, .FailedRequest) 48 | 49 | } else if let data = data, let response = response as? HTTPURLResponse { 50 | if response.statusCode == 200 { 51 | processWeatherData(data: data, completion: completion) 52 | } else { 53 | completion(nil, .FailedRequest) 54 | } 55 | 56 | } else { 57 | completion(nil, .Unknown) 58 | } 59 | } 60 | 61 | private func processWeatherData(data: Data, completion: WeatherDataCompletion) { 62 | if let JSON = try? JSONSerialization.jsonObject(with: data, options: []) { 63 | completion(Location(JSON: JSON), nil) 64 | } else { 65 | completion(nil, .InvalidResponse) 66 | } 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /Weather/Models/Day.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Day.swift 3 | // Weather 4 | // 5 | // Created by Bart Jacobs on 03/09/16. 6 | // Copyright © 2016 Cocoacasts. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | struct Day { 12 | 13 | let date: Date 14 | let min: Double 15 | let max: Double 16 | 17 | } 18 | 19 | extension Day: JSONDecodable { 20 | 21 | public init?(JSON: Any) { 22 | guard let JSON = JSON as? [String: AnyObject] else { return nil } 23 | 24 | guard let time = JSON["time"] as? Double else { return nil } 25 | guard let min = JSON["temperatureMin"] as? Double else { return nil } 26 | guard let max = JSON["temperatureMax"] as? Double else { return nil } 27 | 28 | self.min = min 29 | self.max = max 30 | self.date = Date(timeIntervalSince1970: time) 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Weather/Models/Location.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Location.swift 3 | // Weather 4 | // 5 | // Created by Bart Jacobs on 04/09/16. 6 | // Copyright © 2016 Cocoacasts. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | struct Location { 12 | 13 | let lat: Double 14 | let long: Double 15 | 16 | let days: [Day] 17 | 18 | } 19 | 20 | extension Location: JSONDecodable { 21 | 22 | init?(JSON: Any) { 23 | guard let JSON = JSON as? [String: AnyObject] else { return nil } 24 | 25 | guard let lat = JSON["latitude"] as? Double else { return nil } 26 | guard let long = JSON["longitude"] as? Double else { return nil } 27 | guard let dailyData = JSON["daily"]?["data"] as? [[String: AnyObject]] else { return nil } 28 | 29 | self.lat = lat 30 | self.long = long 31 | 32 | var buffer = [Day]() 33 | 34 | for dailyDataPoint in dailyData { 35 | if let day = Day(JSON: dailyDataPoint) { 36 | buffer.append(day) 37 | } 38 | } 39 | 40 | self.days = buffer 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Weather/Protocols/JSONDecodable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // JSONDecodable.swift 3 | // Weather 4 | // 5 | // Created by Bart Jacobs on 04/09/16. 6 | // Copyright © 2016 Cocoacasts. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | protocol JSONDecodable { 12 | 13 | init?(JSON: Any) 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Weather/Resources/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 | } -------------------------------------------------------------------------------- /Weather/Storyboards/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 | -------------------------------------------------------------------------------- /Weather/Storyboards/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 25 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Weather/Supporting Files/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 | -------------------------------------------------------------------------------- /Weather/Table View Cells/DayTableViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DayTableViewCell.swift 3 | // Weather 4 | // 5 | // Created by Bart Jacobs on 03/09/16. 6 | // Copyright © 2016 Cocoacasts. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class DayTableViewCell: UITableViewCell { 12 | 13 | static let ReuseIdentifier = "DayTableViewCell" 14 | 15 | @IBOutlet var dateLabel: UILabel! 16 | @IBOutlet var temperatureLabel: UILabel! 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Weather/View Controllers/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Weather 4 | // 5 | // Created by Bart Jacobs on 03/09/16. 6 | // Copyright © 2016 Cocoacasts. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | // MARK: - Outlets 14 | 15 | @IBOutlet var messageLabel: UILabel! 16 | @IBOutlet var tableView: UITableView! 17 | @IBOutlet var activityIndicatorView: UIActivityIndicatorView! 18 | 19 | // MARK: - Private Properties 20 | 21 | var days = [Day]() 22 | 23 | private let dataManager = DataManager(baseURL: API.AuthenticatedBaseURL) 24 | 25 | lazy var dateFormatter: DateFormatter = { 26 | let dateFormatter = DateFormatter() 27 | dateFormatter.dateFormat = "MMM d" 28 | return dateFormatter 29 | }() 30 | 31 | // MARK: - View Life Cycle 32 | 33 | override func viewDidLoad() { 34 | super.viewDidLoad() 35 | 36 | setupView() 37 | 38 | fetchWeatherData() 39 | } 40 | 41 | // MARK: - View Methods 42 | 43 | private func setupView() { 44 | setupTableView() 45 | setupMessageLabel() 46 | setupActivityIndicatorView() 47 | } 48 | 49 | private func updateView() { 50 | let hasDays = days.count > 0 51 | tableView.isHidden = !hasDays 52 | messageLabel.isHidden = hasDays 53 | 54 | if hasDays { 55 | tableView.reloadData() 56 | } 57 | } 58 | 59 | // MARK: - 60 | 61 | private func setupTableView() { 62 | tableView.isHidden = true 63 | } 64 | 65 | private func setupMessageLabel() { 66 | messageLabel.isHidden = true 67 | messageLabel.text = "Hmm ... I don't have anything to show you." 68 | } 69 | 70 | private func setupActivityIndicatorView() { 71 | activityIndicatorView.startAnimating() 72 | } 73 | 74 | // MARK: - Helper Methods 75 | 76 | private func fetchWeatherData() { 77 | dataManager.weatherDataForLocation(latitude: 37.8267, longitude: -122.423) { (location, error) in 78 | DispatchQueue.main.async { 79 | if let location = location { 80 | self.days = location.days 81 | } 82 | 83 | self.updateView() 84 | self.activityIndicatorView.stopAnimating() 85 | } 86 | } 87 | } 88 | 89 | } 90 | 91 | extension ViewController: UITableViewDataSource { 92 | 93 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 94 | return days.count 95 | } 96 | 97 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 98 | // Dequeue Reusable Cell 99 | let cell = tableView.dequeueReusableCell(withIdentifier: DayTableViewCell.ReuseIdentifier, for: indexPath) as! DayTableViewCell 100 | 101 | // Fetch Day 102 | let day = days[indexPath.row] 103 | 104 | // Configure Cell 105 | cell.dateLabel.text = dateFormatter.string(from: day.date) 106 | cell.temperatureLabel.text = String(format: "%.0f - %.0f", day.min, day.max) 107 | 108 | return cell 109 | } 110 | 111 | } 112 | --------------------------------------------------------------------------------