I'm making a TextField which takes a proper date only. Now when I'm using the text field delegate and action methods in the same ViewController class in which my UITextField is, it is working fine. But, I have to make it like a reusable component which can be used in any project by drag and drop. I have two files - MakeDate.swift and ViewController.swift
MakDate.swift --
import Foundation
import UIKit
class MakeDate: NSObject, UITextFieldDelegate {
var textField: UITextField!
var string: String!
var viewController: UIViewController!
let characterset = NSCharacterSet(charactersInString: "0123456789")
init?(textField: UITextField!) {
self.textField = textField
}
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
self.string = string
return true
}
func takeProperDateInput() {
textField.addTarget(textField, action: #selector(self.textChange(_:)), forControlEvents: .EditingChanged)
}
#IBAction func textChange(sender: UITextField) {
print("\(sender.text!)")
print("\(sender.text!) && \(self.string)")
if self.string == "" {
if sender.text?.characters.count == 2 {
let index = sender.text?.endIndex.advancedBy(-2)
sender.text = sender.text?.substringToIndex(index!)
}
else if sender.text?.characters.count == 5 {
let index = sender.text?.endIndex.advancedBy(-2)
sender.text = sender.text?.substringToIndex(index!)
}
}
if sender.text?.characters.count == 1 && self.string != "" {
if self.string.rangeOfCharacterFromSet(characterset.invertedSet) != nil {
let index = sender.text?.endIndex.advancedBy(-1)
sender.text = sender.text?.substringToIndex(index!)
}
else if Int(sender.text!) != 1 && Int(sender.text!) != 0 {
sender.text = "0" + sender.text! + "/"
}
}
else if sender.text?.characters.count == 2 && self.string != "" {
if Int(string) != 1 && Int(string) != 2 && Int(string) != 0{
let index = sender.text?.endIndex.advancedBy(-1)
sender.text = sender.text?.substringToIndex(index!)
}else {
sender.text = sender.text! + "/"
}
}
else if sender.text?.characters.count == 4 && self.string != "" {
if self.string.rangeOfCharacterFromSet(characterset.invertedSet) != nil {
let index = sender.text?.endIndex.advancedBy(-1)
sender.text = sender.text?.substringToIndex(index!)
}
}
else if sender.text?.characters.count == 5 && self.string != "" {
if self.string == "/" {
var yearComponent = sender.text?.componentsSeparatedByString("/")
let index = sender.text?.endIndex.advancedBy(-2)
sender.text = sender.text?.substringToIndex(index!)
sender.text = sender.text! + "0" + yearComponent![1] + "/"
}else {
var yearComponent = sender.text?.componentsSeparatedByString("/")
if Int(yearComponent![1]) > 31 {
let index = sender.text?.endIndex.advancedBy(-1)
sender.text = sender.text?.substringToIndex(index!)
}else if Int(yearComponent![1]) > 0 && Int(yearComponent![1]) < 32 {
sender.text = sender.text! + "/"
}else {
let index = sender.text?.endIndex.advancedBy(-1)
sender.text = sender.text?.substringToIndex(index!)
}
}
}
else if sender.text?.characters.count == 10 && self.string != "" {
let index = sender.text?.endIndex.advancedBy(-4)
if sender.text?.substringFromIndex(index!).rangeOfCharacterFromSet(characterset.invertedSet) != nil {
let index = sender.text?.endIndex.advancedBy(-4)
sender.text = sender.text?.substringToIndex(index!)
} else {
var yearComponent = sender.text?.componentsSeparatedByString("/")
if Int(yearComponent![2]) == 0 {
let index = sender.text?.endIndex.advancedBy(-4)
sender.text = sender.text?.substringToIndex(index!)
}
}
}
else if sender.text?.characters.count > 10 && self.string != "" {
let index = sender.text?.endIndex.advancedBy(-1)
sender.text = sender.text?.substringToIndex(index!)
}
}
}
and ViewController.swift --
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
#IBOutlet weak var dateInsert: UITextField!
var dateMaker: MakeDate!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
dateMaker = MakeDate(textField: self.dateInsert)
self.dateInsert.delegate = self.dateMaker
self.dateMaker.takeProperDateInput()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
The error i get is unrecognized selector sent to instance
Create a textfield class with the default properties and implement in the view controller not a nsobject to send a textfield as parameter:
class baseTextfield: UITextField, UITextFieldDelegate {
}
class ViewController: UIViewController{
#IBOutlet weak var dateInsert: UIBaseTextField!
}
The properties are of the textfield, not of the view.
Related
I am pretty new with programming but I am currently learning iOS. I have been trying to build a calculator but I have some problems. For instance, when I try to calculate 2 + 2, it shows me 5. Because when I press the second number (in this case 2) it makes it 3.
Can anyone help me to fix and understand the problem?
import UIKit
class ViewController: UIViewController {
var numberOnScreen:Double = 0
var previousNumber:Double = 0
var performingMath = false
var operation = 0
#IBOutlet weak var label: UILabel!
#IBAction func numbers(_ sender: UIButton)
{
if performingMath == true
{
label.text = String(sender.tag)
numberOnScreen = Double(label.text!)!
performingMath = false
}
else
{
label.text = label.text! + String(sender.tag-1)
numberOnScreen = Double(label.text!)!
}
}
#IBAction func buttons(_ sender: UIButton)
{
if label.text != "" && sender.tag != 11 && sender.tag != 16
{
previousNumber = Double(label.text!)!
if sender.tag == 12 {
label.text = "/"
}
else if sender.tag == 13 {
label.text = "*"
}
else if sender.tag == 14 {
label.text = "-"
}
else if sender.tag == 15 {
label.text = "+"
}
operation = sender.tag
performingMath = true
}
else if sender.tag == 16 {
if operation == 12 {
label.text = String(numberOnScreen / previousNumber)
}
else if operation == 13 {
label.text = String(numberOnScreen * previousNumber)
}
else if operation == 14 {
label.text = String(numberOnScreen - previousNumber)
}
else if operation == 15 {
label.text = String(numberOnScreen + previousNumber)
}
}
else if sender.tag == 11 {
label.text = ""
numberOnScreen = 0
previousNumber = 0
operation = 0
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}
I am building an iOS app which requires user to input pin which consists of 4 digits. So, I created 4 TextField separately in order to accept one number for each TextField. It is working fine when user inputs each textfield and move forward from textfield to another textfield smoothly.
But the problem is that I want user be able to delete by clicking on clear button icon that provided by iOS built-in keyboard. When user clicks on that icon button it should let textfield move to previous textfield but it does not work for me.
I have found lots of resources online on stackoverflow and it is still not working for me. That is why I created my own question.
This is how my code looks likes! I created textfield programmatically!
self.coverView.addSubview(self.paymentView.firstDigit)
self.coverView.addSubview(self.paymentView.secondDigit)
self.coverView.addSubview(self.paymentView.thirdDigit)
self.coverView.addSubview(self.paymentView.fourthDigit)
self.view.addSubview(self.overlayView)
self.overlayView.snp.makeConstraints { (make) in
make.top.width.height.centerX.equalTo(self.coverView)
}
self.paymentView.firstDigit.becomeFirstResponder()
self.paymentView.firstDigit.snp.makeConstraints { (make) in
make.top.equalTo(self.coverView)
make.width.height.equalTo(21)
make.leading.equalTo(self.coverView)
}
self.paymentView.secondDigit.snp.makeConstraints { (make) in
make.top.equalTo(self.coverView)
make.leading.equalTo(self.paymentView.firstDigit.snp.trailing).offset(8)
make.width.height.equalTo(21)
}
self.paymentView.thirdDigit.snp.makeConstraints { (make) in
make.top.equalTo(self.coverView)
make.leading.equalTo(self.paymentView.secondDigit.snp.trailing).offset(8)
make.width.height.equalTo(21)
}
self.paymentView.fourthDigit.snp.makeConstraints { (make) in
make.top.equalTo(self.coverView)
make.leading.equalTo(self.paymentView.thirdDigit.snp.trailing).offset(8)
make.width.height.equalTo(21)
}
self.paymentView.firstDigit.delegate = self
self.paymentView.secondDigit.delegate = self
self.paymentView.thirdDigit.delegate = self
self.paymentView.fourthDigit.delegate = self
The code above included delegate of TextField. And below is how I setup target for each TextField
self.paymentView.firstDigit.addTarget(self, action: #selector(textfieldDidChange(textField:)), for: .editingChanged)
self.paymentView.secondDigit.addTarget(self, action: #selector(textfieldDidChange(textField:)), for: .editingChanged)
self.paymentView.thirdDigit.addTarget(self, action: #selector(textfieldDidChange(textField:)), for: .editingChanged)
self.paymentView.fourthDigit.addTarget(self, action: #selector(textfieldDidChange(textField:)), for: .editingChanged)
And below is the function of textfieldDidChange
#objc func textfieldDidChange(textField: UITextField) {
let text = textField.text
print("This is an amount of text ", text?.count)
if text?.count == 1 {
switch textField {
case self.paymentView.firstDigit:
self.paymentView.firstDigit.textColor = BaseColor.colorPrimary
self.paymentView.firstDigit.backgroundColor = BaseColor.colorPrimary
self.paymentView.secondDigit.becomeFirstResponder()
case self.paymentView.secondDigit:
self.paymentView.secondDigit.textColor = BaseColor.colorPrimary
self.paymentView.thirdDigit.becomeFirstResponder()
self.paymentView.secondDigit.backgroundColor = BaseColor.colorPrimary
case self.paymentView.thirdDigit:
self.paymentView.thirdDigit.textColor = BaseColor.colorPrimary
self.paymentView.fourthDigit.becomeFirstResponder()
self.paymentView.thirdDigit.backgroundColor = BaseColor.colorPrimary
case self.paymentView.fourthDigit:
self.paymentView.fourthDigit.textColor = BaseColor.colorPrimary
self.paymentView.fourthDigit.backgroundColor = BaseColor.colorPrimary
self.paymentView.fourthDigit.resignFirstResponder()
self.view.endEditing(true)
default:
break
}
}
if text?.count == 0 {
switch textField {
case self.paymentView.firstDigit:
self.paymentView.firstDigit.becomeFirstResponder()
self.paymentView.firstDigit.backgroundColor = .red
case self.paymentView.secondDigit:
self.paymentView.firstDigit.becomeFirstResponder()
self.paymentView.firstDigit.backgroundColor = .red
case self.paymentView.thirdDigit:
self.paymentView.secondDigit.becomeFirstResponder()
self.paymentView.secondDigit.backgroundColor = .red
case self.paymentView.fourthDigit:
self.paymentView.thirdDigit.becomeFirstResponder()
self.paymentView.thirdDigit.backgroundColor = .red
default:
break
}
}
}
The above is how I tried to make textfield move to previous textfield when clear button of built-in keyboard iOS is clicked but it did not move. And the code above I copied from the source How to move cursor from one text field to another automatically in swift ios programmatically?
I have worked with this just follow these steps and you will get results as per your need:
#IBOutlet weak var txt4: UITextField!
#IBOutlet weak var txt3: UITextField!
#IBOutlet weak var txt2: UITextField!
#IBOutlet weak var txt1: UITextField!
Add textField Delegate in view controller
In viewDidLoad assign delegate:
txt1.delegate = self
txt2.delegate = self
txt3.delegate = self
txt4.delegate = self
Then add this code you will get as you want
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if (textField == txt1) {
txt2.becomeFirstResponder()
}else if (textField == txt2) {
txt3.becomeFirstResponder()
}else if (textField == txt3) {
txt4.becomeFirstResponder()
}else if (textField == txt4) {
//here
var str = self.txt1.text! + self.txt2.text! + self.txt3.text! + self.txt4.text!
str = str.replacingOccurrences(of: " ", with: "")
self.verify(otp: str)
// self.navigationController?.pushViewController(vc, animated: true)
}
return true
}
func textFieldDidBeginEditing(_ textField: UITextField) {
if(textField.text?.count == 0)
{
textField.text = " "
}
}
#objc func setNextResponder(textfield : UITextField)
{
textfield.becomeFirstResponder()
}
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let _char = string.cString(using: .utf8)
// const char * _char = [string cStringUsingEncoding:NSUTF8StringEncoding];
// int isBackSpace = strcmp(_char, "\b");
let isBackSpace = strcmp(_char, "\\b")
if (isBackSpace == -92) {
// NSLog(#"Backspace was pressed");
if (textField == txt4)
{
if(textField.text!.count == 2)
{
}
else{
self.perform(#selector(setNextResponder), with: txt3, afterDelay: 0.01)
txt3.text = " "
}
}
else if (textField == txt3)
{
if(textField.text!.count == 2)
{
}
else{
self.perform(#selector(setNextResponder), with: txt2, afterDelay: 0.01)
txt2.text = " "
}
}
else if (textField == txt2)
{
if(textField.text!.count == 2)
{
}
else{
self.perform(#selector(setNextResponder), with: txt1, afterDelay: 0.01)
txt1.text = " "
}
}
else if (textField == txt1)
{
if(textField.text!.count == 2)
{
}
else{
textField.resignFirstResponder()
}
}
}
if (string.count > 1 && !(Scanner.init(string: string).scanInt(nil)))
{
return false;
}
let oldLength = textField.text!.count
let replacementLength = string.count
let rangeLength = range.length
let newLength = oldLength - rangeLength + replacementLength
// This 'tabs' to next field when entering digits
if (newLength == 2) {
if (textField == txt1)
{
self.perform(#selector(setNextResponder), with: txt2, afterDelay: 0.01)
}
else if (textField == txt2)
{
self.perform(#selector(setNextResponder), with: txt3, afterDelay: 0.01)
}
else if (textField == txt3)
{
self.perform(#selector(setNextResponder), with: txt4, afterDelay: 0.01)
}
else if(textField == txt4)
{
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
// let vc = self.storyboard?.instantiateViewController(withIdentifier: "navVC") as! NavigationViewController
// vc.modalPresentationStyle = .fullScreen
// self.present(vc, animated: true, completion: nil)
var str = self.txt1.text! + self.txt2.text! + self.txt3.text! + self.txt4.text!
str = str.replacingOccurrences(of: " ", with: "")
self.verify(otp: str)
}
}
}
return newLength <= 2;
}
My approach was like this:
import UIKit
class ViewController1: UIViewController, UITextFieldDelegate {
#IBOutlet weak var text1: UITextField!
#IBOutlet weak var text2: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
text1.delegate = self
text2.delegate = self
}
func textFieldShouldClear(_ textField: UITextField) -> Bool {
if textField == text1 {
textField.text = ""
textField.resignFirstResponder()
text2.becomeFirstResponder()
}
return false
}
}
My problem is that I can click and input multiple numbers for my first value but then after I used a math operator (ex. +,-,*,/) it only allows me to input a single value unlike the first time running it.
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var Label: UILabel!
var secondNumber: Double = 0;
var firstNumber: Double = 0;
var performingMath = false
var operatorUsed = 0;
#IBAction func cleartext(_ sender: UIButton) {
Label.text = ""
performingMath = false
}
#IBAction func Numbers(_ sender: UIButton) {
if performingMath {
Label.text = String(sender.tag - 1)
secondNumber = Double(Label.text!)!
performingMath = true
} else {
Label.text = Label.text! + String(sender.tag - 1)
secondNumber = Double(Label.text!)!
}
}
#IBAction func Operators(_ sender: UIButton) {
if Label.text != " " && sender.tag != 11 {
firstNumber = Double(Label.text!)!
if sender.tag == 12 {
Label.text = "+"
} else if sender.tag == 13 {
Label.text = "-"
} else if sender.tag == 14 {
Label.text = "*"
} else if sender.tag == 15 {
Label.text = "/"
}
operatorUsed = sender.tag
performingMath = true
} else if sender.tag == 11 {
if operatorUsed == 12 {
Label.text = String(firstNumber + secondNumber)
}
if operatorUsed == 13 {
Label.text = String(firstNumber - secondNumber)
}
if operatorUsed == 14 {
Label.text = String(firstNumber * secondNumber)
}
if operatorUsed == 15 {
Label.text = String(firstNumber / secondNumber)
}
}
}
}
I expect the that I can input many values as possible after I used a math operator (ex. +-*/)
When you update the label's text when performingMath is true, you just assign the new value instead of adding the value to the existing one (see line 3)
#IBAction func Numbers(_ sender: UIButton) {
if performingMath {
Label.text = String(sender.tag - 1) // !! HERE !!
secondNumber = Double(Label.text!)!
performingMath = true
} else {
Label.text = Label.text! + String(sender.tag - 1)
secondNumber = Double(Label.text!)!
}
}
This should perform the same action as when performingMath is false, so you just need to update this line with:
Label.text = Label.text! + String(sender.tag - 1)
In my calculator app I ran into a problem where I want ... to show in my array but only when the if statement for resultIsPending is true. Then after that I want the ... to be deleted. How can I do this in Swift? Here is the code of my ViewController.swift:
#IBOutlet weak var sequence: UILabel!
#IBOutlet weak var display: UILabel!
var userInTheMiddleOfTyping = false
var resultIsPending:Bool = false
var elements = [String]()
//var sequenceArray:Array = []
#IBAction func clear(_ sender: Any) {
display.text = " "
elements.removeAll()
elements = elements.filter{$0 != "\(String(describing: display.text))"}
sequence.text = elements.joined()
}
override func viewDidLoad() {
}
#IBAction func touchDigit(_ sender: UIButton) {
let digit = sender.currentTitle!
elements.append(digit)
combineToMakeOperationHistory()
if userInTheMiddleOfTyping{
let textCurrentlyInDisplay = display!.text!
display!.text = textCurrentlyInDisplay + digit
} else {
display!.text = digit
userInTheMiddleOfTyping = true
}
}
var displayValue: Double{
get{
return Double(display.text!)!
}
set{
display.text = String(newValue)
}
}
private var brain = CalculatorBrain()
#IBAction func performOperation(_ sender: UIButton) {
let perSender = sender.currentTitle!
elements.append(perSender)
combineToMakeOperationHistory()
if perSender == "+" || perSender == "÷" || perSender == "×" || perSender == "-" || perSender == "^"{
resultIsPending = true
}
if userInTheMiddleOfTyping{
brain.setOperand(displayValue)
userInTheMiddleOfTyping = false
}
userInTheMiddleOfTyping = false
if let mathematicalSymbol = sender.currentTitle{
brain.performOperation(mathematicalSymbol)
}
if brain.result != nil{
displayValue = brain.result!
}
}
func combineToMakeOperationHistory() {
if resultIsPending{ // this is the if statement
elements.append("...")
}else if resultIsPending == false{
}
sequence.text = elements.joined()
}
You can filter your elements array and remove the "...".
elements = elements.filter({ $0 != "..." })
Whenever you want to remove the occurrence of a String value.
you can uses something like hat
var resultIsPending:Bool = false{
didSet(isPending) {
if isPending {
elements.append("...")
} else {
elements.dropLast()
}
}
}
Don't combine data that are not of the same type. There is no reason to put ... into the array of elements:
func combineToMakeOperationHistory() {
var sequenceText: String = elements.joined()
if (resultIsPending) {
sequenceText += "..."
}
sequence.text = sequenceText
}
Since we are not appending ... to the array, we don't have to remove it.
This question already has answers here:
Swift 3 first parameter names
(5 answers)
Closed 6 years ago.
i'm a totally beginner of swift and ios programming
and i met a question by following a coding lesson video which was written by swift 1 and xcode 6 beta.
i know the version of swift had changed ,and the syntax had been changed a lot two.
and i have fix some problems but there is still one that i can't deal with.
That's "missing argument label in call"
the following is my code:
import UIKit
import CoreLocation
class ViewController: UIViewController,CLLocationManagerDelegate {
let locationManger:CLLocationManager = CLLocationManager()
#IBOutlet weak var location: UILabel!
#IBOutlet weak var icon: UIImageView!
#IBOutlet weak var temperature: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
locationManger.delegate = self
locationManger.desiredAccuracy = kCLLocationAccuracyBest
if(ios10()) {
locationManger.requestWhenInUseAuthorization()
}
locationManger.startUpdatingLocation()
}
func ios10() ->Bool {
return UIDevice.current.systemVersion == "10.2"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){
let location:CLLocation = locations[locations.count-1] as CLLocation
if(location.horizontalAccuracy > 0) {
print(location.coordinate.latitude)
print(location.coordinate.longitude)
self.updateWeatherInfo(latitude: location.coordinate.latitude,longitude: location.coordinate.longitude)
locationManger.stopUpdatingLocation()
}
}
func updateWeatherInfo(latitude:CLLocationDegrees,longitude:CLLocationDegrees){
let manager = AFHTTPRequestOperationManager()
let url = "http://api.openweathermap.org/data/2.5/weather?APPID=c5a8f49ee6e86f1aaa2be178f25f37f2"
let params = ["lat":latitude,"lon":longitude,"cnt":0]
manager.get(url,
parameters: params,
success: { (operation:AFHTTPRequestOperation!, responseObject: Any!) in
print("JSON:" + (responseObject as AnyObject).description!)
updateUISuccess(responseObject as! NSDictionary!)
//that's where my error1 :missing argument label 'jsonResult' in call
}
)
}
func updateUISuccess(jsonResult:NSDictionary){
if let tempResult = (jsonResult["main"] as? [String:Double])?["type"] {
//if let tempResult = (jsonResult["main"] as? [String:Double])?["type"] current
//if let tempResult = jsonResult["main"]?["temp"]? as? Double pre
var temperature:Double
if ((jsonResult["sys"] as? [String:String])?["country"] == "US"){
//CONVERT TO FAHRENHEIT IF USER IN US
temperature = round(((temperature - 273.15) * 1.8) + 32)
}
else{
//CONVERT TO CELSIUS
temperature = round(temperature - 273.15)
}
self.temperature.text = "\(temperature)°"
print(temperature)
var name = jsonResult["name"] as! String
self.location.text = "\(name)"
var conditionArray = (jsonResult["weather"] as! NSArray)[0] as! NSDictionary
var condition = conditionArray["id"] as! Int
var sunrise = (jsonResult["sys"] as? [String:Double])?["sunrise"]
var sunset = (jsonResult["sys"] as? [String:Double])?["sunset"]
var nightTime = false
var now = NSDate().timeIntervalSince1970
if (now < sunrise! || now > sunset!) {
nightTime = true
}
//self.icon.image = UIImage(named:"sunny")
updateWeatherIcon(condition,nightTime: nightTime)
//that's where my error2 :missing argument label 'condition:' in call
}
else {
print("error!")
}
}
func updateWeatherIcon(condition: Int,nightTime: Bool){
//thunderstorm
if(condition < 300) {
if nightTime {
self.icon.image = UIImage(named:"tstorm1_night")
}
else {
self.icon.image = UIImage(named:"tstorm1")
}
}
//drizzle
else if (condition < 500) {
}
//rain
else if (condition < 600) {
}
//snow
else if (condition < 700) {
}
//fog
else if (condition < 771) {
if nightTime {
self.icon.image = UIImage(named: "fog_night")
}
else {
self.icon.image = UIImage(named: "fog")
}
}
//tornado
else if (condition < 800) {
self.icon.image = UIImage(named:"tstorm3")
}
//clear
else if (condition == 800) {
if nightTime {
self.icon.image = UIImage(named:"sunny_night")
}
else {
self.icon.image = UIImage(named:"sunny")
}
}
//few clouds
else if (condition < 804) {
if nightTime {
self.icon.image = UIImage(named:"cloudy2_night")
}
else {
self.icon.image = UIImage(named:"cloudy2")
}
}
//overcast
else if (condition == 804) {
self.icon.image = UIImage(named:"overcast")
}
//extreme
else if ((condition >= 900 && condition < 903) || (condition >= 904 && condition < 1000)){
self.icon.image = UIImage(named:"tstorm3")
}
//cold
else if (condition == 903) {
self.icon.image = UIImage(named:"snow5")
}
//hot
else if (condition == 904) {
self.icon.image = UIImage(named:"sunny")
}
//dont know
else {
self.icon.image = UIImage(named:"dono")
}
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error){
print(error)
}
}
i want to know how to fix it
thank you very much!
The error is because your function requires that you name the argument you are passing in. Try changing:
updateUISuccess(responseObject as! NSDictionary!)
To:
updateUISuccess(jsonResult: responseObject as! NSDictionary!)
Alternatively, you can define the function like this to not require the parameter to be named:
func updateUISuccess(_ jsonResult:NSDictionary){
Note the underscore.
Your second error has a similar cause, so change:
updateWeatherIcon(condition,nightTime: nightTime)
to:
updateWeatherIcon(condition: condition, nightTime: nightTime)