Skip to content

Instantly share code, notes, and snippets.

let mainLayer = CALayer()
mainLayer.frame = CGRect(x: 0, y: 0, width: 500, height: 500)
mainLayer.backgroundColor = CGColor(red: 100.0/255.0, green: 130.0/255.0, blue: 230.0/255.0, alpha: 1.0)
let layer = CALayer()
layer.frame = CGRect(x: 250, y: 250, width: 100, height: 100)
layer.backgroundColor = CGColor(srgbRed: 10.0, green: 50.0, blue: 10.0, alpha: 100.0)
let oneLayer = CALayer()
oneLayer.frame = CGRect(x: 300, y: 300, width: 50, height: 50)
func lines(space: Int, context: CGRect, count: Int) -> [CGRect] {
var line = [CGRect]()
for arr in 0..<count {
let lineOne = CGRect(origin:context.minX + CGRect(space) * CGRect(arr),
size: context.height)
let lineOtwo = CGRect(origin:context.width,
func makePlus(at point: CGPoint, dimension: CGFloat, thickness: CGFloat) -> [CGRect] {
let width = dimension
let height = thickness
let first = CGRect(
x: point.x - dimension / 2 ,
y: point.y - thickness / 2,
width: width,
func rectangles( largeRect: CGRect, count: Int) -> [CGRect] {
if count <= 1 {
CGRect(x: 0, y: 0, width: largeRect.width , height: largeRect.height)
return []
} else {
for _ in 0...count{
CGRect(x: (0 + (largeRect.width)) * CGFloat(count) ,
func rectangles( largeRect: CGRect, count: Int) -> [CGRect] {
if count <= 1 {
CGRect(x: 0, y: 0, width: largeRect.width , height: largeRect.height)
return []
} else {
for _ in 0...count{
CGRect(x: 0 + (largeRect.width) * CGFloat(count) ,
func rectangles( largeRect: CGRect, count: Int) -> [CGRect] {
if count <= 1 {
CGRect(x: 0, y: 0, width: largeRect.width , height: largeRect.height)
return []
} else {
for _ in 0...count{
CGRect(x: 0 + (largeRect.width) * CGFloat(count) ,
struct Siblings {
var sibling1: Int
var sibling2: Int
init(sibling1: Int, sibling2: Int){
self.sibling1 = sibling1
self.sibling2 = sibling2
}
struct Siblings {
var sibling1: Int
var sibling2: Int
init(sibling1: Int, sibling2: Int){
self.sibling1 = sibling1
self.sibling2 = sibling2
}
func swapTwoString(a: inout String, b: inout String) {
let temporaryB = a
a = b
b = temporaryB
}
var someString = "I AM FIRST"
var anotherStirng = "I AM SECONDE"
var array = ["One", "Two", "Three"]
array.append("Four")
// This won't compile, since the above array is specialized
// for strings, meaning that other values can't be inserted:
array.append(5)
// As we pull an element out of the array, we can still treat
// it like a normal string, since we have full type safety.
let characterCount = array[0].count