iOS App Development
10. (8 point) What are optionals? Why are optionals needed? Why must unwrapping be done? What can go wrong with optional unwrapping?
12. (6 Point)Name a swift / iOS type is a value type. Name a Swift/iOS type that is a reference type. Explain what happens when a value type variable is assigned a new value. Do not mention parameter passing in your answer.
10.
Optionals in Swift are can be having data or no-data
//for the user the input can be optional (he might give data or he can leave it blank)
if we dont use optional then every data input is mandatory
Syntax:
var name: String? or var name : Optional<String>
//above String? , variable name can be of type String or nothing
Unwrapping
Basically feel optionals as a container so until we open the container we dont know what is the data inside the container
to unwrap we use ! at the end of var name
eg : print("My name is \(name!)")
problem with optional is when we assign name=nil
it raises the runtime crash stating nil is unexpected
so,we have to be clear that the optional data is having a valid input
we can use if statements to handle this
eg : if (name != nil) {
print("My name is \(name!)")
}
only when there is data in var name print following statement
we can also use if let statement provided by swift
eg:
if let name: String = name {
print("My name is \(name!)")
}
iOS App Development 10. (8 point) What are optionals? Why are optionals needed? Why must unwrapping...
Using Swift playground and / or the command line for macOS (open Xcode, create a new Xcode project, macOS, command line tool), practice the following exercises: Exercise: Swift Variables Declare 2 variables/constants with some random values and any name of your choice Considering these 2 variables, one as a value of PI and other as a radius of circle, find the area of circle Print the area of circle Declare a string variable explicitly with value “Northeastern”. Declare a string...
Program Overview This brief exercise is designed for you to consider how reference variables behave when you are passing them as arguments by-value. Instructions Name your class References.java. 1. Implement the following methods. 1.1 Method name: readStudentNames Purpose: This method accepts an array of strings as a parameter. It loops through the array and asks the user to input names. It populates the array of strings with the names. Parameters: an array of Strings, stringArray Return type: void In the...
use
intellij idea
main java
wp the professor. Please make sure to only implement what is asked for. You may not add any instance variables to any class, though you may create local variables inside of a method to accomplish its task. No other methods should be created other than the ones listed here. Step 1 Develop the following interface: Interface Name: Queue Interface<T> Access Modifier: public Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Name: dequeue...
1. What is an abstract method and why are they useful? Illustrate your answer using an example of where you might use an abstract method. 2. What is the difference between a static variable and a non-static variable? Given the example of a class representing Dogs, give an example of a variable that may be static and another that may non-static. 3. In Java, when you modify a String as shown in the code below, Java makes a new String...
Mobile Application Development questions Match the component type to the example of that component type. - A. B. C. D. E. F. G. A Tip Calculator - A. B. C. D. E. F. G. Where’s My App, which waits for a text message to be received...
Download BankAccount.java and BankAccountTester.java starting files and drag and drop them into your eclipse project. The BankAccount class declaration in file BankAccount.java is the blueprint of a BankAccount object. Check out the design of a BankAccount class. 1. In BankAccount.java class, all of the method stubs ( methods with a header but empty bodies ) are present to help you get started. Your task is to complete the method bodies. All comments in red in the diagram above indicates what...
Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...
Rules of implementation!: You may NOT modify any of the files except Expression.java in ANY way. You may NOT make ANY modifications to Expression.java EXCEPT: Write in the bodies of the methods you are asked to implement, Add private helper methods as needed (including the recursive evaluate method discussed below.) Note that the java.io.*, java.util.*, and java.util.regex.* import statements at the top of the file allow for using ANY class in java.io, java.util, and java.util.regex without additional specification or qualification....
Question 1 What is the value of x after the following int x = 5; x++; x++; x+=x++; A)14 B)10 C)13 D)15 Question 2 The last line in value returning function (before the }) should contain the word return. True False Question 3 This contains three parts: Void or Data Type the name optional parameter list A)Menu System B)Function Header C)Switch Question 4 What is a variable? A)a pointer B)a place in memory to hold data C)int D)a computer programming...
Need help problem 9-13
C++ Homework please help
WRITE FUNCTION PROTOTYPES for the following functions. The functions are described below on page 2. (Just write the prototypes) When necessary, use the variables declared below in maino. mm 1.) showMenu m2.) getChoice 3.) calcResult m.) showResult 5.) getInfo mm.) showName 7.) calcSquare 8.) ispositive int main { USE THESE VARIABLES, when needed, to write function prototypes (#1 - #8) double num1 = 1.5; double num2 = 2.5; char choice; double result;...