Skip to content

Instantly share code, notes, and snippets.

View dmlebron's full-sized avatar

David dmlebron

View GitHub Profile
int main(void)
{
int h = get_positive_int("Height: "); // ask height and store it as i
printf("Stored: %i\n", h); //confirm value
for (int k = 1; k <= h; k++)
{
for (int i = 1; i <= (h-k); i++)
{
printf(".");
int main(void)
{
for (int i=0; i < 3; i++)
{
for (int j=0; j<=i; j++)
{
printf("#");
}
printf("\n");
}
var kindOfAnimal = Animal(rawValue: "dinosaur").unwrappedOrUnknown
enum Animal: String {
case unknown
case dog
case cat
}
extension Optional where Wrapped == Animal {
var unwrappedOrUnknown: Animal {
switch self {
struct MyObject {
var myProperty: String?
}
extension Optional where Wrapped == MyObject {
var unwrappedOrInit: MyObject {
switch self {
case .some(let unwrapped):
return unwrapped
tableView.register(MyCell.nib, forCellReuseIdentifier: MyCell. identifier)
let nib = UINib(nibName: "MyCell", bundle: nil)
tableView.register(nib, forCellReuseIdentifier: "MyCell")
protocol CellRegistrable {
static var identifier: String { get }
static var nib: UINib { get }
}
extension CellRegistrable {
/// Defaults value to the name of the class
static var identifier: String {
return String(describing: Self.self)
}
extension Optional where Wrapped == Int {
var unwrappedOrZero: Int {
switch self {
case .some(let unwrapped):
return unwrapped
case .none:
return 0
}
}
extension Optional where Wrapped == Bool {
var unwrappedOrFalse: Bool {
switch self {
case .some(let unwrapped):
return unwrapped
case .none:
return false
}
}