Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Swift programming Questions and answers Swift programming Questions and answers, Exams of Nursing

Swift programming Questions and answers Swift programming Questions and answers

Typology: Exams

2023/2024

Available from 03/25/2024

Julietangugi
Julietangugi 🇬🇧

267 documents

1 / 29

Toggle sidebar

Related documents


Partial preview of the text

Download Swift programming Questions and answers Swift programming Questions and answers and more Exams Nursing in PDF only on Docsity! Swift programming Questions and answers Type safety - CORRECT ANSWERS✅ - the property that an object can be accessed only according to its type. - allows you to be clear about the types of values your code can work with i.e. if part of your code expects you to pass a *String*, this characteristic will prevent you from passing it an *Int* by mistake Type inference - CORRECT ANSWERS✅ refers to the automatic deduction of the type of an expression power knowledge: - helps make Swift code more concise and readable Booleans - CORRECT ANSWERS✅ True or false values *Bool* Optional - CORRECT ANSWERS✅ - Handles the absence of a value. Swift programming Questions and answers - They say either "there is a value, and it equals *x*" or "there isn't a value at all" - Let you indicate the absence of a value for any type at all, without the need for special constants. Range operators - CORRECT ANSWERS✅ Strings are value types - CORRECT ANSWERS✅ String interpolation - CORRECT ANSWERS✅ Mutability of collections - CORRECT ANSWERS✅ Arrays - CORRECT ANSWERS✅ stores multiple values of the same type in an ordered list. For-in - CORRECT ANSWERS✅ Swift programming Questions and answers introspection - CORRECT ANSWERS✅ String vs NSString - CORRECT ANSWERS✅ Array vs. NSArray - CORRECT ANSWERS✅ Dictionary vs. NSDictionary - CORRECT ANSWERS✅ Property List - CORRECT ANSWERS✅ NSUserDefault - CORRECT ANSWERS✅ first-class types - CORRECT ANSWERS✅ What should start with capital letters? - CORRECT ANSWERS✅ Types control flow: switch - CORRECT ANSWERS✅ - exhaustive Swift programming Questions and answers - default: used when inappropriate to provide a case for every member example of enum - CORRECT ANSWERS✅ Write in code: Define an enumeration type called Barcode, which can take either a value of UPCA with an associated value of type (Int, Int, Int, Int), or a value of QRCode with an associated value of type String. - CORRECT ANSWERS✅ Associated values - CORRECT ANSWERS✅ Raw values - CORRECT ANSWERS✅ mutable or immutable? : let - CORRECT ANSWERS✅ immutable mutable or immutable? : var - CORRECT ANSWERS✅ mutable when you access a dictionary using a key, what kind of type is returned? - CORRECT ANSWERS✅ optional Swift programming Questions and answers Property observers - CORRECT ANSWERS✅ willSet & didSet Lazy Initialization - CORRECT ANSWERS✅ A property that does not get initialized until someone accesses it syntax: *lazy* When is an *init* method needed? - CORRECT ANSWERS✅ because: - properties can have their defaults set using *=* - or properties might be *Optionals*, in which case they start out as *nil* - or use *lazy* instantiation So, only use this method when a value can't be set in any of these ways. What can you do inside an *init*? - CORRECT ANSWERS✅ - you can set any property's value, even those with default values Swift programming Questions and answers expert level: - you can use this to return multiple values from a function as a single compound value constant vs. variables - CORRECT ANSWERS✅ If a stored value is not going to change, always declare it as a constant. Use variables only for storing values that need to be able to change. type annotation - CORRECT ANSWERS✅ - specifies the type of values the constant or variable can store - Write it by placing a colon (:) after the constant/variable name, followed by a space, followed by the name of the type to use - colon means "...of type..." Swift programming Questions and answers "Declare a variable called welcomeMessage that is *of type* String." declaring multiple constants/variables on a single line, separated by commas - CORRECT ANSWERS✅ defining multiple related variables of the same type on a single line, separated by commas: - CORRECT ANSWERS✅ *type annotation*: practical use - CORRECT ANSWERS✅ - it's rare because you usually provide an initial value, which Swift then applies type inference to determine the type. - only used when an initial value is not used compile-time error: languageName cannot be changed - CORRECT ANSWERS✅ What type of error is this? Why? *println*, *print* - CORRECT ANSWERS✅ global functions that print a value. Swift programming Questions and answers One is followed by a line break while the other isn't. string interpolation - CORRECT ANSWERS✅ is the process of evaluating a string literal containing one or more placeholders, which are replaced with their corresponding values e.g. *println*("Today's date is \(placeholder). This is a string literal") nested multiline comments - CORRECT ANSWERS✅ allows you to comment out large blocks of code quickly and easily, even if the code already has multiline comments /* code code code/*comment comment*/code code */ double - CORRECT ANSWERS✅ - 64-bit floating-point number - precision of at least 15 decimal places Swift programming Questions and answers Keyword: *import* - CORRECT ANSWERS✅ Keyword: *init* - CORRECT ANSWERS✅ Keyword: *internal* - CORRECT ANSWERS✅ Keyword: *let* - CORRECT ANSWERS✅ tells compiler that what follows is a constant value Keyword: *operator* - CORRECT ANSWERS✅ Keyword: *private* - CORRECT ANSWERS✅ Keyword: *protocol* - CORRECT ANSWERS✅ Keyword: *public* - CORRECT ANSWERS✅ Keyword: *static* - CORRECT ANSWERS✅ Swift programming Questions and answers Keyword: *struct* - CORRECT ANSWERS✅ Keyword: *subscript* - CORRECT ANSWERS✅ Keyword: *typealias* - CORRECT ANSWERS✅ Keyword: *var* - CORRECT ANSWERS✅ tells compiler that what follows is a variable value break - CORRECT ANSWERS✅ statement that ends execution of an entire control flow statement immediately (loop or switch) case - CORRECT ANSWERS✅ continue - CORRECT ANSWERS✅ tells a loop to stop what its doing and start the next iteration through the loop power wits: Swift programming Questions and answers in a *for* loop with a condition and incrementer, the incrementer is still evaluated after evaluating this type of statement default - CORRECT ANSWERS✅ do - CORRECT ANSWERS✅ else - CORRECT ANSWERS✅ *fallthrough* - CORRECT ANSWERS✅ in switch statements, it causes code execution to move directly to the statements inside the next case block. for - CORRECT ANSWERS✅ if - CORRECT ANSWERS✅ in - CORRECT ANSWERS✅ return - CORRECT ANSWERS✅ Swift programming Questions and answers Protocol - CORRECT ANSWERS✅ required - CORRECT ANSWERS✅ right - CORRECT ANSWERS✅ set - CORRECT ANSWERS✅ Type - CORRECT ANSWERS✅ unowned - CORRECT ANSWERS✅ weak - CORRECT ANSWERS✅ willSet - CORRECT ANSWERS✅ Swift programming Questions and answers Swift's array and dictionary types are implemented as *generic collections*. What does that mean? - CORRECT ANSWERS✅ a generic collection allows you to have a collection of values of any type. i.e. An array of integers, Array<Int>, or an array of strings, Array<String>. - CORRECT ANSWERS✅ associativity - CORRECT ANSWERS✅ In Swift, there are two kinds of types: - CORRECT ANSWERS✅ *Named type*- can be given a particular name when it's defined. *Compound type*- e.g. (Int, (Int, Int)) Compound type - CORRECT ANSWERS✅ a type without a name e.g. (Int, (Int, Int)) What are the two compound types? - CORRECT ANSWERS✅ Function types & tuple types Swift programming Questions and answers syntactic sugar - CORRECT ANSWERS✅ syntax used to make things easier to read or express Inheritance - CORRECT ANSWERS✅ - when a class inherits methods, properties, and other characteristics from another class - power knowledge: this behavior differentiates classes from other types in Swift. subclass - CORRECT ANSWERS✅ the class that inherits superclass - CORRECT ANSWERS✅ the class that is inherited from base class - CORRECT ANSWERS✅ any class that does not inherit from another class What is important to know about *String* type? - CORRECT ANSWERS✅ Swift's *String* type is a *value type*, which means that the string value is copied when it's passed to a function or method, or when it's assigned to a constant or variable. Swift programming Questions and answers - return what makes up a function's type? - CORRECT ANSWERS✅ its parameter types and return type What does knowing the function type of a function allow you to do? - CORRECT ANSWERS✅ - pass functions as parameters to other functions - return functions from other functions What is one thing you can always try to do with the function's body? - CORRECT ANSWERS✅ simplify it when using a function type as a parameter for another function, what's important? - CORRECT ANSWERS✅ that the function is of correct type Are input parameters and return return types necessary in a function's signature? - CORRECT ANSWERS✅ no, you can define a function without input parameters or return types Swift programming Questions and answers Closure expression syntax - CORRECT ANSWERS✅ The parameters, return type and body are all written inside the curly braces. *in* begins the body How do you access properties of a class/structure instance? - CORRECT ANSWERS✅ dot syntax: you write the property name immediately after the instance name, separated by a period (.), without any spaces How do you assign a new value to a variable property of a class? - CORRECT ANSWERS✅ dot syntax value types - CORRECT ANSWERS✅ a type whose value is copied when it is assigned to a variable or constant, or when it is passed to a function What kind of type has their value copied when it is assigned to a variable or constant, or when it is passed to a function? - CORRECT ANSWERS✅ value type Swift programming Questions and answers Classes have additional capabilities that structures do not: - CORRECT ANSWERS✅ - inheritance - type casting - deinitializers (enable an instance of a class to free up resources assigned - reference counting (allows more than one reference to a class instance.) How do classes get passed vs structures? - CORRECT ANSWERS✅ class instances are always passed by reference structure instances are always passed by value What do properties do? - CORRECT ANSWERS✅ associate values with a particular class, struct, or enumeration. What is the difference between stored properties and computed properties? - CORRECT ANSWERS✅ stored properties store constant & variable values as part of an instance - computed properties calculate (rather than store) a value.
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved