자료실 2020. 4. 15. 08:46

컴포넌트.zip
0.03MB

 

posted by 핵커 커뮤니티
:
SQL 2020. 4. 14. 19:28

JOIN 의 개념

서로 다른 테이블을 공통 컬럼을 기준으로 합치는(결합하는) 테이블 단위 연산

조인의 결과 테이블은 이전 테이블의 컬럼 수의 합과 같다.

SELECT * FROM 테이블 1 JOIN 테이블 2 ON 테이블1.컬럼명 = 테이블2.컬럼명 ...

조인 시 서로 다른 테이블에 같은 컬럼명이 존재하면 구분을 위해 테이블명.컬럼명으로 사용해서 표시

 

예제

- city 테이블과 country 테이블을 조인하시오. (city.CountryCode = country.Code)

- 국가코드와 해당 나라의 GNP 를 표시하시오

 

결과 확인

- SELECT * FROM city JOIN country ON city.CountryCode = country.Code;

- SELECT city.CountryCode, country.GNP FROM city join country ON

city.CountryCode = country.Code;

 

 

 

 

 

 

JOIN 의 종류

조인 시 NULL 값을 허용하는 내부 조인(불가)과 외부조인(허용)으로 구분

INNER JOIN / LEFT JOIN / RIGHT JOIN / FULL JOIN

 

INNER JOIN

조인 시 NULL 값을 허용하지 않음

(NULL 값을 가진 레코드는 조인결과에 빠짐)

LEFT JOIN

조인 시 JOIN 의 왼쪽 테이블의 NULL 값을 포함해서 표시

RIGHT JOIN

조인 시 JOIN 의 오른쪽 테이블의 NULL 값을 포함해서 표시

FULL JOIN

MySQL 은 지원하지 않음

 

 

예제

- city 테이블에 국가코드가 없는 도시가 있는지 확인

- country 테이블에는 존재하지만 도시가 하나도 없는 나라가 있는지 확인

- 이 때 INNER JOIN / LEFT JOIN / RIGHT JOIN 의 차이점으로 확인

 

결과 확인

- SELECT COUNT(*) FROM city WHERE CountryCode is NULL;

- SELECT COUNT(*) FROM city LEFT JOIN country ON city.CountryCode = country.Code;

(country 값이 존재하지 않는 city 는 포함)

- SELECT COUNT(*) FROM city RIGHT JOIN country ON city.CountryCode = country.Code;

(country 중 도시 수가 하나도 없는 country 는 포함)

 

 

 

 

 

 

별명(ALIAS)

SQL 쿼리 결과 생성 시 컬럼명에 대한 별명을 사용해 표시하는 기능

SELECT 테이블명1.컬럼명1 AS 별명1, 테이블명2.컬럼명2 AS 별명2 FROM ....

조인할 때 많이 사용된다

 

예제

- city 테이블과 country 테이블을 조인해서 국가코드 'KOR' 인 나라의 축약표시명(Abbr) 과 정식명(Full Name)을 표시하시오

 

결과 확인

- SELECT city.CoutryCode AS Abbr, country.Name AS FullName FROM city JOIN country on city.CountryCode = country.Code WHERE city.CountryCode = 'KOR';

 

 

 

 

뷰 (VIEW)

SQL 쿼리의 결과값을 임시 테이블로 저장해서 사용할 수 있음

사용 용도가 끝나면 명시적으로 삭제해야 함 (DROP VIEW ....)

CREATE VIEW 뷰명 AS SELECT ...

 

예제

CREATE VIEW sampleView AS SELECT city.CountryCode AS Abbr, country.Name AS FullName FROM city JOIN country ON city.CountryCode = country.Code WHERE city.CountryCode = 'KOR';

SELECT * FROM sampleView;

posted by 핵커 커뮤니티
:
SQL 2020. 4. 14. 19:18

DISTINCT 연산자

SELECT 문의 결과 값에서 특정 컬럼만 출력할 경우 중복된 값들이 나오는 경우에 이를 제거해서 표시하는 기능

SELECT DISTINCT 컬럼명 1, 컬럼명 2, ... FROM 테이블명

 

예제

- 국가코드가 'KOR' 인 도시들의 국가코드를 표시하시오.

- 국가코드가 'KOR' 인 도시들의 국가코드를 중복제거해서 표시하시오.

 

결과 확인

- SELECT CountryCode FROM city WHERE CountryCode = 'KOR';

- SELECT DISTINCT CountryCode FROM city WHERE CountryCode = 'KOR';

 

 

 

 

논리연산자 (AND, OR, NOT)

SELECT 문의 조건절에 논리 조건 적용해서 적용할 수 있는 연산자

SELECT * FROM 테이블명 WHERE (NOT) 조건 1 AND/OR (NOT) 조건 2 ..... 

 

예제

- 국가코드가 'KOR' 이면서 인구가 100만 이상인 도시를 찾으시오

- 국가코드가 'KOR', 'CNN', 'JPN' 인 도시를 찾으시오

- 국가코드가 'KOR' 이 아니면서 인구가 100만 이상인 도시를 찾으시오.

 

 

 

결과 확인

- SELECT * FROM city WHERE CountryCode = 'KOR' AND Population > 1000000

- SELECT * FROM city WHERE CountryCode = 'KOR' OR CountryCode = 'CNN' OR CountryCode = 'JPN'

- (위와 같은 코드) SELECT * FROM city WHERE CountryCode in ('KOR', 'CNN', 'JPN')

 

- SELECT * FROM city WHERE CountryCOde != 'KOR' AND Population > 1000000

posted by 핵커 커뮤니티
:
SQL 2020. 4. 14. 19:17

SQL (Structured Query Language) :

     - 관계형 데이터베이스에서 사용하는 표준 질의언어를말한다.

     - 사용 방법이나 문법이 다른 언어(Java, C, C#, Java)보다 단순하다.

     - 모든 DBMS에서 사용 가능하다.

     - 인터프리터 언어

     - 대소문자 구별하지 않는다.

 

 

 

DML :

     - 데이터베이스의 테이블에 있는 내용을 직접 조작하는 기능

     - 테이블의 레코드를 CRUD (Create, Retrieve, Update, Delete)

 

SQL 문

내용

insert

데이터베이스 객체에데이터를 입력

delete

데이터베이스 객체에데이터를 삭제

update

데이터베이스 객체 안의데이터 수정

select

데이터베이스 객체 안의데이터 조회

 

 

DDL :

     - 데이터베이스의 스키마를 정의, 생성, 수정하는 기능

     - 테이블 생성, 컬럼 추가, 타입 변경, 각종 제약조건 지정,수정 등

 

SQL 문

내용

create 

데이터베이스 객체를생성

drop

데이터베이스 객체를삭제

alter

기존에 존재하는데이터베이스 객체를다시 정의

 

 

DCL :

     - 데이베이스의 테이블에 접근 권한이나 CRUD 권한을 정의하는기능

     - 특정 사용자에게 테이블의 조회권한 허가 / 금지 등

 

SQL문

내용

grant

데이터베이스 객체에권한을 부여

revoke

이미 부여된데이터베이스 객체권한을 취소

 

CRUD (Create, Retrieve, Update, Delete) :

이름

조작

SQL

create 

read (retrieve)

생성

읽기 (인출)

insert

select

update

갱신

update

delete (destroy)

삭제 

delete

 

     Create : 데이터베이스 객체 생성     

          - insert into

          - 새로운 레코드를 추가

 

     Update : 데이터베이스 객체 안의 데이터 수정

          - update     

          - 특정 조건의 레코드의 컬럼 값을 수정

 

Delete : 데이터베이스 객체의 데이터 삭제

     - delete     

     - 특정 조건의 레코드를 삭제

 

Retrieve : 데이터베이스 객체 안의 데이터 검색

     - select     

     - 조건을 만족하는 레코드를 찾아 특정 컬럼 값(모두표시 *)을 표시

 

 

 

 

select 명령문 :

select 컬럼명 from 테이블명 where 조건절;

 

- "world" DB에서의 쿼리 예제

국가 코드가 'KOR' 으로 되어 있는 도시들의 이름을구하시오

select Name from city where CountryCode='KOR';

 

인구가 500만 이상인 도시들의 이름을 구하시오

select Name from city where Population > 5000000;

 

 

insert into 명령문 : 

insert into 테이블명 (컬럼명) values (값);

 

- 예제

# 각각의 필드와 대응 시켜줘서 insert 를 시켜주어야한다.

insert into city (ID, Name, CountryCode, District, Population) values (10000, "Sample", "KOR", "Test", 1000000);

 

# 이 경우에는 모든 컬럼 값들이 일일히 필드와대응되면 생략 가능

insert into city values (20000, "SampleTest", "KOR", "Test", 2000000);

 

- 결과 확인

# ID 가 100000 인 레코드 출력

select * from city where ID = 20000;

 

# ID 가 200000 인 레코드 출력

select * from city where ID = 10000;

 

 

 

 

update 명령문 : 

update 테이블명 set 컬럼명=값, ..... where 조건절;

 

- 예제

# ID 가 10000 인 레코드의 name 을"SampleRevised" 로 변경

update city set name = "SampleRevised" where id = 10000;

 

- 결과 확인

# ID 가 100000 인 레코드 출력

select * from city where ID = 10000;

 

 

delete 명령문 :

delete from 테이블명 where 조건절;

 

- 예제 

# ID 가 20000 이며 Population 이 2000000 인레코드를 삭제

delete from city where (ID = 20000) AND (Population = 2000000);

 

# ID 가 10000 이며 Population 이 1000000 인레코드를 삭제

delete from city where (ID = 10000) AND (Population = 1000000);

 

- 결과 확인

# ID 가 100000 인 레코드 출력

select * from city where ID = 10000;

 

# ID 가 200000 인 레코드 출력

select * from city where ID = 20000;

'SQL' 카테고리의 다른 글

[SQL] JOIN VIEW,별명알아보자  (0) 2020.04.14
[SQL] 일부결과 및 집합함수  (0) 2020.04.14
[SQL] 연산 논리 (기초 배우기 )  (0) 2020.04.14
[SQL] 설치하기 / 다운로드  (0) 2020.04.11
posted by 핵커 커뮤니티
:
PHP 2020. 4. 14. 19:07

[PHP]함수의 인수

함수 안에서 사용하는 값을 함수 밖에서 전달할 수 있는데 이 값을 인수라고 한다.

-예

<?php

function check($age) {

$result = (20 <= $age)?"프로":"그래밍";

print $result."입니다.";

}

check(19);

?>

-결과

​프로그래밍

 

인수가 지정되지 않은 경우(에러가 발생한다.)

- 예

<?php

function check($age) {

$result = (20 <= $age)?"프로":"그래밍";

print $result."입니다.";

}

check();

?>

- 결과(에러 발생)

Fatal error: Uncaught ArgumentCountError: Too fewargumenC:/ xampp/hydocs/for:php:

2 Stack trace: #0 C:xampp/hidocs/for

인수에 값이 없는 경우 에러가 발생하므로 인수의 기본값을 사용한다.

-예

<?php

function check($age=19) {

$result = (20 <= $age)?"프로":"그래밍";

print $result."입니다.";

}

check();

?>

 

- 결과(에러가 발생하지 않았다.)

프로그래밍

 

<?php

function test($x1, $x2)(

echo '*'.$x1.$x2.'*';

)

test('핵','커');

?>

결과는 *핵커*

'PHP' 카테고리의 다른 글

[PHP] PHP 문자 N 문자를 연결해보자!  (0) 2020.04.14
[PHP] PHP 함수 생성 및 호출  (0) 2020.04.14
[PHP] PHP 다운로드  (0) 2020.04.14
[PHP] 시작,종류,태그,변수,저장확정자  (0) 2020.04.11
posted by 핵커 커뮤니티
:
PHP 2020. 4. 14. 19:05

[PHP]문자와 문자를 연결하기

php에서는 문자와 문자를 연결시 + 대신에 .를 사용한다.

-입력

<?php

echo "*"."아이유";​

?>

-출력

아이유

 

html을 포함한 경우

-줄바꿈이 가능하다.

-입력

​<?php

echo "*"."아이"."</br>"."유2";

?>

-출력

결과

아이유

입력1

<?

$test = "너 ";

$test.= "랑";

$test.= "나";

print $test;

?>

결과

너 랑 나

'PHP' 카테고리의 다른 글

[PHP] PHP 함수의 인수 배우보자!!!  (0) 2020.04.14
[PHP] PHP 함수 생성 및 호출  (0) 2020.04.14
[PHP] PHP 다운로드  (0) 2020.04.14
[PHP] 시작,종류,태그,변수,저장확정자  (0) 2020.04.11
posted by 핵커 커뮤니티
:
PHP 2020. 4. 14. 19:03

[PHP]함수 생성 및 호출

다음은 모두 같은 의미이다.

- 작은 프로그램의 모음

- 서브루틴

- 사용자 정의 함수

사용자 정의 함수를 사용하면 같은 내용을 여러 번 사용할 때 간단히 함수를 불러오면 되서 편리하다.

정의

- function 함수명() {

​ 처리 내용;

}

사용

- 함수명();

* 함수의 정의와 함수의 사용 순서는 상관없다.

​예

<?php

function copyright() {

print "<font size=7>";

print "copyright all right reserved";

print "</font>";

}

copyright();

?>

<?php

fuction test()(

echo 1;

)

test();

?>

함수 실행 예1

<?php

test($x)(

echo $x;

)

test('hello world');

?>

함수 실행 예2

<?php

test($x)(

echo $x;

)

test('hello world');

test('hello jeju');

?>

함수 실행 예3

<?php

test($x)(

echo $x;

)

test('hello');

test('mr my);

test('yesterday);

?>

posted by 핵커 커뮤니티
:
Objective_C 2020. 4. 14. 18:52

9.파운데이션 프레임워크

9-1.루트 클래스

NSObject는 Objective-C의 클래스가 가져야 할 가장 기본적인 기능(메모리 관리, 객체 식별 등)을 제공하며,모든 클래스는 NSObject를 직접 혹은 간접적으로 상속함으로써 그 기능들을 사용할 수 있게된다. 사용자가 직접 구현하는 클래스도 이를 위해 NSObject를 상속하는 것을 절대 잊지말아야한다.

 

9-2.문자열 관련 클래스

9-2-1.NSString

유니코드 방식으로 문자열을 다루는 기능을 제공하는 클래스,. 파운데이션 프레임워크에서 가장 많이 사용되는 클래스

-기본사용방법 : 문자열 앞에 항상 '@'를 붙여주어야한다. NSString *string = @"string test";

-포맷표현 방식 : 다른언어의 %s가 아니라 %@사용한다. 나머지 타입은 같다(%d,%f,%u)

NSString *string1 = [[NSString alloc]initWithFormat:@"%@",@"string"];

NSStirng *string2 =[NSString stringWithString:@"string"];

-생성 메소드 : 클래스 메소드는 alloc 또는 copy로 시작하는 이름을 갖지 않으므로 사용이 끝난 후 release할 필요없다.

인스턴스 메소드들은 alloc 메소드를 이용하여 생성되므로, 사용이 끝난 후에는 반드시 release를 호출해야한다.

//빈 문자열을 가지는 객체를 생성하여 반환

+(id)string

//주어진 문자열을 가지는 객체를 생성하여 반환

+(id)stringWithFormat:(NSString *)format, …

+(id)stringWithString:(NSString *)aString;

//위 메소드들의 인스턴스 메소드 형태, 기능은 동일

-(id)initWithFormat:(NSString *)format …

-(id)initWithString:(NSString *)aString

//사용예

NSString *string1 = [NSString string];

NSString *string2 = [NSString stringWithFormat:@"String: %@", @"Test"];

NSString *string3 = [NSString stringWithString:@"String"];

NSString *string4 = [[NSString alloc] initWithFormat:@"String : %@",@"Test"];

NSString *string5 = [[NSString alloc] initWithString:@"String"];

-결합메소드

//현재 문자열과 주어진 문자열을 결합하여 반환

-(NSString *)stringByAppendingFormat:(NSSting *)format …

-(NSString *)stringByAppendingString:(NSString *)aString

//사용예

NSString *string1 = @"Hello"

NSString *string2 = [stirng1 stringByAppendingFormat:@"%@",@"World"];

NSString *string3 = [stirng1 stringByAppendingString:@" World"];

-분리 메소드

//현재 문자열을 검사하여 주어진 문자열이 나타낼 때마다 문자열 분리

-(NSArray *)componentsSeparatedByString:(NSString *)separator

//현재 문자열의 주어진 위치 이후 문자열 반환

-(NSString *)substringFromIndex:(NSUInteger)anIndex

//현재 문자열의 주어진 위치까지의 문자열 반환

-(NSString *)substringToIndex:(NSUInteger)anIndex

 

//사용예

NSString *string1 = @"String1, String2, String3";

NSArray *iterms =[string1 componentsSeparatedByString:@". "];

//ite는 :{@"String1", @"String2", @"String2"}

NSString *string2 =@"String";

NSString *string3 =[string2 substringFromIndex:3];

NSString *string4 =[string2 substringToIndex:3];

//string 2: @"ing" string 4:@"str"

-값 변환 메소드

//현재 문자열에 해당하는 정수값 반환

-(int)intValue

//현재 문자열에 해당하는 실수값 반환

-(float)floatValue

-(double)doubleValue

//사용예

NSString *string1 =@"5";

int intValue =[string1 intValue]; //intValue : 5

NSString *string2 =@"2.34";

float floatValue = [string2 floatValue]; //2.34

double double Value = [string2 doubleValue]; //2.34

-비교 메소드

//현재 문자열이 주어진 문자열로 시작하는지 검사

-(BOOL)hasPrefix:(NSString *)aString

//현재 문자열이 주어진 문자열로 끝나는지 검사

-(BOOL)hasSuffix:(NSString *)aString

//현재의 문자열이 주어진 문자열과 동일하지 검사

-(BOOL)isEqualToString:(NSString *)aString

//사용예

NSString *string1 = @"Hello World!";

BOOL value1 = [string1 hasPrefix:@"Hel"];

BOOL value2 = [string1 hasSuffix:@"orld"]; //value1,value2 :YES

BOOL value3 = [string1 isEaualToString:@"Hello World!"]; //value3 :YES

-기타 메소드

//문자열의 길이를 반환

-(NSUInteger)length

//문자열읮 ㅜ어진 위치에 해당하는 문자를 반환

-(unichar)characterAtIndexLNSUInteger)index

//사용예

NSString *string = @"String";

int length = [string length]; //length :6

unichar value = [string characterAtIndex:3]; //value : i

9-2-2.NSMutableString

NSString 클래스를 상속하는 자식 클래스, 문자열을 한번 할당하면 변경할 수 없는 NSString과는 달리 수정할 수 있다는 것이 장점, 참고로 파운데이션 프레임워크 클래스 중에서 이름에 Nutable이 포함된 클래스 (NSMutableArray, NSMutableDictionary 등)는 값을 수정할 수 있는 클래스다,.

 

//주어진 문자열을 현재의 문자열과 결합

-(void)appendFormat:(NSString *)format ..

-(void)appendFormat:(NSString *)aString

//주어진 문자열을 현재 문자열의 주어진 위치에 사입

-(void)insertString:(NSString *)aString atIndex:(NSUInteger)anIndex;

//현재의 문자열을 주어진 문자열로 대체

-(void)setString:(NSString *)aString

//사용예

NSMutableString *string. = [NSmutableString stringWithString:@"Hello"]; //String :@"Hello"

[string appendFormat:@"%@",@"Wor"]; //String :@"Hellowor"

[string appendString:@"ld!"] //string: @"Helloworld!"

[string insertString:@" " atIndex:5]; //string: @"Hello world!"

[string setString:@"Bye World!"]; //string: @"Bye World!"

 

9-3.객체 집합 관련 클래스

NSArray : 순서가 있는 객체 리스트를 관리

NSDictionary : 키 – 값 형태의 객체 리스트를 관리

NSSet : 순서가 없는 객체 리스트를 관리

위는 할당된 내용을 수정할 수 없는 클래스지만. 이들 클래스 이름에 Mutable이 들어간 MSMutableArray, NSMutableDictionary, NSMutableSet는 수정할수 있는 클래스이다.

 

9-3-1.NSArray

-생성메소드

//사용예

NSDate     *aDate = [NSDate distantFuture];

NSValue     *aValue = [NSNumber numberWithInt:5];

NSString     *aString = @"a string";

// +(id)arrayWithObjects : 주어진 객체들을 포함하는 객체를 생성하여 반환

NSArray *array1 = [NSArray arrayWithObjects:aData, avalue, aString, nil]; //마지막은 반드시 nil을 전달

// -(id)initWithObjects : arrayWithObjects의 인스턴스 메소드 형태, 기능은 동일

NSArray *array2 = [[NSArray alloc]initWithObjects:aData, aValue, aString, nil]; //마지막은 반드시 nil을 전달

//+(id)arrayWithArray: 주어진 배열 내의 인자들을 포함하는 객체를 생성하여 반환

NSArray *array3 = [NSArray arrayWithArray: array1];

//-(id) initWithArray : +arrayWithArray의 인스턴스 메소드 형태 기능은 동일

NSArray *array4 = [[NSArray alloc] initWithArray: array1];

주요메소드

NSString *item1 = @"1", *item2 = @"2", *item3=@"3";

NSArray *array = [NSArray arrayWithObjects: item1, item2, item3, nil]; //array :{item1, item2, item3}

//주어진 배열 내의 인자의 수를 반환

int cout : [array count]; //count :3

//주어진 인덱스의 객체를 반환

NSString *string = [array objectAtIndex:1]; //string :@"2"

//주어진 객체의 배열 내의 인덱스를 반환

NSUInteger index = [array indexOfbject :item3]; //index:2

 

9-3-2.NSMutabelArray

NSString *item1 = @"1", *item2 = @"2", *item3=@"3", *item4=@"4";

NSMutableArray *array =[NSMutableArray arrayWithObjects: item1, item2, item3, nil]; //array :{item1, item2, item3}

//주어진 인자를 지정된 위치에 삽입한다.

[array insertObject:item4 atIndex:2]; ////array :{item1, item2,item4, item3}

//지정된 위치의 인자를 삭제한다.

[array removeObjectAtIndex:3]; ////array :{item1, item2,item4}

//주어진 인자를 배열 끝에 추가한다.

[array addObject:item3]; // array :{item1, item2,item4,item3}

//마지막 인자를 삭제한다.

[array removeLastObject]; // array :{item1, item2,item4}

//현재 배열의 지정된 위치의 객체를 주어진 객체로 대체한다.

[array replaceObjectAtIndex:2, withObject:item3]; // array :{item1, item2,item3}

 

9-3-3.NSDictionary –stl의 map

-생성메소드

//+(id) dictionaryWithObjectsAndKeys: 주어진 객체, 키 값으로부터 객체를 생성반환

NSDictionary *dict1 = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2",nil];

//-(id) initWithdictionaryWithObjectsAndKeys:+(id) dictionaryWithObjectsAndKeys의 인스턴스 메소드 형태

NSDictionary *dict2 = [[NSDictionary alloc] initWithdictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2",nil];

-주요메소드

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"Chris", @"name", @"programmer", @"job",nil]; //dirct :{@"job" : @"programmer", @"name :@"Chris"}

//dictionary에 있는 객체의 수를 반환

NSUInteger count = [dict count]; //count :2;

//dictionary에 있는 모든 키 값들을 반환

NSArray *keys= [dict allKeys]; //Keys:{@"job",@"name"};

//dictionary에 있는 모든 객체들을 반환

NSArray *values = [dict allValues]; values :{@"programmer",@"Chris"}

//주어진 키 값을 갖는 객체를 반환

NSString *string = [dict objectForKey:@"name"]; //string : @"Chris"

9-3-4.NSMutableDictionary

NSMutableDictionary *dict =[NSMutableDictionary dictionary]; //Dict: { }

//주어진 객체와 키 조합을 추가한다.

[dict setObject:@"Chris" forKey:@"name"]; //dict:{@name: @"chris"}

[dict setObject:@"programmer" forKey:@"job"]; //dict: {@"job": @"programmer", @"name" : @"Chris"}

//주어진 객체와 키 조합을 삭제

[dict removeObjectForKey:@"name"]; //dict : {@"job" : "programmer"};

//모든 객체-키 조합 삭제

[dict removeAllObjects];//dict:{ }

9-3-5.NSSet –NSArray와 달리 순서가 없다.

-생성메소드

NSDate *aDate = [NSDate distantFuture];

NSValue *aValue = [NSNumber numberWithInt:5];

NSString *aString = @"a string";

//주어진 객체들을 포함하는 객체를 생성하여 반환

NSSet "mySet =[NSSet setWithObjects:aDate, aValue, aString, nil];

// NSSet "mySet =[[NSSet alloc]initWithObjects:aDate, aValue, aString, nil];

-주요메소드

NSDate *aDate = [NSDate distantFuture];

NSValue *aValue = [NSNumber numberWithInt:5];

NSString *name = @"Chris";

NSSet *mySet =[NSSet setWithObjects: date, value, name, nil]; //mySet :{value, name, date}

//NSSet 에 들어있는 오브젝트 객체 개수

NSUInteger count =[mySet count]; //count :3

//NSSet에 들어있는 모든 오브젝트 객체 반환

NSArray *array1 = [mySet allObjects]; // array1 : {value, name, date;

//NSSet 내에 주어진 객체가 존재하는지 검사하여 결과 반환

BOOL result = [mySet containsObject:@"Chris"]; //result :YES

9-3-6 NSMutableSet

NSDate *aDate = [NSDate distantFuture];

NSValue *aValue = [NSNumber numberWithInt:5];

NSString *name = @"Chris", *job = @"programmer";

NSMutableSet *mySet =[NSMutableSet setWithObjects: date, value, name, nil]; //mySet :{value, name, date}

//set에 주어진 객체를 추가

[mySet addObject:job]; //mySet :{job, value, name, date}

//set에 주어진 객체 삭제

[mySet removeObject:@"Chris"]; //mySet :{job, date,value}

//set의 모든 객체 삭제

[mySet removeAllObjects]; //mySet: {}

9-3-7 객체 탐색

-객체를 탐색하는 예

NSArray *array = [NSArray arrayWithObjects:@"One",@"Two", @"Three", @"Four", nil];

NSString *item = nil;

for( item in array){

if([item isEqualToString:@"Three"]){

break;

}

}

-NSEnumerator를 사용하는 방법

NSArray *array = [NSArray arrayWithObjects:@"One", @"Two", @Three", @"Four", @nil];

NSString *item = nil;

NSEnumerator *enumerator = [array objectEnumerator];

 

while(item = [enumerator nextObject]){

if( [item isEqualToString:@"Three"]){

break;

}

}

NSEnumerator 사용하면 좋은예

NSArray의 경우 reverseEnumerator 메소드를 이용하여 객체를 역순으로 탐색 할수 있다.

objectEnumerator 대신에 reverseEnumerator 메소드를 호출하면 된다.

NSDictionary의 경우 NSEnumerator를 이용하면 키 값뿐 아니라 객체도 탐색할 수 있다. 키 값을 탐색할때는 KeyEnumerator 메소드, 객체 값을 탐색할때는 objectEnumerator를 이용하면 된다

 

9-4. 값(정수 및 실수)표현 관련 클래스

9-4-1.NSNumber

NSValue 클래스를 상속하는 자식 클래스, BOOL, char, int, float와 double 등 각종 값을 설정하고 반환하는 기능을 수행한다.

NSNumber *boolNumber = [NSNumber numberWithBool:YES];

NSNumber *intNumber = [NSNumber numberWithInt:23];

NSNumber *doubleNumber = [NSNumber numberWithDouble:23.46];

BOOL     value1 = [boolNumber boolValue];

int     value2 = [intNumber intValue];

double     value3 = [doubleNumber doubleValue];

//값비교

NSNumber *intNumber = [NSNumber numberWithInt:23];

NSNumber *floatNumber = [NSNumber numberWithFloat:3.45];

NSString *string1 = [intNumber stringValue]; //string1 : 23

if(NSOrderedAscending == [intNumber compare:floatNumber]{

}

BOOL equality = [intNumber isEqualToNumber:floatNumber];

 

//compare:메소드는 kemdarhk 같은 반환값을 가지게된다.

NSOrderedAscending    :현재 값보다 주어진 값이 클경우

NSOrderedDescending    :현재 값보다 주어진 값이 작은경우

NSOrderedSame        :현재 값과 주어진 값이 같은 

'Objective_C' 카테고리의 다른 글

[Objective-C] 기초배우기 (3)  (0) 2020.04.14
[Objective-C] 기초배우기 (2)  (0) 2020.04.14
[Obejective-C] 기초배우기 (1)  (0) 2020.04.13
posted by 핵커 커뮤니티
: