This file contains hidden or 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
extension UIHostingController { | |
func capture() -> UIImage { | |
let size = sizeThatFits(in: UIScreen.main.bounds.size) | |
view.bounds.size = size | |
view.sizeToFit() | |
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.isOpaque, 0) | |
view.drawHierarchy(in: view.bounds, afterScreenUpdates: true) | |
let snapshotImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()! | |
UIGraphicsEndImageContext() |
This file contains hidden or 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
require 'find' | |
require 'pp' | |
swift_file_paths = [] | |
Find.find('./') do |path| | |
if path =~ /.*\.swift$/ and !path.start_with? "./Carthage" | |
swift_file_paths << path | |
cmd = "xcrun swift-update -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -target arm64-apple-ios9 #{path} > convert.swift" | |
system cmd |
This file contains hidden or 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
@objc(Person) | |
final public class Person : NSCoding { | |
public var firstName:String | |
public var lastName:String | |
private enum SerializationKeys : String { | |
case FirstName | |
case LastName | |
} |
This file contains hidden or 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
//: Playground demonstrating how to deal with an Array containing items that conform | |
//: to a protocol. | |
import Cocoa | |
/*: | |
Just a basic protocol with a single function that has to be implemented. | |
*/ | |
protocol Nameable { | |
This file contains hidden or 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 Cocoa | |
import AppKit | |
let item1 = NSPathControlItem() | |
item1.title = "This is the title" | |
let title1 = item1.title |
This file contains hidden or 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 UIKit | |
extension Array { | |
subscript(index:Int,defaultValue def:T) -> T { | |
if ( (0 <= index) && (index < self.count) ) { | |
return self[index] | |
} | |
else { | |
return def |
This file contains hidden or 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
// | |
// Basic replacement of a variable with no specified style attribute | |
// #{field} | |
// | |
// Replacement with variable and style | |
// #{field:style} | |
// | |
// Push a style on the stack | |
// #{+style} | |
// |
This file contains hidden or 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
# This is a sample command for compiling a swift file that requires an external framework. | |
# | |
# | |
# | |
xcrun swift -i swifthello.swift -framework DHTest2 -F /Users/davidahouse/Projects/swift -sdk $(xcrun --show-sdk-path --sdk macosx) |
This file contains hidden or 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
# Add image field to model | |
# fields :title, :some_image_field | |
# Create a form for uploading the image | |
<%= form_tag({ :action => :upload_image_save}, :multipart => true) do %> | |
<%= file_field_tag 'image' %> | |
<div class="actions"> | |
<%= submit_tag %> | |
</div> |
This file contains hidden or 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
+ (<class> *)shared<whatever> { | |
static <class> *shared<class> = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
shared<class> = [[self alloc] init]; | |
}); | |
return shared<class>; | |
} |
NewerOlder