0% found this document useful (0 votes)
39 views

Untitled Document

1. Error handling in Swift involves methods declaring that they "throw errors" with the "throws" keyword, to indicate they may throw errors. 2. The Any and AnyObject types can hold values of any type, but AnyObject only holds class types. These types are generally used for interfacing with Objective-C code and it is better to avoid them in Swift code. 3. Key classes discussed include NSObject as the base class for Objective-C classes, NSNumber for storing numeric values, Date for working with dates/times, and Data for saving/transmitting raw data.

Uploaded by

api-372726260
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Untitled Document

1. Error handling in Swift involves methods declaring that they "throw errors" with the "throws" keyword, to indicate they may throw errors. 2. The Any and AnyObject types can hold values of any type, but AnyObject only holds class types. These types are generally used for interfacing with Objective-C code and it is better to avoid them in Swift code. 3. Key classes discussed include NSObject as the base class for Objective-C classes, NSNumber for storing numeric values, Date for working with dates/times, and Data for saving/transmitting raw data.

Uploaded by

api-372726260
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

-Topic Notes

-Misc
-Error Handling
-Thrown Errors
-Methods can throw errors in swift
-The way to know if that methods have the ability to throw errors if
they have the word ‘throws’ at the end of the method.
-Any
-Another topic covered was portions of Any and AnyObject
-These types are normally used for using code with old Objective-C API.
This isn’t super relevant and commonly used now because lots of Objective-C API has been
updated.
-Variables of type “Any” can hold something of any type where AnyObject
holds classes only.
-For good practice in Swift, try to avoid using Any and anyObject.
-We have already seen ’any’ a little when we used
‘NSAttributedStringKey’ where ‘any’ was used as the type of the values in the attributes
Dictionary.
-Since any is mainly used in old Objective C code, we would probably use
enums with protocols attached to it.
-The main lesson is to not use ‘Any’ in this coursework with projects but it
is ok to call an API that uses it.
-Other Interesting Classes
-NSObject
-Base class for all Objective-C Classes.
-Some advanced features with require you to call a subclass from
NSObject.
-NSNumber
-NSNumber is the generic number-holding class.
-Date
-Value type used to find out the date and time in a instance and to
store dates.
-Useful classes
-Calendar
-DateFormatter
-DateComponents
-Data
-Class Data is used to save, restore, transmit raw data through the
software development kit.
-Views
-A view represents a rectangular area
-defines coordinate space
-for drawing
-handling touch events
-Hierarchical
-a view only has one superview
-it can have many subviews
-order in subview array is important
-UIWindow
-at the very top of the view hierarchy
-normally only one UIWindow in an entire iOS application.
-Where does view hierarchy start?
-The top of the (useable) view hierarchy is the Controller’s var view:
UIView.
-This simple property is a very important thing to understand!
-This view is the one whose bounds will change on rotation, for example.
-This view is likely the one you will programmatically add subviews to (if
you ever do that).
-All of your MVC’s View’s UIViews will have this view as an ancestor.
-It’s automatically hooked up for you when you create an MVC in Xcode.
-Initializing UIView
-Always try to avoid an initializer if possible
-a UIView’s initializer is different if it comes out of a storyboard
-if you need an initializer, implement them both
-Coordinate System Data Structures
-CGFloat
-use this instead of double or float for anything to do with UIView’s coordinate
system.
-CGPoint
-Simply a struct with two CGFloats: an x and y
-CGSize
-a struct with two CGFloats: width and height
-CGRect
-a struct with a CGPoint and a CGSize in it
-View Coordinate System
-Origin is in the upper left
-units are in points, not pixels
-pixels are the minimum-sized unit of drawing your device is capable of
-points are the units in the coordinate system
-most of the time there is 2 pixels per point
-bounds vs frame
-use frame or center to position a UIView
-Creating Views
-most often you create your views by using the storyboard
-you occasionally create it with code
-Custom Views
-When To Create UIView Subclass
-when you want to do custom drawing on screen
-handling touch events in particular way
-NEVER CALL draw(cgRect)
-Custom Views
-Core Graphics Concepts
-you get a context to draw into
-create paths (out of lines, arcs, etc)
-set drawing attributes like colors fonts, textures linewidths, linecaps
-Defining a Path
-Create a UIBezierPath
-Move around, add lines or arcs to path
-close the path (if you want, not always necessary)
-set attributes and use stroke or fill
-Drawing
-You can also draw common shapes with UIBezierPath
-clipping your drawing to a UIBezierPath
-Hit detection
-UIColor
-Colors are set using UIColor
-Background color of a UIView
-Colors can have alpha
-Layers
-Underneath UIView is a drawing mechanism called CALayer
-there is some useful API in CALayer that I should do some side
research on
-View Transparency
-What happens when views overlap and have transparency
-subviews list order determines who is in front
-completely hide a view without removing it is used with “isHidden”

You might also like