(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.
#import <Foundation/Foundation.h> | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
//Mutable Array | |
NSMutableArray *array; | |
array = [NSMutableArray arrayWithCapacity:4]; |
/////////////////////////////////////////////////////////////////////////////////// | |
/// Colection of RGB to HSB, HSB to RGB convert functions | |
/// Source: http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb | |
/////////////////////////////////////////////////////////////////////////////////// | |
/** | |
* componentToHex convert two digit htx value to R, G or B chanel value | |
* @param number c value from 0 to 225 | |
* @return string value of R, G or B chanel | |
* @usage //alert (componentToHex(255)); //ff |
class FileManager { | |
struct StaticInstance { | |
static var instance = FileManager() | |
} | |
class var defaultManager : FileManager { | |
return StaticInstance.instance | |
} | |
} |
(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.
function componentToHex(c) { | |
var hex = c.toString(16); | |
return hex.length == 1 ? "0" + hex : hex; | |
} | |
function rgbToHex(r, g, b) { | |
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b); | |
} | |
function invert(rgb) { |
iOS applications are usually built with MVC (Model – View – Controller) architecture, which introduces very important concept of separating actual data (Model Layer) and their presentation (View Layer), while the application logic (Controller Layer) stands between them.
View ← Controller → Model
With MVC you typically write most of the code in UIViewController
, which usually represents the Controller Layer. View Layer can be easily done in Interface Builder and Model Layer usually doesn’t need a lot of code. The UIViewControleler
then holds strong references to both View and Model objects and is responsible for setting them up, handling actions and listening to events.
The problem is, that this middle layer tends to hold too much code and this situation is then jokingly called Massive View Controller. When a single class sets up views, formats data values, handles user input and actions, listens for a bunch of notif
function toHex(n: number) { | |
return ('0' + n.toString(16)).slice(-2); | |
} | |
// ES6 | |
function hexToRGB(code) { | |
const [r, g, b] = code.replace('#', '') | |
.match(/../g).map((hex) => parseInt(hex, 16)); | |
return {r, g, b}; |
/* | |
(c) by Thomas Konings | |
Random Name Generator for Javascript | |
*/ | |
function capFirst(string) { | |
return string.charAt(0).toUpperCase() + string.slice(1); | |
} | |
function getRandomInt(min, max) { |
internal let DEFAULT_MIME_TYPE = "application/octet-stream" | |
internal let mimeTypes = [ | |
"html": "text/html", | |
"htm": "text/html", | |
"shtml": "text/html", | |
"css": "text/css", | |
"xml": "text/xml", | |
"gif": "image/gif", | |
"jpeg": "image/jpeg", |
A common task when developing iOS apps is to register custom cell subclasses for both UITableView
and UICollectionView
. Well, that is if you don’t use Storyboards, of course.
Both UITableView
and UICollectionView
offer a similar API to register custom cell classes:
public func registerClass(cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String)
public func registerNib(nib: UINib?, forCellWithReuseIdentifier identifier: String)