Skip to content

Instantly share code, notes, and snippets.

View zhihuitang's full-sized avatar
😜

Zhihui Tang zhihuitang

😜
View GitHub Profile

Sometimes we need to open Setting's Preferences not of our app, but of the iPhone itself. What should we do to acomplish this?

[UPDATE: Added Wallet And Apple Pay below]

[UPDATE: Changed prefs for Bluetooth]

keyboard

exec > /tmp/${PROJECT_NAME}_archive.log 2>&1
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
@zhihuitang
zhihuitang / archieve-pre-actions.sh
Last active February 15, 2020 06:11
Remove i386/x86_64 architectures from framework
exec > /tmp/${PROJECT_NAME}_archive.log 2>&1
FRAMEWORK_NAME="YOUR-FRAMEWORK-NAME"
cd ${SRCROOT}/Pods/${FRAMEWORK_NAME}/
echo "🚀backup ${SRCROOT}/Pods/${FRAMEWORK_NAME}/${FRAMEWORK_NAME}.framework"
if [ -f "${FRAMEWORK_NAME}.zip" ]
then
exec >> /tmp/${PROJECT_NAME}_archive.log 2>&1
FRAMEWORK_NAME="YOUR-FRAMEWORK-NAME"
cd ${SRCROOT}/Pods/${FRAMEWORK_NAME}/
echo "🚀restore ${SRCROOT}/Pods/${FRAMEWORK_NAME}"
rm -rf ./${FRAMEWORK_NAME}.framework
unzip -o ${FRAMEWORK_NAME}.zip
rm -rf ${FRAMEWORK_NAME}.zip
@zhihuitang
zhihuitang / OCCatch.h
Last active June 10, 2019 04:06
How to properly catch NSExceptions in Swift?
//
// OCCatch.h
//
//
#ifndef OCCatch_h
#define OCCatch_h
// add the code below to your -Bridging-Header.h
@zhihuitang
zhihuitang / SwiftIntegerChecker.swift
Created January 7, 2018 14:17 — forked from juliengdt/SwiftIntegerChecker.swift
To check if a number is between a range in Swift
// To check if a number is between a range, don't do
if number >=0 && number <= 100 {
}
// Use range and news operators instead :
if 0...100 ~= number {
}
@zhihuitang
zhihuitang / AsyncOperation
Last active March 31, 2020 16:52
AsyncOperation: Wrap Asynchronous Function in Operation For synchronous tasks, you can create an Operation subclass by overriding the main() method. AsyncOperation is a custom subclass of Operation that handles state changes automatically. Then, to
class AsyncOperation: Operation {
enum State: String {
case Ready, Executing, Finished
fileprivate var keyPath: String {
return "is" + rawValue
}
}
var state = State.Ready {
@zhihuitang
zhihuitang / AsynchronousOperation.swift
Created February 14, 2018 13:58 — forked from calebd/AsynchronousOperation.swift
Concurrent NSOperation in Swift
import Foundation
/// An abstract class that makes building simple asynchronous operations easy.
/// Subclasses must implement `execute()` to perform any work and call
/// `finish()` when they are done. All `NSOperation` work will be handled
/// automatically.
open class AsynchronousOperation: Operation {
// MARK: - Properties
@zhihuitang
zhihuitang / Collection
Last active February 29, 2020 10:20
Returns the element at the specified index if it is within bounds, otherwise nil.
public extension Collection {
/// Returns the element at the specified index if it is within bounds, otherwise nil.
subscript (safe index: Index) -> Element? {
return indices.contains(index) ? self[index] : nil
}
}
public extension CGSize {
public func rescale(_ scale: CGFloat) -> CGSize {
return applying(CGAffineTransform(scaleX: scale, y: scale))
}
}