Algorithm2016.08.18 20:33
Solution.java


Solution2.java


저작자 표시 비영리 변경 금지
신고

'Algorithm' 카테고리의 다른 글

괄호매치문제 풀이  (0) 2016.08.18
Posted by NuBiFoRM
iPhone Dev.2013.04.25 00:09

NSURLConnection, NSURLConnectionDelegate 사용 예제

다음 코드는 야후 Weather API를 사용하여 데이터를 받아오는 것을 구현


Delegate 메소드

1)데이터 수신

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data


2)연결 오류

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error


3)연결 종료

- (void)connectionDidFinishLoading:(NSURLConnection *)connection


#pragma mark -

#pragma mark Custom Methods


- (void)loadData {

    NSLog(@"loadData");


    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];


    NSURL *weatherURL = [[NSURL alloc] initWithString:@"http://weather.yahooapis.com/forecastrss?w=2502265"];

    NSURLConnection *URLConnection = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:weatherURL] delegate:self];

    [URLConnection release];

    [weatherURL release];

}


#pragma mark -

#pragma mark NSURLConnectionDelegate


- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {

    NSLog(@"connection:didReceiveData:");


    if (receiveData == nil) {

        receiveData = [[NSMutableData alloc] init];

    }

    [receiveData appendData:data];

}


- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {

    NSLog(@"connection:didFailWithError:");


    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];


    [receiveData release];

    receiveData = nil;

}


- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

    NSLog(@"connectionDidFinishLoading:");


    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];


    NSString *receiveString = [[[NSString alloc] initWithData:receiveData encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingEUC_KR)] autorelease];


    NSLog(@"%@", receiveString);


    [receiveData release];

    receiveData = nil;

}


저작자 표시 비영리 변경 금지
신고
Posted by NuBiFoRM
iPhone Dev.2013.04.22 22:47

아래 화면과 같이 -DDEBUG=1 항목을 추가



프로젝트명-Prefix.pch 파일에 다음을 추가


#ifdef DEBUG

    #define NSLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )

#else

    #define NSLog( s, ... )

#endif


출처 : 아이군의 블로그

http://theeye.pe.kr/entry/upgrade-NSLog-only-working-debug-mode


저작자 표시 비영리 변경 금지
신고
Posted by NuBiFoRM
TAG Debug, nslog