Translate

顯示具有 Objective-C 標籤的文章。 顯示所有文章
顯示具有 Objective-C 標籤的文章。 顯示所有文章

2014年12月16日 星期二

Objective-C Math functions

常常忘記objective-c的數學運算式
特地寫一下記錄

• pow(x,y) : x 的 y 次方
• sqrt(x) : x的平方根
• floor(x) : 小於 x 的最大整數
• ceil(x) : 大於 x 的最小整數
• exp(x) : e 的 x 次方
• log(x) : 以 e 為底 x 的對數值
• log10(x) : 以10為底 x 的對數值
• abs(x) : 整數 x 的絕對值
• fabs(x) : 浮點數 x 的絕對值
• srand(x), rand() : 產生亂數

參考1
參考2
參考3

2013年4月14日 星期日

objective-c type

今天在查objective-c的資料形態
發現一個網站介紹的很仔細
參考網站
主要是為了要查long long怎麼format
我個人只有用過每個format的第一種方法
另外id的format我是都用%@

2012年5月29日 星期二

Objective-C make short url

使用Client來作short url
目前我有找到三個
最基本最簡單的為http://tinyurl.com/

做法很簡單

NSString *link = [NSString stringWithFormat:@"http://tw.yahoo.com/"];
NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:@"http://tinyurl.com/api-create.php?url=%@", link]];
NSString *link_shorten = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:nil];
NSLog(@"link_shorten is %@",link_shorten);



再來是google的服務


請上git下載原作者開源碼

用法


GSUrl *url = [[GSUrl alloc] initWithString:@"http://tw.yahoo.com/"];
NSLog(@"[url shorten] is %@",[url shorten]);

好處是可以再解析短網址還原長網址內容
# GSUrl

Google URL Shortener in Objective-C

I create this class for my studies in Objective-C

## Usage
    GSUrl *url = [[GSUrl alloc] initWithString:@"www.someurlhere.com"];
    [url shorten]; // => http://goo.gl/aGf9V

## Json
  I use [json-framework]("http://stig.github.com/json-framework") for parser.

## TODO
- Expand a short URL
- Look up a short URL's analytics
- Look up a user's history




最最最複雜的是

用法
MKBitlyHelper *bitlyHelper = [[MKBitlyHelper alloc] initWithLoginName:@"yourlogin" andAPIKey:@"yourapi"];
NSString *shortURL = [bitlyHelper shortenURL:@"http://mugunthkumar.com"];
NSString *longURL = [bitlyHelper expandURL:shortURL];

因為本人英文不好所以也沒去申請網頁申請

bit.ly的服務如果有人知道如何申請

請告訴我詳細步驟謝謝

2012年5月28日 星期一

Objective-C 取亂數arc4random()

本身我自己是使用arc4random()來取亂數

因為使用rand()亂數會發現每次從新執行應用程式會取得的數值都是一樣的