Skip to content

Instantly share code, notes, and snippets.

View hyperspacemark's full-sized avatar

Mark Adams hyperspacemark

View GitHub Profile
@hyperspacemark
hyperspacemark / iOS Analytics.md
Last active May 5, 2023 02:51
iOS Analytics State of the Union

Analytics

Old School Event Tracking

Until recently we've only needed to report analytics events for Venmo, to Amplitude, via mParticle.

To that end, iOS uses the following abstraction for tracking analytics events in feature code.

protocol AnalyticsEventTracker {
private func loadCFunction<Function>(named name: String, ofType _: Function.Type = Function.self) -> Function {
let sym = dlsym(UnsafeMutablePointer<Void>(bitPattern: -2), name) // RTLD_DEFAULT
return unsafeBitCast(sym, Function.self)
}
private let CC_SHA1_DIGEST_LENGTH = 20
private let CC_SHA1: @convention(c) (UnsafePointer<Void>, Int32, UnsafeMutablePointer<UInt8>) -> UnsafeMutablePointer<UInt8> = loadCFunction(named: "CC_SHA1")
extension String {
/// Defines an interface for objects that can be collated.
protocol Collatable: Hashable {
/// The string value that will be used to collate objects.
var collationString: String { get }
}
final class LocalizedIndexedCollation<T: Collatable> {
// MARK: Properties
[Xcode.app/Contents] ag -g icns$ | ag "framework"
Developer/Library/Xcode/Templates/Project Templates/Mac/Framework & Library/Bundle.xctemplate/TemplateIcon.icns
Developer/Library/Xcode/Templates/Project Templates/Mac/Framework & Library/Cocoa Framework.xctemplate/TemplateIcon.icns
Developer/Library/Xcode/Templates/Project Templates/Mac/Framework & Library/XPC Service.xctemplate/TemplateIcon.icns
Developer/Platforms/AppleTVOS.platform/Developer/Library/Xcode/Templates/Project Templates/AppleTVOS/Framework & Library/TV Framework.xctemplate/TemplateIcon.icns
Developer/Platforms/AppleTVOS.platform/Developer/Library/Xcode/Templates/Project Templates/AppleTVOS/Framework & Library/TV Static Library.xctemplate/TemplateIcon.icns
Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/iOS/Framework & Library/Cocoa Touch Framework.xctemplate/TemplateIcon.icns
Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/iOS/Framework & Library/Cocoa Touch St
struct AttributedStringBuilder {
// MARK: - Types
enum Attribute {
case Font(UIFont)
case ParagraphStyle(NSParagraphStyle)
case ForegroundColor(UIColor)
case BackgroundColor(UIColor)
case Ligature(UInt)
final class Controller: A {
var property: String = "" {
didSet {
for a in collectionOfA {
// Cannot assign to property: 'a' is a 'let' constant
a.property = property
}
}
}
@hyperspacemark
hyperspacemark / RageMap.swift
Created August 21, 2015 21:32
A new implementation of `flatMap(f:)` added to `SequenceType` in Swift 2.0.
extension SequenceType {
/// Return an `Array` containing the non-nil results of mapping
/// `transform` over `self`.
///
/// - Complexity: O(*M* + *N*), where *M* is the length of `self`
/// and *N* is the length of the result.
public func flatMap<T>(@noescape transform: (Self.Generator.Element) -> T?) -> [T]
}
@interface LocationController () <CLLocationManagerDelegate>
@property (nonatomic) CLLocationManager *locationManager;
@end
@implementation LocationController
- (RACSignal *)locationUpdate
{
@interface NetworkActivityStatus : NSObject
+ (instancetype)sharedStatus;
- (void)pushNetworkActivity;
- (void)popNetworkActivity;
@end
enum CameraConnectionResult {
case Success(CameraType)
case Failure(NSError) // Really don't want this to be Optional<NSError>
}
class CameraClient {
class func connect(completion: CameraConnectionResult -> ()) {
let URL = NSURL(string: "http://10.5.5.9:8080/videos/MISC/version.txt")
if let versionURL = URL {
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()