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
// | |
// MyMetalWaterfall.swift | |
// version 0.1.104 | |
// | |
// Demonstrates using a MetalKit compute shader to render a live waterfall | |
// RGB spectrogram bitmap from iOS RemoteIO audio input into a UIView | |
// | |
// This is a single file iOS app (it only compiles for iOS devices, not the Simulator) | |
// | |
// It includes AppDelegate for a minimal demonstration app |
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
// - (UIWindow *)frontWindow { | |
// #if !defined(SV_APP_EXTENSIONS) | |
// NSEnumerator *frontToBackWindows = [UIApplication.sharedApplication.windows reverseObjectEnumerator]; | |
// for (UIWindow *window in frontToBackWindows) { | |
// BOOL windowOnMainScreen = window.screen == UIScreen.mainScreen; | |
// BOOL windowIsVisible = !window.hidden && window.alpha > 0; | |
// BOOL windowLevelSupported = (window.windowLevel >= UIWindowLevelNormal && window.windowLevel <= self.maxSupportedWindowLevel); | |
// BOOL windowKeyWindow = window.isKeyWindow; | |
// | |
// if(windowOnMainScreen && windowIsVisible && windowLevelSupported && windowKeyWindow) { |
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
# Copyright (c) 2015 Bent Cardan | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), | |
# to deal in the Software without restriction, including without limitation | |
# the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
# and/or sell copies of the Software, and to permit persons to whom | |
# the Software is furnished to do so, subject to the following conditions: |
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
infix operator ???: NilCoalescingPrecedence | |
public func ???<T>(optional: T?, defaultValue: @autoclosure () -> String) -> String { | |
switch optional { | |
case let value?: | |
return String(describing: value) | |
case nil: | |
return defaultValue() | |
} | |
} |
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 Foundation | |
public class Storage { | |
fileprivate init() { } | |
enum Directory { | |
// Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the <Application_Home>/Documents directory and will be automatically backed up by iCloud. | |
case documents | |
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
func hierarchyOfView(_ view: UIView, level: Int = 1) { | |
let subviews = view.subviews | |
if subviews.isEmpty { return } | |
for subview in subviews { | |
var blank = "" | |
for _ in 1..<level { | |
blank += "-" | |
} |
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
// | |
// ViewController.m | |
// AVPlayerCaching | |
// | |
// Created by Anurag Mishra on 5/19/14. | |
// Sample code to demonstrate how to cache a remote audio file while streaming it with AVPlayer | |
// | |
#import "ViewController.h" | |
#import <AVFoundation/AVFoundation.h> |
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
【iOS中有关键盘事件】 | |
let notificationCenter = NSNotificationCenter.defaultCenter() | |
notificationCenter.addObserver(self, selector: "adjustForKeyboard:", name: UIKeyboardWillHideNotification, object: nil) | |
notificationCenter.addObserver(self, selector: "adjustForKeyboard:", name: UIKeyboardWillChangeFrameNotification, object: nil) | |
func adjustForKeyboard(notification: NSNotification) { | |
let userInfo = notification.userInfo! | |
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
UIDevice *device = [UIDevice currentDevice]; //Get the device object | |
[device beginGeneratingDeviceOrientationNotifications]; //Tell it to start monitoring the accelerometer for orientation | |
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; //Get the notification centre for the app | |
[nc addObserver:self //Add yourself as an observer | |
selector:@selector(orientationChanged:) | |
name:UIDeviceOrientationDidChangeNotification | |
object:device]; | |
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
@implementation NSString (Range) | |
- (NSArray *)rangesOfString:(NSString *)substring { | |
if (self.length == 0 || substring.length == 0) | |
return @[]; | |
NSRange searchRange = NSMakeRange(0, self.length - 1); | |
NSMutableArray *ranges = [@[] mutableCopy]; | |
while (searchRange.location < self.length) { |