The best way to learn and master iOS development is to read the official documentation. It can be boring but you can trust its accuracy and the information will be presented without opinion.
Read documents in order where indicated.
The best way to learn and master iOS development is to read the official documentation. It can be boring but you can trust its accuracy and the information will be presented without opinion.
Read documents in order where indicated.
| // MARK: Using NSURLSession | |
| // Get first todo item | |
| let todoEndpoint: String = "http://jsonplaceholder.typicode.com/todos/1" | |
| guard let url = NSURL(string: todoEndpoint) else { | |
| print("Error: cannot create URL") | |
| return | |
| } | |
| let urlRequest = NSURLRequest(URL: url) |
| // Thanks to http://www.labs.saachitech.com/2012/10/23/pdf-generation-using-uiprintpagerenderer | |
| // Note: including images in the HTML won't work, see here: | |
| // https://github.com/nyg/HTMLWithImagesToPDF | |
| import UIKit | |
| // 1. Create a print formatter | |
| let html = "<b>Hello <i>World!</i></b>" | |
| let fmt = UIMarkupTextPrintFormatter(markupText: html) |
| ############################################################################### | |
| # Helpful Git/GitHub commands and code snippets | |
| ############################################################################### | |
| #### Remove/Squash All History on Master - CAUTION! #### | |
| # https://stackoverflow.com/a/26000395/580268 | |
| git checkout --orphan latest_branch \ | |
| && git add -A \\ | |
| && git commit -am "Remove/squash all project history" \ | |
| && git branch -D master \ |
| #!/usr/bin/env xcrun swift | |
| import Foundation | |
| let kDelayUSec : useconds_t = 500_000 | |
| func DragMouse(from p0: CGPoint, to p1: CGPoint) { | |
| let mouseDown = CGEventCreateMouseEvent(nil, .LeftMouseDown, p0, .Left) | |
| let mouseDrag = CGEventCreateMouseEvent(nil, .LeftMouseDragged, p1, .Left) | |
| let mouseUp = CGEventCreateMouseEvent(nil, .LeftMouseUp, p1, .Left) |
| import Cocoa | |
| @IBDesignable | |
| class <#ClassName#> : NSView { | |
| override init(frame frameRect: NSRect) { | |
| super.init(frame: frameRect) | |
| commonSetup() | |
| } | |
| -(UIImage*)mmg_imageScaledToFitSize:(CGSize)fitSize | |
| { | |
| // Create a vImage_Buffer from the CGImage | |
| CGImageRef sourceRef = self.CGImage; | |
| vImage_Buffer srcBuffer; | |
| vImage_CGImageFormat format = { | |
| .bitsPerComponent = 8, | |
| .bitsPerPixel = 32, | |
| .colorSpace = NULL, | |
| .bitmapInfo = (CGBitmapInfo)kCGImageAlphaFirst, |
Please consider using http://lygia.xyz instead of copy/pasting this functions. It expand suport for voronoi, voronoise, fbm, noise, worley, noise, derivatives and much more, through simple file dependencies. Take a look to https://github.com/patriciogonzalezvivo/lygia/tree/main/generative
float rand(float n){return fract(sin(n) * 43758.5453123);}
float noise(float p){
float fl = floor(p);
float fc = fract(p);
| import QuartzCore | |
| func executionTimeInterval(block: () -> ()) -> CFTimeInterval { | |
| let start = CACurrentMediaTime() | |
| block(); | |
| let end = CACurrentMediaTime() | |
| return end - start | |
| } |
| Events & Delegates | |
| ------------------ | |
| Events and Delegates were something I struggled with when I was first learning how they worked. Once I figured it out it became one of the most useful and powerful techniques for games. Its especially useful for helping to decouple classes while allowing for messaging. | |
| Delegates - Simply a container for a function that can be used as a variable. | |
| Events - Allows you to specify a delegate that gets called when some event in your code is triggered. | |
| Overview |