Miscellaneous2 Flashcards

1
Q

How is your app notified during a touch interaction when a call comes through?

A

UIKit notifies the app via touchesCancelled(_:with:)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain how UITouch class in UIKit works when a user adds one finger then another?

A

A UITouch object is created for the first finger and delivered to the app via a UIEvent object to the UIView’s touchesBegan, touchesMoved, touchesEnded method calls.

That is repeated for each subsequent touch interaction with a new finger, with multiple touches delivered together inside the UIEvent object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Can you override functions from a Swift extension?

A

No, not permitted. Only permitted to override from a class that inherits from the class you are extending.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the importance of the final keyword for classes and methods?

A

A final class cannot be extended. Final methods cannot be overridden in subclasses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you keep track of multi-finger touches?

A

Override touchesBegan, touchesMoved, touchesEnded, touchesCancelled in the UIView or UIViewController class while tracking the touches in an array of 5 UITouch objects, each indexed by finger.

https://stackoverflow.com/questions/39823914/how-to-track-multiple-touches

var fingers = UITouch?

// SETUP ARRAY IF FINGER NIL
override func touchesBegan(_ touches: Set, with event: UIEvent?) {
    super.touchesBegan(touches, with: event)
    for touch in touches{
        let point = touch.location(in: self.view)
        for (index,finger)  in fingers.enumerated() {
            if finger == nil {
                fingers[index] = touch
                print("finger \(index+1): x=\(point.x) , y=\(point.y)")
                break
            }
        }
    }
}
//TRACK MOVEMENT BY FINGER MATCHING TOUCH ID
override func touchesMoved(_ touches: Set, with event: UIEvent?) {
    super.touchesMoved(touches, with: event)
    for touch in touches {
        let point = touch.location(in: self.view)
        for (index,finger) in fingers.enumerated() {
            if let finger = finger, finger == touch {
                print("finger \(index+1): x=\(point.x) , y=\(point.y)")
                break
            }
        }
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Can touchesBegan, touchesMoved, touchesEnded, touchesCancelled be overridden on UIViews and ViewControllers?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are some ways of restricting touches on a UIView/ViewController?

A

Universally: UIApplication’s beginIgnoringInteractionEvents (bookended by endIgnoringInteractionEvents)

isUserInteractionEnabled
alpha = 0.0 (touches fall thru)
isHidden
isMultipleTouchEnabled

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you convert a point from one coordinate space to another’s?

A

func convert(_ point: CGPoint, to view: UIView?) -> CGPoint

Where point is in the receiver’s coordinate space and view is the view to translate it into

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the four methods that intercept touches on UIView and descendants?

A

touchesBegan, touchesMoved, touchesEnded, touchesCancelled

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is some of the information you can get out of a UITouch?

A

location(in:): gets the location as translated into the coordinate system of the in parameter element.

previousLocation(in:): same as above, but the the position of the element previously in the coordinate system of the in parameter element

preciseLocation/previousPreciseLocation

timeStamp: TimeInterval can kept as a class variable and used to subtract to get time difference between touches.

force: where 1.0 is average touch

tapCount: number of times the finger was tapped for a given touch.

view: the view to which touches are being delivered, if any

// CODE BELOW: GET PREVIOUS LOCATION, CURRENT LOCATION IN SUPERVIEW AND RECALCULATE THE CENTER BASED ON THE CHANGE IN X/Y
override func touchesMoved(_ touches: Set, with event: UIEvent?) {
		let t = touches.first
		let point = self.convert(self.center, to: superview)
	if let location = t?.location(in: self.superview), let oldLocation = t?.previousLocation(in: self.superview){
			let deltaX = location.x - oldLocation.x
			let deltaY = location.y - oldLocation.y
		self. center.x += deltaX
		self. center.y += deltaY

	}

}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What class member of UIView can be set to false to stop more than one finger touches?

A

isMultipleTouchEnabled

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Are Gesture Recognizers part of the UIResponder chain?

A

No, does not participate in responder chain. Touches are delivered to a view and if there are Gesture Recognizers it gets delivered there as well, and to the superview’s Gesture Recognizers, etc. up the chain.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

At a high-level how does Gesture Recognizer determine a gesture?

A

It maintains its own sate as touch events arrive, building up evidence as to what gesture it is, until it decides it has its gesture, where it then sends a single message(e.g., tap) or series of messages(e.g., movement)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are key methods of UIGestureRecognizer?

A

location(ofTouch:in) - in, is the view whose coordinate system you want to use

isEnabled: turn on/off

state: progression of modes the GR goes through as it starts, recognizes the gesture, updates changes, and ends. (.possible, .failed, .ended, .began, .changed)
view: view where the GR is attached

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

List the set of UIGestureRecognizers

A
UITapGestureRecognizer
UIPinchGestureRecognizer
UIRotationGestureRecognizer
UISwipeGestureRecognizer
UIPanGestureRecognizer
UIScreenEdgePanGestureRecognizer
UILongPressGestureRecognizer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

List the states of a UIGestureRecognizer

A
.possible
.failed
.ended
.began
.changed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What do the states of a UIGestureRecognizer mean and at a high-level list out what they do?

A

UIGestureRecognizers stay in a particular state until a decision is made. State becomes .possible -> .began -> .changed -> .ended for a drag where .changed is called repeatedly. A tap might go .possible->.ended where the gesture is recognized or .possible->.failed where its the wrong gesture.

Action messages are sent to selectors once for .began, as many times as necessary for .changed, and once for .cancelled/.ended.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What methodology do you use to prevent conflicts between UIGestureRecognizers?

A

require(toFail:UIGestureRecognizer)

Make the UIGestureRecognizers dependent on each other using require to have one fail before the other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What kind of conflicts can arise between UIGestureRecognizers?

A

A double tap and a single tap on the same UIView

UIControl in a superclass view (think root window view with UIButton in it and a GR on the view to detect background taps) - If the user taps button the GR will also fire.

Solve this issue with require(toFail:) on the GR

Solve this issue by subclassing UIView and overriding gestureReognizerShouldBegin - this can then return false so the UIView(or Button, or other control) for the type of gesture recognizer, like a SingleTapGR vs others which could return true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

If you subclassed UIView and implemented touchesBegan, touchesMoved, touchesEnded, etc (where touches moved repositions the UIView)

Then, also put a UIPanGestureRecognizer on the UIView inside the UIViewController it’s instantiated in, that only prints to output.

What happens?

A

UIGestureRecognizers supplant overriding touchesBegan, touchesMoved, etc. but not until the Gesture is recognized.

SO.

Initially, touchesMoved is called until the Gesture is recognized as a Pan by the GR which then takes over. So, the dragging would work until the PanGR takes over, in which case the movement stops and only prints to output.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Difference between isKind(of aClass: AnyClass) and isMember(of aClass: AnyClass)

A

isKind will return true if the caller is an instance or a subclass of that parameter class. isMember returns true if it is an instance NOT a subclass.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Describe the sequence of events when hitTest method is called by UIView?

A

hitTest(_ point:CGPoint? with UIEvent?) takes a point in and first calls the same method on its own subviews. The subviews are queried front-to-back order so the one in front reports the hit first.

If a subview returns a view, hitTest immediately returns that view.

If no subviews or all return nil (meaning neither they nor their subview have been hit) then the UIView calls point(inside:with) on itself. If hit was inside itself, the UIView returns self, otherwise nil

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

If you have two UIViews on superview but want to monitor hit testing at the superview level. You place a UITapGestureRecognizer on the superview and make the UIViews subviews by adding them.

What do you do to distinguish which UIView was tapped?

A

In the action method of the UITapGestureRecognizer, perform a hit test to return the touched view. Then test if that view is an instance of one or the other UIViews.

let p = tapgr.location(ofTouch:0, in tapgr.view)
let v = tapgr.view.hitTest(p, with: nil)
// now we've got the view that was touched, test which one
if let v = v as UIView && v === self.myTargetedView{
....
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What method can you call on a GestureRecognizer that will give you the Point of the touch that occurred?

A

location(ofTouch:, in UIView)

ofTouch is the Index of the touch event

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Can you call hitTest on CALayers?

A

Normally CALayer do not receive touches. Yet you can still detect touches by calling hitTest on the layer with a point in the super layer coordinates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Describe what UIViewControllers are responsible for and their purpose?

A

Logic of what views are shown, what data those views display, response to user gestures, View and Controller in the MVC design pattern,

Manages the interface and presents UIViews

Animation of the interface

Save and restore state

Root View: the UIVC that sits on top of the UIView hierarchy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What retains the root UIViewController?

A

UIWindow

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What retains an embedded UIViewController?

A

Parent UIViewController

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Is it safe to perform dimension dependant calculations from the viewDidLoad method?

A

No, self.view dimensions may not have been set from this function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What is the UIViewController’s loadView method for?

A

Loading the initial view of that UIViewController! (self.view). If you don’t override it, a generic view is assigned to self.view by the default implementation of loadView

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

How do you use a nib file to load a UIViewController?

A

Create the nib (file->new file->iOS->user interface -> view. Then instantiate the VC with the name of that nib file:

let theVC = MyRootViewController.init(nibName:"mynib", bundle: nil)
self.window.rootViewController = theVC
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What are some of the methods that are called when a UIViewController receives events that the main view is being resized?

A

viewWillTransition(to:with:TransitionCoordinator): sent when main view’s size will change (rotation, user widens window on iPad)

willTransition(to:with:TransitionCoordinator): sent when trait Collection is about to change (could be rotation or other things like dynamic text size change)

traitCollectionDidChange(_:): sent after trait collection changes, when trait collection is set for the first time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What is the TransitionCoordinator parameter of viewWillTransition/willTransition?

A

Use the coordinator to hook into the transition animation and perform setup/teardown and add a completion. I.e., change constraints for rotation change.

coordinator.animate(alongsideTransition: { _ in

    }) { [unowned self] _ in

        self.postsCollectionView.reloadData()
        self.postsCollectionView.collectionViewLayout.invalidateLayout()
        DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
            // Trigger layoutSubViews call when orientation changes

            UIView.animate(withDuration: 0.5) {
                 self.postsCollectionView.alpha = 1.0
            }

        }

    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What’s the most reliable way to detect size changes (e.g., rotation)?

A

viewWillLayoutSubviews/viewDidLayoutSubviews: there are some situations where view can be resized without a size change being notified but you’ll ALWAYS get layout events, the viewWillLayoutSubviews and viewDidLayoutSubviews methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What’s the updateViewConstraints method?

A

UIViewController method (that can be overridden) that the view receives when it’s told to update its constraints.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

On size change like rotation what are the order of methods related to the change that is called?

A
willTransition(to:with)  //the trait collection
viewWillTransition(to:with) //the size
updateViewConstraints
traitCollectionDidChange(_:)
viewWillLayoutSubviews
viewDidLayoutSubviews

It’s possible that some of these events are sent more than once so take care to do nothing if nothing is changed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

How do you check the orientation of the device?

A

UIApplication.shared.statusBarOrientation
OR
UIApplication.shared.windows.first?.windowScene!.interfaceOrientation if > iOS 13

check landscapeLeft/landscapeRight/portrait/portraitUpsideDown of the orientation object

if #available(iOS 13, *) {
orientation = (UIApplication.shared.windows.first?.windowScene!.interfaceOrientation)!
} else {
orientation = UIApplication.shared.statusBarOrientation;
}

if orientation == UIInterfaceOrientation.portraitUpsideDown || orientation == UIInterfaceOrientation.portrait{

}else if orientation == UIInterfaceOrientation.landscapeLeft || orientation == UIInterfaceOrientation.landscapeRight {

38
Q

How can you test for the iOS version?

A

if #available(iOS 13, *){ ….}

39
Q

What are three ways to lock an application into a particular orientation?

A

In the info.plist: UISupportedInterfaceOrientations

AppDelegate: implement the application(_:supportedInterfaceOrientationsFor:), returning a bit mask indicating the permitted orientations. This overrides info.plist.

Top-level VC may override the supportedInterfaceOrientations property returning a bit mask listing the set of allowed orientations

Be careful: mixing these, using info.plist then overriding in root VC will result in strange behavior.

The bit mask values are:
.landscapeLeft
.landscapeRight
.portrait
.portraitUpsideDown
.all
.allButUpsideDown
40
Q

Should you create a UIView inside viewWillLayoutSubviews?

A

No, viewWillLayoutSubviews is fine for positioning items, adding or taking away constraints, but not for creating because it gets called repeatedly throughout the lifetime of an app.

41
Q

Create a UITabBarController manually with two child UIViewControllers, one red, one green background.

A

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

		self.window = self.window ?? UIWindow()
		let tabBarController = UITabBarController.init()
		let vc1 = UIViewController.init()
		let vc2 = UIViewController.init()
	vc1.view.backgroundColor = UIColor.green
	vc2.view.backgroundColor = UIColor.red
	vc1.title = "Green"
	vc2.title = "Red"
	tabBarController.viewControllers = [vc1,vc2]

	self. window?.rootViewController = tabBarController
	self. window?.makeKeyAndVisible()

	return true
}
42
Q

What are the two key methods to show and hide a ViewController?

A

present(_:animated:completion)

dismiss(animated:completion)

43
Q

What are the steps of Test Driven Development Cycle?

A

Focus on writing only code necessary to pass tests.

1) Add a test
2) Run the tests and make sure it fails
3) Write the code that makes the test pass
4) Run tests
5) Refactor code
6) Repeat

44
Q

What does the test creation step entail in TDD?

A
  • Each new feature begins with a test.
  • Write a test that defines the function, it should be very succinct.
  • To write the test the developer must clearly understand the feature’s spec and requirements.
  • use cases and user stories can cover the requirements)
45
Q

What are the advantages of writing tests first?

A
  • Helps ensure the app is written for testability. Developers think about testing from the beginning rather than retrofitting it into a design.
  • Writing tests first helps understand the requirements.
  • Ensures effectiveness of test code.
  • Maintains continual focus on software quality.
46
Q

What does “red, green, refactor” mean?

A

First tests fail(red), then pass (green), then refactoring to eliminate redundancies and duplication.

47
Q

List some important HTTP codes

A

200 OK — This is most commonly used HTTP code to show that the operation performed is successful.
201 CREATED — This can be used when you use POST method to create a new resource.
202 ACCEPTED — This can be used to acknowledge the request sent to the server.
400 BAD REQUEST — This can be used when client side input validation fails.
401 UNAUTHORIZED / 403 FORBIDDEN— This can be used if the user or the system is not authorised to perform certain operation.
404 NOT FOUND— This can be used if you are looking for certain resource and it is not available in the system.
500 INTERNAL SERVER ERROR — This should never be thrown explicitly but might occur if the system fails.
502 BAD GATEWAY — This can be used if server received an invalid response from the upstream server.

48
Q

What is the unauthorized HTTP code

A

401

49
Q

What is the Created HTTP code

A

201

50
Q

What is the accepted HTTP code

A

202

51
Q

What is the bad request HTTP Code

A

400

52
Q

what is the Forbidden HTTP code

A

403

53
Q

What is the Not Found HTTP code

A

404

54
Q

What is the internal server error code

A

500

55
Q

What is the bad gateway code

A

502

56
Q

What are some design guidelines for creating REST APIs?

A

Simplicity and ease of use

  • focus on URIs and payloads (internal domain model is not as important0
  • Explorable on standard web browser

Consistency

Flexibility

57
Q

What are the four HTTP methods?

A

GET — To get a resource or collection of resources.

POST — To create a resource or collection of resources.(can be used and not create a resource)

PUT/PATCH — To update the existing resource or collection of resources.(either creates or replaces an existing resource)

DELETE — To delete the existing resource or the collection of resources.

58
Q

What’s the GET HTTP Method?

A

Returns (GETs) a resource or collection of resources

59
Q

What’s the POST HTTP method?

A

Creates a resource or collection of resources. (can be used and not create a resource)

60
Q

What’s the PUT HTTP method?

A

Updates existing resource or collection of resources (either creates or replaces an existing resource)

61
Q

What’s the DELETE HTTP method?

A

Deletes an existing resource or collection of resources.

62
Q

When designing an API what’s the primary decision that needs to be made?

A

Separate API into logical resources (nouns: sounds, cars, payments, articles, etc)

Figure out the data set: what set of data / which concepts do you want to expose/manipulate through the API?

63
Q

What should be used as resource names for an API?

A

USE NOUNS

Good examples
/employees
/cars
/payments
/bills
Bad examples:
/addEmployee
/buyCar
/sendPayment
/createBill
64
Q

Elaborate on what the difference is between POST and GET?

A

The GET request response body contains a representation of the fetched resource.

The POST request body contains a representation of the resource to create.

65
Q

Where is the JSON type set in a header of a POST request?

A

Content-Type: application/json; charset=utf-8

66
Q

Show what a POST request to update an existing resource would look like?

A

POST https://adventure-works.com/orders HTTP/1.1
Content-Type: application/json; charset=utf-8
Content-Length: 57

{“Id”:1,”Name”:”Gizmo”,”Category”:”Widgets”,”Price”:1.99}

67
Q

How should a GET request be configured in order to receive JSON?

A

Accept Header should be set to application/json

GET https://adventure-works.com/orders/2 HTTP/1.1
Accept: application/json

68
Q

If a POST method creates a new resource successfully what HTTP status code is returned?

A

201 (Created)

69
Q

Whats a PATCH HTTP request

A

Updates a resource partially. The sent JSON has a subset of fields to change. E.g.

Original resource:
{
    "name":"gizmo",
    "category":"widgets",
    "color":"blue",
    "price":10
} 
PATCH Merge patch (subset of original):
{
    "price":12,
    "color":null,
    "size":"small"
}
70
Q

If a POST, PUT, PATCH or DELETE is long running what should the server return to the client?

A

202 (Accepted) to indicate the request is processing but not complete.

71
Q

How to support versioning in API design?

A

add version in URL: /v1/tickets

72
Q

What is resource nesting when designing a REST API?

A

The URI will demonstrate the hierarchy between resource objects.

/users

73
Q

How to handle Errors when designing an API

A

Use the Standard HTTP error codes and change the message parameter in the response body JSON.

{
“status”: 400,
“message”: “No to number is specified”,
“code”: 21201,
“more-info”: “http://www.twilio.com/docs/errors”
}

74
Q

What are three important functions a REST API can perform?

A

Filtering, Sorting Paging

75
Q

Give an example of filtering a REST API

A

Filtering:
GET /users?country=USA
GET /users?creation_date=2019-11-11

76
Q

Give an example of sorting a REST API

A

GET /users?sort=birthdate_date:asc

GET /users?sort=birthdate_date:desc

77
Q

Give an example of Paging an REST API

A

GET /users?limit=100

GET /users?offset=2

78
Q

What are some important parts of API Documentation?

A
  • provide information about the available endpoints and methods
  • request/response examples
  • possible response codes
  • information about the authorization
  • available limits or throttling.

Publishing the documentation in the form of a browsable web page with interactive options, curl examples, maybe even a playground is a good idea.

79
Q

Swagger: can define Open API Specification throughSwaggerHUB. What are key objects in the YAML of OAS?

A

Info (license, contact, terms, description)

Servers: url, description

Paths: define the REST URLs…..HTTP method, define parameters (type, min/max values, etc), responses(for each HTTP code), description, content, define return JSON(array, properties, etc)

80
Q

What are CodingKeys used for in the Codable protocol?

A

CodingKey is a protocol used in an enumeration of the string values of keys in the JSON to parse. The string used is the key name used during encoding and decoding.

struct Landmark: Codable {
    var name: String
    var foundingYear: Int
    var location: Coordinate
    var vantagePoints: [Coordinate]
enum CodingKeys: String, CodingKey {
    case name = "title"
    case foundingYear = "founding_date"

    case location
    case vantagePoints
} }
81
Q

If you dont need bidirectional encoding/decoding support what should you do?

A

Conform the class to either Encodable or Decodable INSTEAD of Codable.

82
Q

Describe the steps to give default values to incoming JSON

A

1) Construct a struct representing the JSON
2) Conform to the Codable (or just Encodable/Decodable)
3) Apply Coding keys as an enum to assign keys for each value (recursive if required)
4) implement the init(from decoder:Decoder) throws initializer.

struct VideoId:Codable{
var kind:String
var videoId:String
var channelId:String

			enum CodingKeys: String, CodingKey{
				case kind = "kind"
				case videoId = "videoId"
				case channelId = "channelId"
			}
			init(from decoder: Decoder) throws {
				let decoded_video = try decoder.container(keyedBy: CodingKeys.self)
			kind = try decoded_video.decodeIfPresent(String.self, forKey: .kind) ?? "None"
			videoId = try decoded_video.decodeIfPresent(String.self, forKey: .videoId) ?? "None"
			channelId =  try decoded_video.decodeIfPresent(String.self, forKey: .channelId) ?? "None"

		}
	}
83
Q

Make a basic HTTP request to a url to download a file

A
let s = "https://url"
let url = URL(string:s)!
let session = URLSession.shared
let task = session.downloadTask(with:url){fileURL, resp, err in
	if let url = fileURL, let d = try? Data(contentsOf:url){
		let im = UIImage(data:d)
		DispatchQueue.main.async{
			self.iv.image = im
		}
	}
}

task.resume()

84
Q

When adding embedded ViewControllers what are the methods that always need to be called?

A

willMove and didMove

Add a Child to a ViewController:

  • addChild(childVC) with the child as argument (child is added to children array and retained)
  • self.view.addSubview()
  • didMove(toParent:self) to child ViewController

willMove is sent by addChild automatically

85
Q

When removing embedded ViewControllers what are the methods that need to be sent?

A

willMove and didMove

  • willMove(toParent:)
  • childVVC.view.removeFromSuperview()
  • child.removeFromParent()
  • removeFromParent

removeFromParent sends didMove automatically

86
Q

What’s the method call to make that removes a VC from its owner?

A

child.removeFromParent()

87
Q

How do you tell if a UIView is on the screen?

A

if viewToCheck.window != nil{
print(“ON THE SCREEN:)
}

You can determine whether the view is onscreen, by checking its window property. If that property contains a valid window, it is part of an active view hierarchy. If that property is nil, the view is not part of a valid view hierarchy.

88
Q

How can a UIView selectively become firstResponder?

A

viewToBecomeFirst.becomeFirstResponder()

89
Q

How do you encrypt files on iOS?

A

Use Data Protection API for NSFileManager, CoreData, NSData, and SQLite.

90
Q

How are secure hashes done on iOS

A

Using CryptoKit (SHA512.hash())