Skip to content

Instantly share code, notes, and snippets.

//
// 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
// - (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) {
@kingiol
kingiol / iosbuild.sh
Created September 3, 2018 05:44 — forked from reqshark/iosbuild.sh
libmill iOS cross-compile for 32 bit (armv7) and 64 bit (arm64) iOS, and i386 and x86_64 simulators
# 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:
@kingiol
kingiol / gist:09e8b30e45d5d30d4dc70ecedcdf997c
Last active September 1, 2018 15:14
Can print any object to String
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()
}
}
@kingiol
kingiol / Storage.swift
Created August 12, 2018 11:44 — forked from saoudrizwan/Storage.swift
Helper class to easily store and retrieve Codable structs from/to disk. https://medium.com/@sdrzn/swift-4-codable-lets-make-things-even-easier-c793b6cf29e1
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
@kingiol
kingiol / gist:40edb046ca3c7aec4d3652641a9338ce
Created August 11, 2018 14:02
打印UIView的所有子节点结构
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 += "-"
}
//
// 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>
@kingiol
kingiol / UIKeyboard
Created November 10, 2015 11:27
iOS键盘事件
【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!
@kingiol
kingiol / UIDevice+Orientation
Created November 10, 2015 09:51
监听手机当前的方向
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];
@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) {