Skip to content

Instantly share code, notes, and snippets.

Scenario:
We have iPads at various locations...
Users have iPhones, with an "Act as a BLE beacon" app, using the Service UUID as an identifier...
The iPads need to respond when a user gets in range...
The iPads *also* have to respond to any other BLE in range...
So far, not a big deal. However...
When the iPhone app goes background, it can ONLY broadcast the Service UUID,
Show an In-Progress indicator (such as a spinner)...
Make the Request...
Alamofire.request(.GET, url, parameters: ["id": site.pressureSensorID])
.responseJSON { response in
// async call has returned...
switch response.result {
// "main" ViewController.swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)runTestURL:(id)sender {
// 1
NSString *dataUrl = @"https://someurl.com";
NSURL *url = [NSURL URLWithString:dataUrl];
// 2
NSURLSessionDataTask *downloadTask = [[NSURLSession sharedSession] dataTaskWithURL:url
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
// 4: Handle response here
// this is ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
// return proportional scaled size, with max width and height
func scaledSize(origSZ: CGSize, targSZ:CGSize) -> CGSize? {
var lNewW = targSZ.width
var lNewH = (origSZ.height / origSZ.width) * targSZ.width
if (lNewH > targSZ.height) {
lNewH = targSZ.height
lNewW = (origSZ.width / origSZ.height) * targSZ.height
//
#import "ViewController.h"
#import <WebKit/WebKit.h>
@interface ViewController ()
@property (strong, nonatomic) UIWebView *theWebView;
@property (strong, nonatomic) WKWebView *wkWebView;
@end
struct Foo {
var names: Set<String> = []
var numbers: Set<Int> = []
var otherNumbers: Set<Double> = []
func setNames<S: SequenceType where S.Generator.Element == String>(seq: S) -> Foo {
var new = self
new.names = Set(seq)
// in AppDelegate.swift
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
#import <UIKit/UIKit.h>
@interface DMView : UIView
@property (strong, nonatomic) UIColor *bkgColor;
- (id)initWithFrame:(CGRect)frame color:(UIColor *)color;
@end