본문 바로가기

프로그래밍

(356)
[Swift] 가장 간단한 Actor 샘플코드, Actor Counter swift concurrency 에 actor 라는 개념이 있다. 가장 간단하게 actor 를 사용하는 예제를 만들어 보았다. ( with a little help of gpt ) 횟수를 카운트 하는 매우 간단한 카운터 class/actor이다. 카운터를 생성해서, 동시에 수행되는 두 태스크에서 동시에 카운팅이 이루어진다. import Foundation actor MyActorCounter { var counter = 0 func incrementCounter() { counter += 1 } } class MyClassCounter { var counter = 0 func incrementCounter() { counter += 1 } } func testActorCounter() async -> V..
SWIFT 기초] 배열 슬라이싱 python과 swift 비교 >>> l = list(range(10)) >>> l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> l[:3] [0, 1, 2] >>> l[3:7] [3, 4, 5, 6] >>> l[7:] [7, 8, 9] 위와 같은 파이썬에서의 슬라이싱을 swift 에서는 다음과 같이 할 수 있다. 39> let l = Array(0.. l[0.. l[3.. Array(l[7...]) $R25: [Int] = 3 values { [0] = 7 [1] = 8 [2] = 9 } 43> l[7..
macOS Xcode 에서 한글입력 특이사항 간단하게 이름과 나이를 입력받아 출력해 주는 C 프로그램이다. 간단히 실행한 내용은 다음과 같다. 이름을 입력하세요. : 홍길녀 나이를 입력하세요. : 18 나의 이름은 홍길녀 이고, 나이는 18 입니다. 이름의 바이트 길이는 24. 이름[00:03] = e1 84 92 = ᄒ 이름[03:06] = e1 85 a9 = ᅩ 이름[06:09] = e1 86 bc = ᆼ 이름[09:12] = e1 84 80 = ᄀ 이름[12:15] = e1 85 b5 = ᅵ 이름[15:18] = e1 86 af = ᆯ 이름[18:21] = e1 84 82 = ᄂ 이름[21:24] = e1 85 a7 = ᅧ 리눅스 등에서 일반적으로 utf-8 의 한글은 한음절이 3바이트로 인코딩되는데, 위 결과를 보면, 자모 하나 당..
spctl rejected (the code is valid but does not seem to be an app) 앱 공증(notarization)에 성공했으나, spctl 커맨드로 확인해 보면, code is valid but does not seem to be an app 이라는 에러가 발생하는 경우에 대한 타래 ( https://developer.apple.com/forums/thread/658054 )의 번역. I've successfully notarized my app. Apple sends me an email saying so. But a minute later, I try running the app but it has a white circle/slash over the icon. It will not run. So I check the notarization with: $ spctl --asses..
[EP0062] 같은 숫자로 이루어진 세제곱이 다섯개 #!/usr/bin/env python # Project Euler 62 # http://projecteuler.net/index.php?section=problems&id=62 # Problem 62 # # The cube, 41063625 (3453), can be permuted to produce two other cubes: # 56623104 (3843) and 66430125 (4053). In fact, 41063625 is the smallest # cube which has exactly three permutations of its digits which are also # cube. # # Find the smallest cube for which exactly five permut..
[C] 4x4 수도쿠 코드 // sudoku4x4.cpp : Defines the entry point for the console application. // // #include "stdafx.h" #include #include int g_num_solutions = 0; void find_sudoku_pan(int *pan); // // 최초의 판 모양은 // // 01-- // 23-- // ---- // ---- void init_pan(int *pan) { for (int i = 0; i < 16; i++) *(pan + i) = -1; *(pan + 4 * 0 + 0) = 0; // [0][0] *(pan + 4 * 0 + 1) = 1; // [0][1] *(pan + 4 * 1 + 0) = 2; // [1][0] ..
[Python] 2117658/8642334 와 연분수표현 2117658/8642334 각 디지트의 연분수꼴의 값이 같다는 신기한 글을 봐서 파이썬으로 계산을 해 봤다. >>> from fractions import Fraction >>> l1 = list(map(int, "2117658")) >>> l2 = list(map(int, "8642334")) >>> def frac(l1, l2): if len(l1) == 1: return Fraction(l1[0], l2[0]) return l1[0]/(l2[0] + frac(l1[1:], l2[1:])) >>> frac(l1, l2) Fraction(37, 151) >>> Fraction(2117658, 8642334) Fraction(37, 151) 이런 꼴의 결과를 주는 다른 숫자도 찾아보고 싶네.
[SwiftUI] @State, struct, class https://www.hackingwithswift.com/books/ios-swiftui/why-state-only-works-with-structs why state only works with structs 라는 제목의 강의. swiftui 에서 변경될 수 있는 변수에 @State 를 붙이는 것에 익숙해졌다. 이 @State 변수에는 스위프트의 기본 형 뿐만 아니라, 사용자형도 사용할 수 있다. 다음과 같다. struct User { var firstName = "Bilbo" var lastName = "Baggins" } struct ContentView: View { @State private var user = User() var body: some View { VStack { VStack {..