NSImage與NSData之間轉換
NSData *imageData = [NSData
dataWithContentsOfFile: imagePath];
UIImage *aimage = [UIImage
imageWithData: imageData];
//UIImage-> NSData
NSData *imageData = UIImagePNGRepresentation(aimae);
隨機數
srandom(time(NULL));
產生 5 ------20
之間的一個隨機數
int n =
5 + (int) (20.0 * (random() / (RAND_MAX +
1.0)));
srand和rand官方已經不推薦使用。原因是產生隨機數的效能不是很好,
另外是隨機數的隨機性沒有random好,
再者就是不是安全執行緒。
NSLog(@"%@",NSStringFromSelector(_cmd));
前往模擬器調試下的程式目錄
/private/var/root/Library/Application Support/iPhone Simulator/5.1/Applications
讀取序列化檔案
NSString *resourcePath = [[NSBundle
mainBundle] resourcePath];
NSString *path = [[NSString
alloc]initWithFormat:@"%@/president.plist",resourcePath];
NSData *data = [[NSData
alloc]initWithContentsOfFile:path];
President *thePres = [NSKeyedUnarchiver
unarchiveObjectWithData:data];
儲存序列化檔案
NSString *resourcePath = [[NSBundle
mainBundle] resourcePath];
NSString *path = [[NSString
alloc]initWithFormat:@"%@/president.plist",resourcePath];
NSData *data = [NSKeyedArchiver
archivedDataWithRootObject:self.president];
if([data
writeToFile:path atomically:NO])
{
UIAlertView *alert = [[UIAlertView
alloc]initWithTitle:@"System"
message:@"儲存成功!" delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil,
nil];
[alert
show];
[alert
release];
}
訪問主控委託
AppDelegate *delegate = [[UIApplication
sharedApplication]delegate];
訪問主程式
UIApplication *app = [UIApplication
sharedApplication];
2)添加自訂的產生後指令碼
在Build Phases中添加一個Phase,右下角的Add
Build Phase,然後單擊Add Run Script,輸入以下指令碼
export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
if [ "${PLATFORM_NAME}" == "iphoneos" ]; then
/Developer/iphoneentitlements401/gen_entitlements.py "my.company.${PROJECT_NAME}" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent";
codesign -f -s "iPhone Developer" --entitlements "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/"
fi