전체 글 34

[Objective-C] 클래스 구조(.h 와 .m) & 메소드

클래스 구조 Objective-C는 클래스 생성시 크게 선언부와 구현부으로 나뉜다 선언부 @interface ~ @end 주로 .h 파일에 구현 @interface ChildClass: ParentClass { // ------ 멤버 변수 선언 int count; NSString *myName; } // ------ 메소드 선언 /* - : Instance Method + : Class Method */ - (id)initWithString: (NSString *)aName; + (ChildClass)createChildClassWithString:(NSString*)aName; @end 구현부 @implementation ~ @end 주로 .m 파일에 구현 @implementation ChildClas..

iOS 2020.08.12

Objective-C와 Swift 비교

공통점과 차이점 - iOS SDK를 사용 - Low Level Virtual Machine(llvm) 컴파일러 사용 Objective-C Swift 앱 속도 런타임 코드 컴파일로 인해 속도가 느림 (C 함수 제외) 빠른 속도 (평균 Objective-C보다 2.6배 빠름) 컴파일 속도 빠름(앱 사이즈가 작음) 느림(앱 사이즈가 큼) 안정성 언어의 안정성 확보 꾸준히 버그가 수정되고 있음 (현재는 Swift 5.0가 최신버전) null 처리 null 포인터를 사용하며 작업 중단을 유발할 수 있음 옵셔널 타입 사용(null 관리 용이) 유지 보수 두개의 별도 파일(.h, .m) 관리 필요 하나의 파일(.swift)로 관리 구문 많은 기호, 선, 세미콜론, 괄호를 포함 (C언어와 유사) 영어 구문과 비슷(가독..

iOS 2020.08.12

[Objective-C] 컬랙션 클래스 NSArray, NSDictionary

NSArray, NSMutableArray 1. NSArray 기본 함수 arrayWithObjects: : init 함수(factory method) : 파라미터로 여러 개의 객체를 넣는다 : int와 같은 기본 자료형은 생성 불가 -> NSInteger처럼 객체로 넣어야 한다 objectAtIndex : index로 배열 내의 요소 액세스 count : 배열 길이 componentsSeparatedByString : 문자열을 배열화 해주는 함수 : java의 split 함수와 비슷 2. NSMutableArray 기본 함수 arrayWithCapacity : init 함수(factory method) : 파라미터로 array 배열 크기를 넣는다 addObject : 배열 맨 끝에 요소 추가 inser..

iOS 2020.08.11

[Objective-C] 기본 클래스 NSString

NSString NSString *str1 = @"hi"; NSString *str2 = @"hello"; // ------ 문자열 길이 int len = [str1 length]; // ------ 문자열 동등비교 [str1 isEqualToString: str2]; // ------ subString NSRange range = NSMakeRange(1,4); // index 2부터 4개 NSString *str3 = [str2 substringWithRange: range]; // ------ NSString을 C로 변환 [str1 UTF8String]; // ------ C를 NSString으로 변환 NSString *str4 = [NSString stringWithCString: argv[i] ..

iOS 2020.08.10