분류 전체보기

개발/아이오에스

[swift] contains

var test = [1,2,3,4] let testcon = test.contains { (testData) -> Bool in return testData == 3 } testcon // true 이전에 contains을 사용해서 해당 배열크기만큼 돌면서 체크를 하는 것을 알고있었지만 해당 리턴값이 하나라도 true라면 그 값이 true로 정해지는지 몰랐다. 예시 코드에서 리턴값은 false, false, true, false 값이지만 결국 true가 하나라도 존재하기 때문에 testcon이라는 변수는 true가 된다.

개발/아이오에스

swift] filter 사용 bool 배열에서 true값 찾아내기

mV.isSelecteds: [bool] = [bool]() let cnt = mV.isSelecteds.filer { (bol) -> Bool in return bol } print(cnt) - [true, true, true] print(cnt.count) - 3

개발/아이오에스

swift] bool 타입 배열 초기화 하는방법

var isSelecteds : [Bool] = [Bool]() mV.isSelecteds = Array.init(repeating: false, count: tmpArrs.count) count: 2 일때 // -> [false, false] mV.isSelecteds = [Bool]() //다시 초기화 // -> []

카테고리 없음

[swift] class 사용 enum 활용하기

class AlarmInfo: NSObject, NSCoding { var sound : eSound = .talkCM init(sound : eSound){ self.sound = sound } } enum eSound : Int { case talkCM case twoSecond case original case first var name: String { switch self { case .first : return "1위" } } var songName: String { switch self { case .first : return "alarm_6_china.mp3" } } } -------- fun test(info: [AlarmInfo]) { info.forEach { (data) in dat..

개발/아이오에스

ios] xcode CodeSnippets 백업/복사하기

~/Library/Developer/Xcode/UserData/CodeSnippets/

개발/아이오에스

swift] json으로 가져온 url(stirng)을 띄어쓰기제거, 한글 인코딩, url 유효성 검사하기

- swift] json으로 가져온 url(stirng)을 띄어쓰기제거, 한글 인코딩, url 유효성 검사하기 json 형식의 데이터를 파싱하여 가져왔을 때 백엔드개발자의 실수나 어떠한 오류로 json의 url 데이터의 값이 오류가 생기는 경우 앱의 이미지를 보여주거나 웹뷰를 보여줄 때 큰 문제를 발생할 수 있다. 그래서 해당 url을 한번 체크(공백제거, 한글 인코딩, url 유효성 체크)를 해주고 앱이 작동되도록 로직을 구현해준다. let freedSpaceString = url.filter {!$0.isWhitespace} //띄어쓰기제거 guard let target = freedSpaceString.addingPercentEncoding(withAllowedCharacters: .urlQuery..

dev.jake
'분류 전체보기' 카테고리의 글 목록 (9 Page)