How to erase a rewritable CD or DVD in OS X

Its rather simple actually.
Insert the CD or DVD into the SuperDrive
You should see an icon appear on the desktop like when you mount any other drive.
Simply right click on the icon and choose erase.
 

NOTE: I’ve had OS X not recognise a DVD and only give me the Ignore and Eject options. If I choose the Ignore option I don’t get an icon to be able to do the steps above. I haven’t worked out what to do there yet. Possibly something with diskutil from terminal……

Optionals in Swift 3

Swift Optionals

A type the either has a “wrapped” value or is nil.
e.g.

let imagePaths = ["star": "/glyphs/star.png","portrait": "/images/content/portrait.jpg","spacer": "/images/shared/spacer.gif"]

Getting a dictionary’s value using a key returns an optional value, so imagePaths[“star”] has the type String?
e.g.

 if let imagePath = imagePaths["star"]
 {
 print("The star image is at '(imagePath)'")
 }
 else
 {
 print("Couldn't find the image")
 }

would print “The star image is at ‘/glyphs/star.png'”
but “if let starPath = imagePaths[puppy]…..
would print “Couldn’t find the image”
To safely access the properties and methods of a wrapped instance, use the postfix optional chaining operator (postfix ?).
e.g.

if let isPNG = imagePaths["star"]?.hasSuffix(".png") {
 print("The star image is in PNG format")
 }
// Prints "The star image is in PNG format"

if you want to supply a “default” value for when the optional is nil, use the nil-coalescing operator (??)

let defaultImagePath = "/images/default.png"
let imagePath = imagePaths["puppy"] ?? defaultImagePath
print(imagePath)
// Prints "/images/default.png"

Unconditionally Unwrapping
When you’re certain that an optional contains a value, you can unconditionally unwrap it using the forced unwrap operator (!)

let number = Int("42")!
print(number)
// Prints "42"

Automatic Unwrapping
If you declare an optional variable with a ! instead of a ? it will automatically unwrap.

var myString:String?
myString = "Hello, Swift!"
if myString != nil {
 println( myString! )
 }else {
 println("myString has nil value")
 }

Vs.

var myString:String!
myString = "Hello, Swift!"
if myString != nil {
 println(myString)
 }else {
 println("myString has nil value")
 }

NOTE: Unconditionally unwrapping a nil instance with ! triggers a runtime error.
see more at https://developer.apple.com/documentation/swift/optional

How to run a shell script in OS X by double-clicking

  • First in terminal make the script executable by typing:
    chmod a+x (yourscriptname)

 

  • Then, in Finder, right-click your file and select “Open with” and then “Other…”.

 

  • Here you select the application you want the file to execute into, in this case it would be Terminal.
  • To be able to select terminal you need to switch from “Recommended Applications” to “All Applications”.
    NOTE: The Terminal.app application can be found in the Utilities folder

 

  • If you want this to be the default behaviour from now on, check the “Always Open With” box.
  • After clicking OK you should be able to execute you script by simply double-clicking it.