Skip to content

Instantly share code, notes, and snippets.

let sourceImage = UIImage(named: "swift1.png")
let maskImage = UIImage(named: "mask1.png")
let maskImageRef = maskImage!.CGImage
let sourceImageRef = sourceImage!.CGImage
let mask = CGImageMaskCreate(CGImageGetWidth(maskImageRef),
CGImageGetHeight(maskImageRef),
CGImageGetBitsPerComponent(maskImageRef),
struct SomeObject {
var variable: String?
init() {
self.variable = "test"
}
}
var j = 1
do {
let jsonDict = try NSJSONSerialization.JSONObjectWithData(fileContents!, options: []) as! NSDictionary
if let features = jsonDict["features"] as? [Dictionary<String, AnyObject>] {
// try this
var oneFeature = features[0]["geometry"]!["coordinates"]!![0][3]
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
// local variable reference so we can call funcs in ViewController class
var vc: ViewController?
@IBAction func click(sender: NSMenuItem) {
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
var v1: UIView
// this seems ok?
guard let vvv = UINib(nibName: "SampleView", bundle: nil).instantiateWithOwner(nil, options: nil)[0] as? UIView else { return }
v1 = vvv
// but this won't compile?
guard v1 = UINib(nibName: "SampleView", bundle: nil).instantiateWithOwner(nil, options: nil)[0] as? UIView else { return }
#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interface BorderedButton : UIButton
- (void)setCornerRadius:(CGFloat)cornerRadius;
- (void)setBorderWidth:(CGFloat)borderWidth;
- (void)setBorderColor:(UIColor *)borderColor;
//var myViews = self.view.subviews where ("some way to say subview-type is UIButton")
var myViews = self.view.subviews.flatMap{ $0 as? UIButton } // thanks bhargavg !!!
// next task: get a sub-array based on object properties?
//var myViews = self.view.subviews.flatMap{ $0 as? UIButton "where $0.backgroundColor == UIColor.yellowColor()" }
// this works - thanks DrYucatan
// ugly "stretched" image
UIImage* image = [UIImage imageNamed:@"btn.png"];
[_theButton setBackgroundImage:image forState:UIControlStateNormal];
// nice "stretchable" image
UIImage* image = [UIImage imageNamed:@"btn.png"];
UIEdgeInsets insets = UIEdgeInsetsMake(8, 8, 8, 8);
image = [image resizableImageWithCapInsets:insets];
[_theButton setBackgroundImage:image forState:UIControlStateNormal];
I need a RegEx...
All lines which:
DO CONTAIN "Created by"
but
DO NOT CONTAIN "Don" or "Joe" or "Bob"
So, for the following lines: