This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/fish | |
set SWIFT_PATH /opt | |
sudo find $SWIFT_PATH/swift/ -name "*.h" ! -perm -go=r -exec chmod go+r "{}" \; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/swift | |
/* | |
* File: ANSITerminalColour.swift | |
* Language: Apple Swift 3 or 4 | |
* Author: Matthias M. Schneider | |
* Purpose: Demonstrate how to use an `enum` to use the ANSI colour control characters in String folding for console output. | |
* Version: 1.0 | |
* Copyright: IDC (I don't care) | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/fish | |
set SWIFT_PATH /opt | |
set swift_versions (sudo find $SWIFT_PATH -maxdepth 1 -name "swift[0-9][0-9][0-9]" -type d -printf "%f\n" | sort) | |
set swift_active_version (stat $SWIFT_PATH/swift -c "%N" | sed -r "s/.+(swift[0-9][0-9][0-9]).+/\1/g") | |
echo -e "\n\e[44;1mI found these Swift versions:\e[0m" | |
set i 1 | |
for v in $swift_versions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: # How to retrieve a host name and associated aliases from an IP address using Core Fondation's `CFHost` in Swift 3 | |
import Foundation | |
import PlaygroundSupport | |
//: In order to get the callback working we use a simple class to implement the showcase. | |
class DNSResolve { | |
//: The IP address may be a Swift `String` thanks to the toll-free bridging to C strings. | |
let ip: String = "17.172.224.47" | |
//: We use an optional `CFHost` variable because CFHost neither comes with an initializer nor is conforming to the Nullable protocol. | |
var host: CFHost? | |
//: We use this array of `String`s to store the resolved host names. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: # How to retrieve a host name and associated aliases from an IP address | |
//: Rename the file extension to `playground` and run it directly in Xcode 8 with Swift 3. | |
import SwiftGlibc | |
//: ## Using the C `struct`s in Swift | |
//: We can safely use a Swift `String` for storing the IP address in character format as Swift supports toll-fee bridging to C strings. | |
// let ip = "17.172.224.47" // Apple | |
let ip = "104.86.147.173" // Akamai Technologies | |
//: In order to use the `hostent` C structure as a reference value (pointer) we have to declare it as an `UnsafeMutablePointer` of the corresponding type. | |
//: We use `let` as the value itself will never change, but only the reference to the value. As such, the value (not the reference, or pointer for that matter) will be a constant. | |
let he: UnsafeMutablePointer<hostent>? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*: | |
Swift `Optional`s, as noted in Apple's documentation, are implemented as an enumeration with two cases: | |
* None | |
* Some | |
The question is how to declare a type-agnostic enumeration. The answer is simple: By using a generic. | |
*/ | |
enum Opt<T>: CustomStringConvertible, NilLiteralConvertible { | |
case None | |
case Some(T) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: # How to retrieve a host name and associated aliases from an IP address using Core Fondation's `CFHost` | |
import Cocoa | |
import XCPlayground | |
//: In order to get the callback working we use a simple class to implement the showcase. | |
class DNSResolve { | |
//: The IP address may be a Swift `String` thanks to the toll-free bridging to C strings. | |
let ip: String = "17.172.224.47" | |
//: We use an optional `CFHost` variable because CFHost neither comes with an initializer nor is conforming to the Nullable protocol. | |
var host: CFHost? | |
//: We use this array of `String`s to store the resolved host names. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: # How to retrieve a host name and associated aliases from an IP address | |
//: Rename the file extension to `playground` and run it directly in Xcode 7 with Swift 2. | |
import Cocoa | |
//: ## Using the C `struct`s in Swift | |
//: We can safely use a Swift `String` for storing the IP address in charachter format as Swift supports toll-fee bridging to C strings. | |
let ip = "17.172.224.47" | |
//: In order to use the `hostent` C structure as a reference value (pointer) we have to declare it as an `UnsafeMutablePointer` of the corresponding type. | |
//: We use `let` as the value itself will never change, but only the reference to the value. As such, the value (not the reference, or pointer for that matter) will be a constant. | |
let he: UnsafeMutablePointer<hostent> | |
//: We can declare another constant of type `hostent` which will be type-compatible with the memory location of `he`'s pointer to the C structure. |