Question

In: Computer Science

13. (6 point) when a downcast is necessary what would be the problem if the downcast...

13. (6 point) when a downcast is necessary what would be the problem if the downcast was not done? Use an example in your explanation.

14. (6 point) The following code is from the ColorViews in-class example. what is the purpose of the function ? what the base class for the type the function is found in? How is it called?

override func draw(_ rect: CGRect)

{

// Get the context being draw upon

let context = UIGraphicsGetCurrentContext( )

//Create layer, if necessary

checkDrawLayer (context)

Solutions

Expert Solution

SOLUTION:

Downcasting::--

In general words we can define Upcasting is "Converitng different different memories to common memory."

Downcasting is converting common memory to different different memories.

**********************************************************************************************************************************

import UIKit //here i am importiong all the UI components

let myButton =UIButton()
let mySlider=UISlider()
let myTextField=UITextField()
let myDatePicker=UIDatePicker() // these all are 4 types of Objects inherited from UIContol class

let controls =[myButton,mySlider,myTextField,myDatePicker];


for item in controls{
if item is UIDatePicker{ // WE are checking the type with "is"
   println("we have UIDatePicker")
          
           // downcast with "as"
           // array controls is having different types of objects
           // if you want to use any of the object in array property you must down cast the object to "required object"
          
           let picker = item as UIDatePicker //Downcastiong
           picker.datePickerMode=UIDatePickerMode.CountDownTimer
  
   }

}
Answer to 14th question:

in UIKit we have UIView class in this class we have property .backgroundColor property
if when UIKit displaying the view it checks for the .backgroundColor
and fills the backgroundColor.

when you set the the property from UIColor.green.set() and rect.fill() it wont change the background color of the view


when you override draw(_rect: CGRect) function our code ""draws a filled rectangle""
as UIKit already done the preprocessing of .backgroundColor property.

as you can see the above example the base class is UIView for the draw(_rect: CGRect).


Related Solutions

Question #6 Explain what a business plan is and when one is necessary. Then list five...
Question #6 Explain what a business plan is and when one is necessary. Then list five components that should be included in a business plan, describing the type of information that would be included in each.
when would formation of a derivative be a necessary step in the experiment
when would formation of a derivative be a necessary step in the experiment
1. When measuring the melting point of an unknown, why is it necessary to prepare two...
1. When measuring the melting point of an unknown, why is it necessary to prepare two samples for determination? (Hint: Included in the answer should be the RATE at which the temperature should be allowed to rise when determining an accurate melting point).
Problem 13-6 Various contingencies [LO13-5, 13-6] Eastern Manufacturing is involved with several situations that possibly involve...
Problem 13-6 Various contingencies [LO13-5, 13-6] Eastern Manufacturing is involved with several situations that possibly involve contingencies. Each is described below. Eastern’s fiscal year ends December 31, and the 2018 financial statements are issued on March 15, 2019. Eastern is involved in a lawsuit resulting from a dispute with a supplier. On February 3, 2019, judgment was rendered against Eastern in the amount of $107 million plus interest, a total of $122 million. Eastern plans to appeal the judgment and...
eBook Tannen Industries is considering an expansion. The necessary equipment would be purchased for $13 million...
eBook Tannen Industries is considering an expansion. The necessary equipment would be purchased for $13 million and will be fully depreciated at the time of purchase, and the expansion would require an additional $4 million investment in net operating working capital. The tax rate is 25%. What is the initial investment outlay after bonus depreciation is considered? Write out your answer completely. For example, 13 million should be entered as 13,000,000. Round your answer to the nearest dollar. Enter your...
Problem 13-53 & 13-54 (Algo) (LO 13-4, 5, 6) [The following information applies to the questions...
Problem 13-53 & 13-54 (Algo) (LO 13-4, 5, 6) [The following information applies to the questions displayed below.] Gulf States Manufacturing has the following data from year 1 operations, which are to be used for developing year 2 budget estimates: Sales revenues (18,000 units) $ 1,620,000 Manufacturing costs Materials $ 289,000 Variable cash costs 395,000 Fixed cash costs 159,000 Depreciation (fixed) 195,000 Marketing and administrative costs Marketing (variable, cash) 208,000 Marketing depreciation 51,000 Administrative (fixed, cash) 204,000 Administrative depreciation $...
Problem 13-53 & 13-54 (Algo) (LO 13-4, 5, 6) [The following information applies to the questions...
Problem 13-53 & 13-54 (Algo) (LO 13-4, 5, 6) [The following information applies to the questions displayed below.] Gulf States Manufacturing has the following data from year 1 operations, which are to be used for developing year 2 budget estimates: Sales revenues (18,000 units) $ 1,620,000 Manufacturing costs Materials $ 289,000 Variable cash costs 395,000 Fixed cash costs 159,000 Depreciation (fixed) 195,000 Marketing and administrative costs Marketing (variable, cash) 208,000 Marketing depreciation 51,000 Administrative (fixed, cash) 204,000 Administrative depreciation $...
is my answer correct ? Problem 2-13 Repeat Problem 6 assuming the corporation is an S...
is my answer correct ? Problem 2-13 Repeat Problem 6 assuming the corporation is an S corporation. Corporate Tax Rate 40% Personal Tax Rate 30% Earnings per share $2.00 Remaining after all taxes $0.60
what do you understand by point estimation? when would you say that estimate of a parameter...
what do you understand by point estimation? when would you say that estimate of a parameter is good? also discuss the requirements of consistency unbiasedness of an estimate?
What are the pros and cons of outsourcing? When is it desirable and necessary?
What are the pros and cons of outsourcing? When is it desirable and necessary?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT