2011년 6월 17일 금요일

.plist(property list) 데이터 입력과 읽기

Xcode 프로젝트에 .plist 파일을 추가한다. 
예제에서는 “data.plist”를 사용


다음으로 문서디렉토리에 .plist 경로를 생성한다.


NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
NSString *documentsDirectory = [paths objectAtIndex:0]; //2
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"data.plist"]; //3

NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path]) //4
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:@”data” ofType:@”plist”]; //5

[fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
}
1) 경로의 리스트를 생성
2) 리스트로부터 문서 경로를 가져온다.
3) 전체 경로를 생성.
4) 파일이 존재하는 지 체크.
5) 번들 디렉토리에 만들었던 문서의 경로를 가져온다.
6) document directory에 번들 파일 경로를 복사한다.
데이터 읽기:
NSMutableDictionary *savedStock = [[NSMutableDictionary alloc] initWithContentsOfFile: path];

//load from savedStock example int value
int value;
value = [[savedStock objectForKey:@"value"] intValue];
[savedStock release];

데이터 쓰기:


NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
//here add elements to data file and write data to file
int value = 5;
[data setObject:[NSNumber numberWithInt:value] forKey:@”value”];

[data writeToFile: path atomically:YES];
[data release]
두가지를 기억:

1)  Xcode project 에 문서를 생성.
2) 앱을 최적화하기 위해서는 app종료 혹은 뷰 종료시 모든 데이터를 저장한다. applicationWillTerminate 인스턴스에 추가. 대용량 데이터라면 이 방법은 사용하지 않는게 좋다. 앱 종료시 오래 걸리고 종종 강제 종료가 발생한다.


iphone simulator document 경로 _ 사용자 -> 라이브러리 -> application Support -> iPhone Simulator -> iOS버전 -> Applications - > 앱의 일련번호 

2011년 6월 16일 목요일

json parser YAJL 세팅


Installing in XCode 4 (iOS)

  • Add YAJLiOS.framework to your project.
  • In Build Phases, make sure its listed in Link Binary With Libraries, along with:
    • CoreGraphics.framework
    • Foundation.framework
    • UIKit.framework
  • In Build Settings:
    • Under Framework Search Paths make sure the (parent) directory to YAJLiOS.framework is listed.
    • Under Other Linker Flags in your target, add -ObjC and -all_load
  • Import with #import <YAJLiOS/YAJL.h>.

2011년 6월 14일 화요일

mysql 5.5.13 설치시 cmake


mysql 5.x부터 설치 방법이 변경되었다.
./configure가 없고 cmake를 이용. ( gcc , g++ 설치 필요)

   # cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DWITH_EXTRA_CHARSETS=all -DMYSQL_DATADIR=/usr/local/mysql/data -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DMYSQL_TCP_PORT=3306

# make && make install
# cp support-files/my-huge.cnf /etc/my.cnf            <---mysql 설정파일 복사
# cp support-files/mysql.server /etc/init.d/mysqld    <---mysql 실행데몬 복사     
# vi /etc/init.d/mysqld
--------------------------------------
datadir=/usr/local/mysql/data              
---------------------------------------
data디렉토리에서 파일 소유권을 mysql로 준다.
chown -R mysql:mysql *


# chmod 755 /etc/init.d/mysqld             <---mysql 데몬 실행 권한 부여
# chown -R mysql:mysql /usr/local/mysql              
# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data                             <---DB생성
# /etc/init.d/mysqld start                     <---mysql 구동 (시작)  또는 /usr/local/server/mysql/bin/mysqld_safe &
# chkconfig --add mysqld                    
# /usr/local/mysql/bin/mysqladmin -u root password 암호        

mysql.sock오류 발생시 파일 확인. ( mysql.sock은 유닉스 소켓연결시 사용. )
bin 폴더에서 
#mysql_config --socket


mysql_config 없다고 메세지 발생시.

#sudo apt-get install libmysqlclient-dev


# ln -s /usr/local/mysql/bin/mysql /usr/bin/                           <---링크
# ln -s /usr/local/mysql/bin/mysqldump /usr/bin/

 3) mysql 접속

# mysql -u root -p                 <---mysql 접속
------------------------------------------------------------------------------------
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.10-log Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
---------------------------------------------------------------------------------------

ubunt 명령어

yum -> apt-get

gcc-c++  -> g++

2011년 6월 12일 일요일

ubuntu 하드웨어 정보를 알려주는 명령어

sudo lshw -C network
sudo hwinfo --netcard

lshw라는 명령어는 기본적으로 설치되어 있고 

hwinfo라는 명령어는 추가 설치.

sudo apt-get install hwinfo


sudo lshw -C network |grep vendor
sudo hwinfo --netcard |grep Model <- 대소문자 구분.

ubuntu wifi


ubuntu 10.10으로 업그레이드한 후, 무선랜이 inactive인 경우의 해결책:

첫째, Terminal을 열고서

sudo rfkill unblock wifi 를 입력하고 엔터하면

네트워크 검색이 되면서 자동으로 무선 네트워크 검색함.

둘째, 상단 네트워크 연결에서 원하는 무선네트워크 연결 후,

아이콘을 마우스 오른쪽클릭(right-click)하고

edit connections선택

wireless 탭을 선택해서 연결한 네크워크 edit를 눌러준다.

팝업되는 창 하단의 available to all users를 틱해주고 apply하면 완료.

ubuntu 11 설치 _ 윈도우X 설치 및 콘솔모드 전환

$apt-get install xorg gdm
$/etc/init.d/gdm start


sudo vi /etc/default/grub 이후
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" // win x
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash text" // console