본문 바로가기

swift

(34)
[SWIFT] dump() 함수 출력을 문자열로 바꾸는 방법 dump 함수는 클래스 인스턴스의 내부 속성까지 간단히 출력해 주기 때문에 디버깅시에 편리하다. 그런데, 출력 내용을 문자열로 저장하여, stdout, stderr 가 아닌 곳으로도 출력/저장하고 싶었다. 스택오버플로우에 간단한 답변이 있었다. https://stackoverflow.com/a/42094841/100093 let myClass = MyClass() var myClassDumped = String() dump(myClass, to: &myClassDumped) https://github.com/apple/swift/blob/master/stdlib/public/core/OutputStream.swift 위 링크를 인용하고 있는데, 직접 영문설명을 읽어보는 게 좋겠지만, 요약하면, print..
Xcode 프로젝트 안의 타겟들 한꺼번에 빌드하기 https://stackoverflow.com/a/69228719/100093 Xcode - Building for Multiple Targets Simultaneously I have one Xcode project with multiple targets. During development, it is becoming laborious to compile and install each separately. Is there a way, through scripting or otherwise; that I can auto... stackoverflow.com Xcode 메뉴 중 Product > Scheme > Manage Schemes 을 보면 자동으로 만들어진 스킴들을 볼 수 있음. 액티브 스킴 편집으..
[XPC] 새로운 타겟에서 xpc service 사용하기 Error Domain=NSCocoaErrorDomain Code=4099 xpc service 를 만들었다. xpc service 를 사용해야 하는 어플리케이션 타겟을 만들어, 기존에 만든 xpc service 의 함수를 호출하려 했다. 그런데, 함수호출을 했는데도, 서비스와의 연결이 실패했다는 에러가 발생하였다. Received error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.xxxx.xxxxxpc was invalidated: failed at lookup with error 3 - No such process." UserInfo={NSDebugDescription=The connection to service named com.xxxx.xxxxxpc was inval..
communcation over XPC is asynchronous https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingXPCServices.html Designing an Interface The NSXPCConnection API takes advantage of Objective-C protocols to define the programmatic interface between the calling application and the service. Any instance method that you want to call from the opposite side of a connection must be explicitl..
[Swift|번역] Process waitUntilExit 은 비동기 completion handler 와 같이 쓰지 않는다. https://stackoverflow.com/a/49541564 동기함수인 waitUntilExit() 은 비동기적 completion handler 와는 같이쓰기 어렵다. 비동기 completion handler 를 사용한다면, exit 을 기다리는 건 의미없는 일이다. --- pipe의 fileHandleForReading 을 클로져에서 사용하기 때문에 double free 에러가 발생하는 것일 수 있다. stdout 을 동기적으로 읽으라.
[Swift] SwiftyXMLParser 를 이용해 xml 트리구조 보기 Swift 의 XML 라이브러리들 중에서, SwiftyXMLParser 라는 라이브러리가 있다. 파이썬의 xmltodict 처럼, 임의의 xml 을 좀 간단하게 파싱해주는 라이브러리이다. 파싱된 xml 의 트리구조를 간단히 보고 싶었는데, 트리구조를 보여주는 예제가 없어서, 만들어 보았다. import Foundation import SwiftyXMLParser func xmlPrint(_ xml: XML.Accessor, _ nIndent: Int = 0, _ seqIndex: Int = -1) { var indent : String { String(repeating: " ", count: nIndent) } switch(xml) { case .singleElement(let element) : if ..
[Swift] error: concurrency is only available in macOS 10.15.0 or newer async, await 를 간단하게 테스트해 보기 위해서, swift package manager 프로젝트를 만들고, 아주 간단한 await, async 예제를 실행해보려 했다. swift package init --type "executable" 로 프로젝트를 만들고, main.swift 를 program.swift 로 바꾸고, 예제 코드를 입력하고, swift build 를 빌드 테스트를 했다. 우선 ubuntu swift 5.6 환경에서는 성공을 했던 코드였는데, 컴파일 에러메시지가 나왔다. /Users/mememe/07_swift_test_projects/asyncawait_pm/Sources/asyncawait_pm/program.swift:24:29: error: concurrency is o..
100DaysOfSwiftUI - Day 26 Stepper Date, Calendar Create ML : 아주 간단한 회귀모델을 만드는 튜토리얼. 코드 없이 csv파일 선택하고 타겟변수 선택하고 독립변수 선택하여 트레이닝. 선형회귀, 랜덤포레스트 등등 모델을 선택할 수 있음. 만들어진 모델은 바이너리 파일로 만들어지고 이걸 프로젝트에서 임포트하여 사용하는 듯. https://daewonyoon.tistory.com/440