Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@TonnyXu
TonnyXu / NSURLConnection.md
Created June 7, 2012 09:57
NSURLConnection returns http response status code 200 even the underlying response is 304

Overview

NSURLConnection is really a complex and convenient class for handling low level connections. Usually, you use NSURLConnection class to establish an FTP/HTTP/HTTPS/FILE connections and get data from remote servers or local files. NSURLConnection aimed to be flexible and handy for some common tasks like redirect/authentication/cache. Also, before iOS 4.0, it adopted delegate design pattern, will send the request to remote server in separated thread automatically.

Let's talk about cache

  1. NSURLConnection provide both on-disk and in-memory cache.
  2. There are two types of cache: local cache and remote cache.
  3. Setting cache policy when create a NSURLRequest instance is ONLY for local cache.
  4. Currently only responses to HTTP and HTTPS are cached.
@TonnyXu
TonnyXu / studyMemo.md
Created May 24, 2012 07:21
2012-05-24 iOS Sample Code Study Group

NSCache, NSURLCache, NSCachedResponse in Fundation.framework

NSCache

  • Is an in memory cache mechanism
  • Just like NSMutableDictionary
  • Available when iOS > 4.0
  • Can be set with a limit

See Document for more information.

@TonnyXu
TonnyXu / textShadow_in_UITabBar.m
Created May 10, 2012 13:27
How to set text shadow to the text in UITabBar?
//...
[self.tabBarController.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem *aTabBarItem, NSUInteger idx, BOOL *stop) {
NSString *selectedImageName = [NSString stringWithFormat:@"tab_icon%d_27x27_selected", idx+1];
NSString *unselectedImageName = [NSString stringWithFormat:@"tab_icon%d_27x27", idx+1];
[aTabBarItem setFinishedSelectedImage:[UIImage imageNamed:selectedImageName]
withFinishedUnselectedImage:[UIImage imageNamed:unselectedImageName]];
[aTabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[[UIColor blackColor] colorWithAlphaComponent:0.5], UITextAttributeTextShadowColor,
@TonnyXu
TonnyXu / UITableView_SeparatorLine.md
Created May 10, 2012 13:21
set UITableView.separatorLine to 2px and with different colors each pixel

Question

How to implement a UITableView with a separator line like this:

doubly separator line

Usually, you can only set the separatorLine property of a UITableView with to single line or single line etched. Sometimes, it is not enough. So, how to implement a separator line like this?

Answer

@TonnyXu
TonnyXu / diff.diff
Created March 24, 2012 07:13
mixi API SDK for iOS V1.3.2 vs V1.3.3
diff -r mixiIOSSDK-1.3.2/History.txt mixiIOSSDK-1.3.3/History.txt
0a1,3
> v1.3.3 2012-03-15
> - 不具合修正(UserDefaults)
>
diff -r mixiIOSSDK-1.3.2/README.markdown mixiIOSSDK-1.3.3/README.markdown
62c62
< <tr><td><a href="http://developer.mt.mixi.co.jp/connect/appli/spec/ios/download/mixiIOSSDK-1.3.2.zip">mixiIOSSDK-1.3.2.zip</a></td><td>v1.3.2</td><td>600KB</td><td>2012-03-01</td></tr>
---
> <tr><td><a href="http://developer.mt.mixi.co.jp/connect/appli/spec/ios/download/mixiIOSSDK-1.3.3.zip">mixiIOSSDK-1.3.3.zip</a></td><td>v1.3.3</td><td>600KB</td><td>2012-03-15</td></tr>
@TonnyXu
TonnyXu / UIImage.imageOrientation.md
Created March 22, 2012 03:17
UIImageのimageOrientationについて

UIImage has a property named imageOrientation

See Apple's documentation: imageOrientation

What's the header looks like?

typedef enum {
 UIImageOrientationUp, // default orientation
@TonnyXu
TonnyXu / strongRetain.md
Created February 17, 2012 09:34
The difference between Strong and Retain

A wired compiler error

Have you ever seen a compiler error like:

error: expected a property attribute before 'strong'

I met one today. The same code was compiled and worked fine in my iPhone project but another similar iPad version could not pass the compilation. WTF? After googling it. I found the reason.

Solution

@TonnyXu
TonnyXu / CLRS_QuickSort.m
Created February 9, 2012 17:13
Randomize Quicksort
//
// QuickSort.c
// algorithms-iOS
//
// Created by Tonny Xu on 2/6/12.
// Copyright (c) 2012 Tonny Xu. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
@TonnyXu
TonnyXu / BubbleSort.m
Created February 3, 2012 15:58
Bubble Sort
//
// CLRS_BubbleSort.c
// algorithms-iOS
//
// Created by Tonny Xu on 2/2/12.
// Copyright (c) 2012 Tonny Xu. All rights reserved.
//
#include <stdio.h>
#include <sys/time.h>
@TonnyXu
TonnyXu / Description.md
Created February 3, 2012 10:03
Make the UITableView with group style to round the image.

The point is, the roundCorner is draw by a subview of UITableViewCell, and mean while, it's not a public class, there is no way you can get layer.cornerRadius from any view. So we need to resolve this problem by ourselves.

There are 2 cases.

  1. There is only one cell.

    This case is ease, just use cell.contentView.layer.cornerRadius and cell.contentView.layer.masksToBounds to make it work.

  2. There are more than one cell.