This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import JavaScriptCore; | |
/// Retaining MOJavaScriptObject retains your JSContext/JSObject as well | |
@interface MOJavaScriptObject : NSObject | |
@property (readonly) JSObjectRef JSObject; | |
@property (readonly) JSContextRef JSContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gif by dave @beesandbombs :) | |
int[][] result; | |
float t, c; | |
float ease(float p) { | |
return 3*p*p - 2*p*p*p; | |
} | |
float ease(float p, float g) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let readBinaryFile = (filepath) => { | |
return NSData.alloc().initWithContentsOfFile(filepath); | |
}; | |
let path = "path/to/file.json" | |
let data = readBinaryFile(path) | |
let contents = NSString.alloc().initWithData_encoding(data, NSUTF8StringEncoding) | |
console.log(JSON.parse(contents)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Excerpt from https://github.com/krzyzanowskim/CoreTextWorkshop | |
// Licence BSD-2 clause | |
// Marcin Krzyzanowski [email protected] | |
func getSizeThatFits(_ attributedString: NSAttributedString, maxWidth: CGFloat) -> CGSize { | |
let framesetter = CTFramesetterCreateWithAttributedString(attributedString) | |
let rectPath = CGRect(origin: .zero, size: CGSize(width: maxWidth, height: 50000)) | |
let ctFrame = CTFramesetterCreateFrame(framesetter, CFRange(), CGPath(rect: rectPath, transform: nil), nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let items = [ | |
"Cats walking down to the mall to hang out at the water fountain", | |
"Dogs catching tennis balls by the hotel pool", | |
"Fish doing backflips as they hone their circus aspirations" | |
] | |
let mainAttributedString = NSMutableAttributedString() | |
for (index, item) in items.enumerated() { | |
// Get the highest number however you want, this is hardcoded for sake of example |