(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
func fizzbuzz(i: Int) -> String { | |
let result = (i % 3, i % 5) | |
switch result { | |
case (0, _): | |
return "Fizz" | |
case (_, 0): | |
return "Buzz" | |
case (0, 0): | |
return "FizzBuzz" | |
default: |
// Let's define a basic Swift class. | |
class Fruit { | |
var type=1 | |
var name="Apple" | |
var delicious=true | |
} | |
// We can get at some info about an instance of an object using reflect(), which returns a Mirror. | |
reflect(Fruit()).count | |
reflect(Fruit())[1].0 |
func add(a: Int, b: Int) -> Int { | |
return a + b | |
} | |
add(1, 2) | |
func add(a: Int, #b: Int) -> Int { | |
return a + b | |
} |
# The following code and the code generated art works are the intellectrual properities of Hailei Wang. | |
# © 2009 - 2014, Hailei Wang. All rights reserved. | |
from nodebox import geo | |
colors = ximport("colors") | |
# Define Brush | |
def composeimage( x, y, colr, radius, points, diminish ) : | |
nofill() | |
stroke() |
# The following code and the code generated art works are the intellectrual properities of Hailei Wang. | |
# © 2010 - 2014, Hailei Wang. All rights reserved. | |
colors = ximport( "colors" ) | |
font( "Courier", 200 ) | |
align( CENTER ) | |
text_path_line_1 = textpath( "IDEO", 0, 200, width = WIDTH) | |
text_path_line_2 = textpath( "LABS", 0, 350, width = WIDTH) |
// An extension to Optional type: | |
// getOrElse() will return optional's value if exists, otherwise the default value provided as argument will be returned. | |
// | |
// Note: Since Xcode6 beta 5, you can use '??' operator. | |
// | |
// (c) Tomek Cejner 2014 | |
// @tomekcejner | |
extension Optional { | |
func getOrElse(val:T) -> T { | |
if self != nil { |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
extension Array { | |
func contains(object:AnyObject) -> Bool { | |
return self.bridgeToObjectiveC().containsObject(object) | |
} | |
func indexOf(object:AnyObject) -> Int { | |
return self.bridgeToObjectiveC().indexOfObject(object) | |
} | |
} |
import Darwin | |
import CoreGraphics | |
protocol ScalarFunctions { | |
var acos:Double {get} | |
var asin:Double {get} | |
var atan:Double {get} | |
func atan2(x:Double) -> Double | |
var cos:Double {get} | |
var sin:Double {get} |
// | |
// Queue.swift | |
// NTBSwift | |
// | |
// Created by Kåre Morstøl on 11/07/14. | |
// | |
// Using the "Two-Lock Concurrent Queue Algorithm" from http://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html#tlq, without the locks. | |
// should be an inner class of Queue, but inner classes and generics crash the compiler, SourceKit (repeatedly) and occasionally XCode. |