반응형
rss 아이콘 이미지
반응형

gem install ffi --version 1.15.5 --user-install

반응형

Swift 제어문 (Control Flow)

개발/iOS 2023. 2. 17. 09:43 Posted by 법당오빠
반응형

wift에서는 while loop, if guard, switch, for-in 문 등 많은 제어문을 제공합니다.

 

For-In 문 (For-In Loops)

for-in문는 배열, 숫자, 문자열을 순서대로 순회(iterate)하기 위해 사용합니다.

 

let names = ["Anna", "Alex", "Brian", "Jack"]
for name in names {
    print("Hello, \(name)!")
}
// Hello, Anna!
// Hello, Alex!
// Hello, Brian!
// Hello, Jack!

 

 

사전(dictionary)에서 반환된 키(key)-값(value) 쌍으로 구성된 튜플을 순회하며 제어할 수도 있습니다.

let numberOfLegs = ["spider": 8, "ant": 6, "cat": 4]
for (animalName, legCount) in numberOfLegs {
    print("\(animalName)s have \(legCount) legs")
}
// ants have 6 legs
// spiders have 8 legs
// cats have 4 legs

 

사전(dictionary)에 담긴 콘텐츠는 정렬이 되지 않은 상태입니다. 사전에 넣었던 순서대로 순회되지 않습니다. 아래와 같이 숫자 범위를 지정해 순회할 수 있습니다.

 

for index in 1...5 {
    print("\(index) times 5 is \(index * 5)")
}
// 1 times 5 is 5
// 2 times 5 is 10
// 3 times 5 is 15
// 4 times 5 is 20
// 5 times 5 is 25

 

반응형

Swift 콜렉션 타입 (Collection Types)

개발/iOS 2023. 2. 16. 14:29 Posted by 법당오빠
반응형
배열(Array)
배열의 축약형 문법
배열 타입은 Array로 적을 수 있는데 축약형으로 [Element] 형태로 사용할 수도 있습니다.

 

빈 배열의 생성
아래와 같이 Int형 빈 배열을 생성할 수 있습니다.
 
var someInts = [Int]()
print("someInts is of type [Int] with \(someInts.count) items.")
// someInts is of type [Int] with 0 items.
 
 
someInts.append(3)
// 배열에 3을 추가 했습니다.
someInts = []
// 배열을 비웠습니다. 배열의 아이템 타입은 그대로 Int로 유지됩니다.
반응형

Swift 단항 양수 연산자(Unary Plus Operator)

개발/iOS 2023. 2. 14. 10:57 Posted by 법당오빠
반응형

+로 표현되는 단항 양수 연산자는 부호에 아무런 영향을 끼치지 않습니다.

 

let minusSix = -6
let alsoMinusSix = +minusSix  // alsoMinusSix는 -6

반응형

Swift 단항 음수 연산자(Unary Minus Operator)

개발/iOS 2023. 2. 14. 10:57 Posted by 법당오빠
반응형

숫자 값은 - 로 표현되는 단항 음수 연산자에 의해 부호가 변합니다.

 

let three = 3
let minusThree = -three       // minusThree는 -3
let plusThree = -minusThree   // plusThree는 3, 혹은 "minus minus 3"

 

 

반응형
반응형

~/Library/MobileDevice/Provisioning Profiles

반응형

Swift 사칙 연산자(Arithmetic Operators)

개발/iOS 2023. 2. 13. 09:10 Posted by 법당오빠
반응형
Swift는 모든 숫자 형에서 사용 가능한 4가지 표준 사칙 연산자를 지원합니다.
덧셈 (+)
뺄셈 (-)
곱셉 (*)
나눗셈 (/)
 
C나 ObjectiveC와 달리 Swift는 사칙 연산의 값이 오버플로우 되는 것을 허용하지 않습니다. 만약 이것을 허용하고 싶으면 Swift의 오버플로우 연산자를 이용해 지원할 수 있습니다. 덧셈 연산자는 아래와 같이 문자열을 합치기 위해 사용할 수 있습니다.
 
"hello, " + "world"  // equals "hello, world"
 
반응형

Swift String 비교

개발/iOS 2023. 2. 10. 17:07 Posted by 법당오빠
반응형

Swift Compare String 


let testString : String = "TEST"

let testString2 : String = "test"

 

testString == testString2

반응형

UILabel copyWithZone 오류

개발/iOS 2012. 4. 2. 14:19 Posted by 법당오빠
반응형

 UILabel *title;


원인 : 변수명 중복 

해결방법 : 다른이름으로 변수명 변경


이걸로 또 삽질했네...


[UILabel copyWithZone:]: unrecognized selector sent to instance 0x3d33270



반응형
반응형

//#define MAXLENGTH 원하는 글자수

//- (BOOL)textView:(UITextField *)textView shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

//   alert = (Alert *)self.appDelegate.alert;

// if (textView.tag == 1) {

// int length = [textView.text length] ;

// if (length >= MAXLENGTH) {

// textView.text = [textView.text substringToIndex:MAXLENGTH];

// [alert alertMaxInfoMessage];

// return NO;

//

// }

//        return YES;

// }

//

//}

 

반응형