Skip to content

Instantly share code, notes, and snippets.

##Logging in Cocoa

There are a ton of ways and frameworks for logging in your project. At the following I will describe the way it works for me.

For me it's not so important to have multiple loggers, meaning I can log to a file and the console simultaneously. If you look for such a solution, I recommend to look in the CocoaLumberjack or the NSLogger framework.

My focus is: Log information to the console in a simple way, without any extra dependences and configurable for the debug or the release setting.

My preferred way to get this, is to use macros. The macros are placed at the end of the Prefix.pch file of your project and looks like the following:

@greyspot09
greyspot09 / GIFLoader.h
Last active August 29, 2015 14:26 — forked from andrei512/GIFLoader.h
GIFLoader - simple GIF support for iOS
//
// GIFLoader.h
// AnimatedGifExample
//
// Created by Andrei on 10/15/12.
// Copyright (c) 2012 Whatevra. All rights reserved.
//
#import <Foundation/Foundation.h>
@greyspot09
greyspot09 / NSRange.swift
Created October 20, 2015 09:44
A better Swift NSRange
// Playground - noun: a place where people can play
import Cocoa
extension NSRange {
init(location:Int, length:Int) {
self.location = location
self.length = length
}
@greyspot09
greyspot09 / list_properties.swift
Created November 3, 2015 03:32 — forked from huandu/list_properties.swift
List properties of a swift class.
import Foundation
struct Point {
var x = 0.0
var y = 0.0
}
class PropertyHub {
var simpleProp = "Foo"
var structProp = Point()
@greyspot09
greyspot09 / file_path_test.sh
Created December 29, 2015 15:25 — forked from feng-ming/file_path_test.sh
unix shell 判断目录/文件是否存在, 以及是否有读写权限。
shell判断文件,目录是否存在或者具有权限
#!/bin/sh
Path="/var/log/httpd/"
File="/var/log/httpd/access.log"
#这里的-x 参数判断$Path是否存在并且是否具有可执行权限
if [ ! -x "$Path"]; then
mkdir "$Path"
fi
@greyspot09
greyspot09 / NSAttributedString+height.h
Created January 20, 2016 14:20 — forked from Yak0xff/NSAttributedString+height.h
NSAttributedString文字高度计算
#import <CoreText/CoreText.h>
@interface NSAttributedString (Height)
-(CGFloat)boundingHeightForWidth:(CGFloat)inWidth;
@end
import Foundation
extension String
{
var length: Int {
get {
return countElements(self)
}
}
@greyspot09
greyspot09 / Readme.md
Created February 25, 2016 04:38 — forked from loganwright/Readme.md
UIView Gesture Recognizer Extension For Swift

Interface for dealing with gesture recognizers via native swift closure syntax

import UIKit

class ViewController: UIViewController {
                            
    override func viewDidLoad() {
        super.viewDidLoad()
 view.addSingleTapGestureRecognizerWithResponder { (tap) -&gt; Void in
@greyspot09
greyspot09 / LICENSE
Created June 21, 2016 08:45 — forked from chriseidhof/LICENSE
A tiny networking library
Copyright 2015 Chris Eidhof
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHE

Videos