Skip to content

Instantly share code, notes, and snippets.

View giannigdev's full-sized avatar

Gianni giannigdev

View GitHub Profile
- (void)testRelativeURLs {
PSPDFDocument *document = [[PSPDFTestAssetLoader new] documentWithName:@"Testcase-relative-links.pdf"];
NSArray *annotations = [document annotationsForPage:0 type:PSPDFAnnotationTypeLink];
PSPDFLinkAnnotation *link = annotations[0];
NSString *const referenceString = @"Testcase-relative-links/Simple.txt";
XCTAssertEqualObjects(link.URL.absoluteString, referenceString, @"URL should be correct");
PSPDFViewController *pdfController = [[PSPDFViewController alloc] initWithDocument:document];
__block NSURL *showPreviewURL = nil;
- (void)testSparkInspectorCompatibility {
PSPDFDocument *document = [[PSPDFTestAssetLoader new] documentWithName:@"Testcase_Metadata.pdf"];
// Spark swizzles this method and calls description on the target. Let's simulate this for this test case, and then clean up.
id<Aspect> token = [NSNotificationCenter aspect_hookSelector:@selector(addObserver:selector:name:object:) withOptions:0 usingBlock:^(id instance, NSArray *args) {
[args.firstObject description];
} error:NULL];
// Load the document. This failed because of side effects in description when called during init.
UIImage *image = [document imageForPage:0 size:CGSizeMake(100, 100) clippedToRect:CGRectZero annotations:nil options:nil receipt:NULL error:NULL];
@calebd
calebd / ArrayHelpers.swift
Last active November 4, 2022 15:17
Swift Helpers
extension Array {
func first() -> Element? {
if isEmpty {
return nil
}
return self[0]
}
func last() -> Element? {
@JamesMGreene
JamesMGreene / gitflow-breakdown.md
Last active May 3, 2024 12:32
`git flow` vs. `git`: A comparison of using `git flow` commands versus raw `git` commands.

Initialize

gitflow git
git flow init git init
  git commit --allow-empty -m "Initial commit"
  git checkout -b develop master

Connect to the remote repository

@mindbrix
mindbrix / gist:710707d3dec311196e5e
Last active August 29, 2015 14:03
Unicode char to NSString
NSString *hexString = @"1F0A7";
unsigned int character;
NSScanner* scanner = [NSScanner scannerWithString:hexString ];
[ scanner scanHexInt:&character ];
UTF32Char inputChar = NSSwapHostIntToLittle(character); // swap to little-endian if necessary
NSString *str = [[NSString alloc] initWithBytes:&inputChar length:4 encoding:NSUTF32LittleEndianStringEncoding];
@seivan
seivan / gist:65bb810a046ee5029174
Created July 12, 2014 11:27
Make an NSSet into an Array by implicit conversion
extension NSSet {
@conversion func __conversion() -> Array<AnyObject> {
return self.allObjects
}
}
func returnImmutableNSSet()-> NSSet {
return NSSet(array: [1,2,3,4])
}
@nicklockwood
nicklockwood / Hacking UIView Animation Blocks.md
Last active January 12, 2024 06:15
This article was originally written for objc.io issue 12, but didn't make the cut. It was intended to be read in the context of the other articles, so if you aren't familiar with concepts such as CALayer property animations and the role of actionForKey:, read the articles in that issue first.

Hacking UIView animation blocks for fun and profit

In this article, I'm going to explore a way that we can create views that implement custom Core Animation property animations in a natural way.

As we know, layers in iOS come in two flavours: Backing layers and hosted layers. The only difference between them is that the view acts as the layer delegate for its backing layer, but not for any hosted sublayers.

In order to implement the UIView transactional animation blocks, UIView disables all animations by default and then re-enables them individually as required. It does this using the actionForLayer:forKey: method.

Somewhat strangely, UIView doesn't enable animations for every property that CALayer does by default. A notable example is the layer.contents property, which is animatable by default for a hosted layer, but cannot be animated using a UIView animation block.

@alloy
alloy / README.markdown
Created August 8, 2014 09:56
Learn the LLVM C++ API by example.

The easiest way to start using the LLVM C++ API by example is to have LLVM generate the API usage for a given code sample. In this example it will emit the code required to rebuild the test.c sample by using LLVM:

$ clang -c -emit-llvm test.c -o test.ll
$ llc -march=cpp test.ll -o test.cpp
@marcboquet
marcboquet / gist:340c240c50aed6c71a1e
Created August 8, 2014 15:37
Create empty Swift playground files
#! /usr/bin/ruby
require 'pathname'
platform = "iphonesimulator" # or "macosx"
contents_xcplayground = <<XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='1.0' sdk='#{platform}'>
<sections>
<code source-file-name='section-1.swift'/>
</sections>
enum FizzBuzz {
case fizz
case buzz
case fizzBuzz
case number(Int)
init(rawValue: Int) {
switch (rawValue % 3, rawValue % 5) {
case (0, 0): self = .fizzBuzz
case (0, _): self = .fizz