🍎 iOS

    [iOS][m1] Xcode Playground output이 안보일 경우

    m1 유저일 경우 xcode를 Rosetta로 열어 사용하면 Playground output이 안보이니 정보가져오기>Rosetta로 열기를 해제해주면 된다.

    [Swift] 길이가 정해진 리스트 만들고 0으로 초기화하기

    Array: repeating repeating이라는 함수를 이용해서 원하는 개수만큼 반복하여 특정 값을 array 안에 넣어줄 수 있다. - 특정 위치에 값이 없으면 앱이 crash 날 경우, 이러한 방법을 이용하여 특정 인덱스까지는 값이 있다는 것을 확신할 수 있다. var myArray = [Int](repeating: 0, count: 100)

    [Swift] Class와 Inheritance(상속)

    Inheritance A parent class = 'Superclass' A child class = 'Subclass' 슈퍼 클래스 없이 정의한 클래스 = 'Base class' class Bicycle: Vehicle { var hasBasket = false } let bicycle = Bicycle() bicycle.hasBasket = true Override property와 method는 오버라이드 할 수 있다. 원래 있던 속성에 올라타서 바꿀 수 있음. 함수 이름 옆에 override 키워드를 붙이면 사용 가능. class Train: Vehicle{ override func makeNoice(){ print("Choo Choo!") } } Reference class Person{ le..

    [Swift] Structure

    ※ convention: 구조체의 이름은 대문자, 그 안에 property나 method들은 소문자, 인스턴스를 만들 때는 소문자 instance 인스턴스 인스턴스를 만들려면 초기화를 해야하고 각각의 인스턴스는 structure의 모든 프로퍼티와 기능들을 가지게 된다. struct User { static var currentUser: User = User(userName: "Default", email: "Default", age: 0) var userName: String var email: String var age: Int static func logIn(user: User){ currentUser = user } } let me = User(userName: "Harry", email: "djk..

    [iOS] IBAction과 IBOutlet, 연결 후 삭제 시 주의할 점

    Outlet: code에서 storyboard로 object를 연결하는 것 Actions: storyboard의 controls에서 swift code로 연결시키는 것 IBOutlet: 스토리보드 상에 선언한 객체(View, Label ...)를 가리키는 변수 IBAction: 스토리보드 상 선언한 객체가 특정 이벤트가 발생했을 경우 호출되는 함수 object를 클릭하고 control 키를 누르고 마우스로 Assistant code에 드래그앤드롭으로 연결시켜주면 된다. 보통 viewDidLoad()를 기준으로 IBOutlet은 위에, IBAction은 아래에 연결시켜준다. // 버튼을 누르면 Label 텍스트가 변경되게 IBAction을 Button에 연결해두었다. IBAction 삭제 시 주의할 점 연..

    [iOS] storyboard에 추가된 view가 어디 있는지 안보일 때

    view object를 storyboard에 추가했는 데 배경과 object 색상이 같아서 보이지 않을 때 오른쪽처럼 표시해줄 수 있는 유용한 팁 Editor > Canvas > Bounds Rectangles ✓

    [iOS] 공유하기 기능 구현하기 iPhone/iPad

    var sharedObject = [Any]() sharedObject.append(image) // image = 공유할 때 보내고 싶은 이미지 let random = Int.random(in: 0...(sharedText.count - 1)) sharedObject.append(sharedText[random] + "\n\n공유할 때 함께 보내고 싶은 문장") let vc = UIActivityViewController(activityItems: sharedObject, applicationActivities: nil) vc.popoverPresentationController?.permittedArrowDirections = [] vc.popoverPresentationController?.sour..

    [Swift] switch 구문의 범위 연산자

    switch number{ case 0: print("zero") case 1..