I am a beginner trying to learn Xcode from a book, but its out of date (written for iOS 10, Swift 3).
I shows a template called Tabbed, which is not in the latest version os Xcode.
I found a Tab Bar Controller but that does not set up the views as shown in the book.
I tried creating a standard single view app then added the Tab Bar Controller which added a set of 3 Tabbed view controllers (master + Item 1 & item 2) and reading the book it should have created a Swift file for each of the scenes. But it did not create any. Next you were supposed to create a third scene and link it to the master Tab Bar Controller. This did have the basic View Controller code.
As this does not work exactly as the old version how I produce the correct swift code for the 2 item tab view controllers.
Do I just copy the Class files for the one that I added as the Third view controller and rename them FirstViewController.swift and SecondViewController.swift? I'm worried that the automated creation of files may create back office code and the method I suggest may not work correctly. The book I am using is: Beginners Guide to iOS 10 App Development Using Swift 3 by S Yamacli.
Post
Replies
Boosts
Views
Activity
I am new to programming and am struggling to find a solution to a problem in the exercise I am using to learn Xcode programming. I have even copied the code from the book website I am using.
I can stop the fatal error if I add a question mark or a Exclamation mark to the following line:
self.weightInput.delegate = self
self.heightInput.delegate = self
This is how I alter the lines:
self.weightInput!.delegate = self
self.heightInput!.delegate = self
The code builds in both cases and only produces a Fatal Error when I run the simulator without the unwrapping tags.
With the unwrapping added the simulator runs, but when I enter the data and click on the link nothing appears in the MY BMI text box.
I have not mastered debugging yet so don't know how to discover where the fault lies.
Can anyone help as I can't learn any more Xcode until I can see where my mistakes are.
Here is the full code:
// ViewController.swift
// BMI Calculator
//
// Created by Tony Hudson on 25/03/2021.
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var weightInput: UITextField!
@IBOutlet weak var heightInput: UITextField!
@IBOutlet weak var BMIOutput: UITextField!
@IBOutlet weak var categoryOutput: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.weightInput.delegate = self //added either ! or ? here and don't get fatal error
self.heightInput.delegate = self //added either ! or ? here and don't get fatal error
}
@IBAction func calcBMI(_ sender: AnyObject) {
if let heightStr = heightInput.text {
if heightStr == "" {
return
}
else {
if let weightStr = weightInput.text {
if weightStr == "" {
return
}
else {
if let heightNum = Double(heightStr) {
if let weightNum = Double(weightStr) {
let BMI: Double = (weightNum) / (heightNum * heightNum)
BMIOutput.text = String(BMI)
print(BMI)
switch BMI {
case 1..15:
categoryOutput!.text = "Very severely underweight"
case 15...16:
categoryOutput!.text = "Severely underweight"
case 16..18.5:
categoryOutput!.text = "Underweight"
case 18.5..25:
categoryOutput!.text = "Normal"
case 25..30:
categoryOutput!.text = "Overweight"
case 30..35:
categoryOutput!.text = "Moderately obese"
case 35..40:
categoryOutput!.text = "Severely obese"
case 40..60:
categoryOutput!.text = "Very severely obese"
default:
return
}
} }
}
}
}
}
}
func textFieldShouldReturn(_ textField: UITextField) - Bool {
self.weightInput.resignFirstResponder()
self.heightInput.resignFirstResponder()
return true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I am just started to learn iOS programming using Xcode.
This may seem a stupid question but I can't figure out how to set the screen to show the storyboard on the left and the swift code on the right. I am new to Xcode and am working through an exercise and need the Storyboard scenes and the specific swift file where I need to drag from the scene to the swift file. I have clicked on Assistant and the assistant editor should be set to Automatic LocationViewController.swift. When I click on Assistant with Storyboard selected, it says no Assistant results, if I click on the swift file in the tabs I get 2 copies of the swift file??
I have looked for a tutorial or info on the web but can't find any info on this topic.
Could someone please help?
I am a begginer using Swift.
In the example I am following from the book ' iOS 14 Programming for Beginners', the instructions tell me to create a folder called Location and as sub folders create 2 other folders called Model and View. It then instructs me to right click on Location, new file (Cocoa Touch Class) and name the swift file LocationViewController and create the file.
According to the book, it should contain the following override function:
override func viewDidLoad() {
super.viewDidLoad()
}
Here is the file that is produced when I create the Cocoa Touch Class, where the above override is missing.
l
//
// LocationViewController.swift
// LetsEat2
//
// Created by Tony Hudson on 17/03/2021.
//
import UIKit
class LocationViewController: UICollectionViewCell {
}
As this is generated by Cocoa Touch, I can't see why this is missing?
Can anybody explain why this code is missing?
I am new to Xcode and have found a useful book online called 'Intro to app development with Swift. It is written for Xcode 10 but I have Xcode 12.4.
The instructions do not follow in the new version. In particular I want to add an image in the View Controller but I can't find anything like Image View in the Attributes Inspector. Can someone indicate. where this is so I can move on from the exercise I am doing.
Also Is there an upto date book online that can help me learn Xcode?