Skip to content

Instantly share code, notes, and snippets.

View Gernot's full-sized avatar

Gernot Poetsch Gernot

View GitHub Profile
NSDictionary *testDict = [NSDictionary dictionary];
NSMutableDictionary *mutableTestDict = [NSMutableDictionary dictionary];
if ([testDict isKindOfClass:[NSDictionary class]]
&& ![testDict isKindOfClass:[NSMutableDictionary class]] //notice the negation here!
&& [mutableTestDict isKindOfClass:[NSDictionary class]]
&& [mutableTestDict isKindOfClass:[NSMutableDictionary class]])
{
NSLog(@"Hey Christian, klappt doch!");
}
From e73676528a86527149063b03882b58ca84e3958d Mon Sep 17 00:00:00 2001
From: Gernot Poetsch <github@poetsch.org>
Date: Wed, 17 Aug 2011 15:39:48 +0200
Subject: [PATCH] Increasing LastUpgradeCheck to please THE STEVE
---
SoundCloudUI.xcodeproj/project.pbxproj | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/SoundCloudUI.xcodeproj/project.pbxproj b/SoundCloudUI.xcodeproj/project.pbxproj
@Gernot
Gernot / gist:1206389
Created September 9, 2011 14:35
ARC + Analyzer
+ (NSString *)nx_stringWithUUID;
{
CFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef string = CFUUIDCreateString(kCFAllocatorDefault, theUUID);
CFRelease(theUUID);
NSString *returnValue = (__bridge_transfer NSString*)string;
return returnValue;
/*
extension NSURL {
convenience init?(optionalString: String?) {
if (optionalString == nil) {
self.init() //Yeah, this makes sense. Go on, try deleting it. Compiler will complain… (At least in Xcode 6.1)
return nil
}
self.init(string:optionalString!)
}
}
@Gernot
Gernot / Swift-Workshop.md
Created November 25, 2014 14:02
Swift Workshop
struct Time {
/* Is there any good way to do this without the intermediate vars? Swift 1.2 (Xcode 6.3b4) does not seem to let me write into the structs constants directly before initializing them. */
init(date: NSDate) {
var hour: Int = 0, minute: Int = 0, second: Int = 0, nanosecond: Int = 0
NSCalendar.currentCalendar().getHour(&hour, minute: &minute, second: &second, nanosecond: &nanosecond, fromDate: date)
self.hour = hour; self. minute = minute; self.second = second; self.nanosecond = nanosecond
}
let hour: Int
public struct Time {
init(date: NSDate) {
NSCalendar.currentCalendar().getHour(&hours, minute: &minutes, second: &seconds, nanosecond: &nanoseconds, fromDate: date)
}
private(set) public var hours: Int = 0
private(set) public var minutes: Int = 0
private(set) public var seconds: Int = 0
private(set) public var nanoseconds: Int = 0
/// Is there any way to use the Options from libxml2 with the cool new `OptionSet` Syntax from Swift 2?
//This is how I do it now
let options = Int32(HTML_PARSE_RECOVER.rawValue | HTML_PARSE_NOWARNING.rawValue | HTML_PARSE_NOERROR.rawValue)
// ideally I want this, but it doesn't work
let options: htmlParserOption = [HTML_PARSE_RECOVER, HTML_PARSE_NOWARNING, HTML_PARSE_NOERROR]
//here's the typedef from libxml/HTMLparser.h
/*
import Foundation
func doStuff<T:CollectionType where T.Generator.Element: Equatable, T.Index.Distance == Int>(collection:T) {
//Do Stuff
}
var list: [Any] = [1,2,2,3,4,5] //This HAS to be saved as [Any]. Or is there another way to specify all kinds of collections that would work with doStuff()?
doStuff(list) //This fails: cannot invoke 'doStuff' with an argument list of type '([Any])'
struct CharacteristicValue {
let format: Int8
let exponent: Int8 = -1
let unit: UInt16
let namespace: Int8
let descriptionInfo: Int16
}
var value = CharacteristicValue(format: 14, unit: 0x272F, namespace: 1, descriptionInfo: 0)