Skip to content

Instantly share code, notes, and snippets.

#import "NSObject+Log.h"
#import <objc/runtime.h>
@implementation NSObject (Log)
- (void)log:(id)logObject
{
unsigned int numberOfProperties = 0;
objc_property_t *propertyArray = class_copyPropertyList([logObject class], &numberOfProperties);
NSLog(@"Property List for: %@", NSStringFromClass([self class]));
@Broich
Broich / gist:11041839
Last active August 29, 2015 14:00
I wonder if the operation addObjectsFromArray happens in constant time
- (void)createWallOfFame:(NSArray *)newWallOfFameMembers
{
NSLog(@"add %i new member(s) into wall of fame", (int)newWallOfFameMembers.count);
NSMutableArray *currentMembers = [NSMutableArray arrayWithArray:self.members];
if (currentMembers.count > 0) { // only if members are available there is a reason to delete them an the end
NSRange rangeForMembersToDelete = NSMakeRange(currentMembers.count-newWallOfFameMembers.count, newWallOfFameMembers.count);
NSLog(@"delete members from position: %d with length: %d", (int)rangeForMembersToDelete.location, (int)rangeForMembersToDelete.length);
[currentMembers removeObjectsInRange:rangeForMembersToDelete];
}
- (void)uploadImageToServer
{
[SVProgressHUD showWithStatus:@"Hochladen" maskType:SVProgressHUDMaskTypeBlack];
NSData *imageToUpload = UIImageJPEGRepresentation(self.croppedImage, 90);
if (!imageToUpload) {
NSLog(@"no data available");
return;
} else {
@Broich
Broich / gist:b91e24afece84ee491a1
Created March 23, 2016 11:23
Filter Localization.strings
"CATEGORY_MEAL_CUISINE" = "Cuisine";
"CATEGORY_MEAL_CUISINE_CHINESE" = "Chinese";
"CATEGORY_MEAL_CUISINE_ITALIAN" = "Italian";
"CATEGORY_MEAL_CUISINE_INDIAN" = "Indian";
"CATEGORY_MEAL_CUISINE_SPANISH_PORTUGUESE" = "Spanish and Portuguese";
"CATEGORY_MEAL_CUISINE_AMERICAN" = "American";
"CATEGORY_MEAL_CUISINE_MIDDLE_EASTERN" = "Middle Eastern";
"CATEGORY_MEAL_CUISINE_ASIAN" = "Asian";
"CATEGORY_MEAL_CUISINE_EUROPEAN" = "European";
MyViewController: UIViewController {
let refreshControl: UIRefreshControl = {
$0.tintColor = Theme.currentTheme().textColor
$0.addTarget(self, action: #selector(refresh(_:)), forControlEvents: .ValueChanged)
return $0
}(UIRefreshControl())
override func viewDidLoad() {
@Broich
Broich / DebugUserDefaultsViewController.swift
Last active June 29, 2016 15:57
Display NSUserDefaults in a UITableViewController (Swift)
class DebugUserDefaultsViewController: UITableViewController {
var userDefaults = NSUserDefaults.standardUserDefaults().dictionaryRepresentation() as NSDictionary
override func viewDidLoad() {
super.viewDidLoad()
title = "NSUserDefaults"
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
server.get('/bla', function(req, res) {
// instead of adding the implementation here
});
// create a new function here
function doBla(req, res) {
// implementation here
});
// now add it to exports