Skip to content

Initial Commit #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions Clima.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
objects = {

/* Begin PBXBuildFile section */
95589E7125DAD5020002DF3A /* WeatherManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95589E7025DAD5020002DF3A /* WeatherManager.swift */; };
95589E7425DB02160002DF3A /* WeatherData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95589E7325DB02160002DF3A /* WeatherData.swift */; };
95E72F0525DC38150097412B /* WeatherModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E72F0425DC38150097412B /* WeatherModel.swift */; };
ADAA27B1231BBFAF00365194 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADAA27B0231BBFAF00365194 /* AppDelegate.swift */; };
ADAA27B3231BBFAF00365194 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADAA27B2231BBFAF00365194 /* SceneDelegate.swift */; };
ADAA27B5231BBFAF00365194 /* WeatherViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADAA27B4231BBFAF00365194 /* WeatherViewController.swift */; };
ADAA27B8231BBFAF00365194 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = ADAA27B6231BBFAF00365194 /* Main.storyboard */; };
ADAA27BA231BBFB300365194 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ADAA27B9231BBFB300365194 /* Assets.xcassets */; };
ADAA27BD231BBFB300365194 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = ADAA27BB231BBFB300365194 /* LaunchScreen.storyboard */; };
ADAA27C6231BC02C00365194 /* light_background.pdf in Resources */ = {isa = PBXBuildFile; fileRef = ADAA27C4231BC02B00365194 /* light_background.pdf */; };
ADAA27C7231BC02C00365194 /* dark_background.pdf in Resources */ = {isa = PBXBuildFile; fileRef = ADAA27C5231BC02B00365194 /* dark_background.pdf */; };
ADAA27CE231BC87F00365194 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = ADAA27CD231BC87F00365194 /* README.md */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
95589E7025DAD5020002DF3A /* WeatherManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherManager.swift; sourceTree = "<group>"; };
95589E7325DB02160002DF3A /* WeatherData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherData.swift; sourceTree = "<group>"; };
95E72F0425DC38150097412B /* WeatherModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherModel.swift; sourceTree = "<group>"; };
ADAA27AD231BBFAF00365194 /* Clima.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Clima.app; sourceTree = BUILT_PRODUCTS_DIR; };
ADAA27B0231BBFAF00365194 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
ADAA27B2231BBFAF00365194 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -27,8 +31,6 @@
ADAA27B9231BBFB300365194 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
ADAA27BC231BBFB300365194 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
ADAA27BE231BBFB300365194 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
ADAA27C4231BC02B00365194 /* light_background.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = light_background.pdf; sourceTree = "<group>"; };
ADAA27C5231BC02B00365194 /* dark_background.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = dark_background.pdf; sourceTree = "<group>"; };
ADAA27CD231BC87F00365194 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -43,6 +45,16 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
95589E6F25DAD4F10002DF3A /* Model */ = {
isa = PBXGroup;
children = (
95589E7025DAD5020002DF3A /* WeatherManager.swift */,
95589E7325DB02160002DF3A /* WeatherData.swift */,
95E72F0425DC38150097412B /* WeatherModel.swift */,
);
path = Model;
sourceTree = "<group>";
};
ADAA27A4231BBFAF00365194 = {
isa = PBXGroup;
children = (
Expand All @@ -65,14 +77,12 @@
children = (
ADAA27B0231BBFAF00365194 /* AppDelegate.swift */,
ADAA27B2231BBFAF00365194 /* SceneDelegate.swift */,
ADAA27CA231BC3FA00365194 /* Model */,
95589E6F25DAD4F10002DF3A /* Model */,
ADAA27C9231BC3F200365194 /* View */,
ADAA27C8231BC3E500365194 /* Controller */,
ADAA27B9231BBFB300365194 /* Assets.xcassets */,
ADAA27BB231BBFB300365194 /* LaunchScreen.storyboard */,
ADAA27BE231BBFB300365194 /* Info.plist */,
ADAA27C5231BC02B00365194 /* dark_background.pdf */,
ADAA27C4231BC02B00365194 /* light_background.pdf */,
);
path = Clima;
sourceTree = "<group>";
Expand All @@ -93,13 +103,6 @@
path = View;
sourceTree = "<group>";
};
ADAA27CA231BC3FA00365194 /* Model */ = {
isa = PBXGroup;
children = (
);
path = Model;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -127,7 +130,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1100;
LastUpgradeCheck = 1100;
LastUpgradeCheck = 1240;
ORGANIZATIONNAME = "App Brewery";
TargetAttributes = {
ADAA27AC231BBFAF00365194 = {
Expand Down Expand Up @@ -159,11 +162,9 @@
buildActionMask = 2147483647;
files = (
ADAA27CE231BC87F00365194 /* README.md in Resources */,
ADAA27C7231BC02C00365194 /* dark_background.pdf in Resources */,
ADAA27BD231BBFB300365194 /* LaunchScreen.storyboard in Resources */,
ADAA27BA231BBFB300365194 /* Assets.xcassets in Resources */,
ADAA27B8231BBFAF00365194 /* Main.storyboard in Resources */,
ADAA27C6231BC02C00365194 /* light_background.pdf in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -175,7 +176,10 @@
buildActionMask = 2147483647;
files = (
ADAA27B5231BBFAF00365194 /* WeatherViewController.swift in Sources */,
95589E7425DB02160002DF3A /* WeatherData.swift in Sources */,
ADAA27B1231BBFAF00365194 /* AppDelegate.swift in Sources */,
95589E7125DAD5020002DF3A /* WeatherManager.swift in Sources */,
95E72F0525DC38150097412B /* WeatherModel.swift in Sources */,
ADAA27B3231BBFAF00365194 /* SceneDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -228,6 +232,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -288,6 +293,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Clima.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
6 changes: 3 additions & 3 deletions Clima/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
34 changes: 24 additions & 10 deletions Clima/Assets.xcassets/background.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "background.png",
"scale" : "1x"
"filename" : "light_background.pdf",
"idiom" : "universal"
},
{
"idiom" : "universal",
"scale" : "2x"
"appearances" : [
{
"appearance" : "luminosity",
"value" : "light"
}
],
"filename" : "light_background-1.pdf",
"idiom" : "universal"
},
{
"idiom" : "universal",
"scale" : "3x"
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "dark_background.pdf",
"idiom" : "universal"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
}
Binary file not shown.
File renamed without changes.
Binary file not shown.
56 changes: 56 additions & 0 deletions Clima/Assets.xcassets/myweatherColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"colors" : [
{
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "0.282",
"green" : "0.263",
"red" : "0.107"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "light"
}
],
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "0.282",
"green" : "0.263",
"red" : "0.107"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "1.000",
"red" : "1.000"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
111 changes: 108 additions & 3 deletions Clima/Controller/WeatherViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,123 @@
//

import UIKit
import CoreLocation

class WeatherViewController: UIViewController {



@IBOutlet var txtFieldSearch: UITextField!

@IBOutlet weak var conditionImageView: UIImageView!
@IBOutlet weak var temperatureLabel: UILabel!
@IBOutlet weak var cityLabel: UILabel!
@IBOutlet var locationButton: UIButton!

var weatherManager = WeatherManager()
let locationManager = CLLocationManager()



override func viewDidLoad() {
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.requestLocation()

super.viewDidLoad()
// Do any additional setup after loading the view.
txtFieldSearch.delegate = self
weatherManager.delegate = self



}



@IBAction func getLocationBtn(_ sender: UIButton) {
locationManager.requestLocation()



}
}

//MARK: - > Add a completion
// Add the name of the section



extension WeatherViewController : UITextFieldDelegate {
@IBAction func searchPressed(_ sender: Any) {
txtFieldSearch.endEditing(true)
print(txtFieldSearch.text!)
}
// Lets app process the return button when pressed by user
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
txtFieldSearch.endEditing(true)

print(txtFieldSearch.text!)
return true
}

//Prevents the user from entering textfield with no text
func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
if txtFieldSearch.text != ""{
return true
} else {
txtFieldSearch.placeholder = "Type something here"
return false
}
}

// Allows text field to clear once the return/search button is pressed
func textFieldDidEndEditing(_ textField: UITextField) {

// Use textFieldSearch.text to Get the weather for the city
if let city = txtFieldSearch.text{
weatherManager.retrieveWeather(cityName: city)
}
//Empties the textfield after the user presses button
txtFieldSearch.text = ""
}

}

//MARK: - Weather Manager Extension

extension WeatherViewController: WeatherManagerDelegate {

//Method that updates the UI tools with the weather conditions of desired location
func didUpdateWeather(_ weatherManager : WeatherManager, weather : WeatherModel){
DispatchQueue.main.async {
self.temperatureLabel.text = weather.temperatureString
self.conditionImageView.image = UIImage(systemName: weather.conditionName)
self.cityLabel.text = weather.cityName
}


}

func didFailWithError(error: Error) {
print(error)
}

}

// MARK: - CLLocationManagerDelegate
extension WeatherViewController : CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.last{
locationManager.stopUpdatingLocation()
let lat = location.coordinate.latitude
let lon = location.coordinate.longitude
weatherManager.retrieveWeather(latitude: lat, longitude: lon)
}
}

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("Failed to find user's location \(error.localizedDescription)")

}
}



2 changes: 2 additions & 0 deletions Clima/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your location is necssary for getting the weather of where you are</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
Expand Down
Loading