본문 바로가기

swift64

Vapor 서버 만들기 - Ubuntu+Swift+Vapor+Github+Nohup+PostgreSQL(6) 서버를 만들었으니 이제 디비를 연결해 보자 데이터 베이스는 PostgreSQL 을 쓰겟다. (Fluent 가 지원해서) 목표 VM에 PostgreSQL 디비를 설치 내 맥에 PostgreSQL 클라이언트 앱에서 디비 연결 예제 디비 만들어서 서버 반영 서버에서 디비값 쿼리해서 HelloWorld 말고 디비값 출력 디비 연결 완성 저번에 올려놨던 Vapor 프로젝트를 깃헙에서 내 맥북으로 클론한다. 그리고 터미널로 해당 디렉토리에 들어가 open Package.swift 하면 프로젝트를 Xcode에서 열 수 있다. 패키지 디펜던시를 fetching 하는데 시간이 좀 걸리긴 한다. 다 진행되면 화살표 모양이 뜬다. 디비 세팅하기전에 먼저 코드를 보자면 routes.swift import Fluent impo.. 2020. 8. 18.
Vapor 서버 만들기 - Ubuntu+Swift+Vapor+Github+Supervisor(5) Supervisor 를 안다니 서버가 자꾸 꺼져서 해결해야겠다. 이전에 에러는 Spawn 에러가 났었는데 로그가 남는다 해서 로그를 보았다. 020-08-16 05:47:08,840 INFO exited: hello (exit status 0; not expected) 2020-08-16 05:47:11,846 INFO spawned: 'hello' with pid 7321 2020-08-16 05:47:11,913 INFO exited: hello (exit status 0; not expected) 2020-08-16 05:47:12,914 INFO gave up: hello entered FATAL state, too many start retries too quickly 2020-08-16 08:.. 2020. 8. 16.
Vapor 서버 만들기 - Ubuntu+Swift+Vapor+Github(4) 할일: Ubuntu 에 있는 Vapor 프로젝트 GitHub 연동 깃헙에서 레포 하나 만들자 Ubuntu 서버에서 git 설정 해주자 sudo apt-get install git-core git config --global user.name TAEHYEONGKIM git config --global uuzaza@naver.com Vapor 프로젝트에 git init git init Remote 저장소 Local 저장소 연결 git remote add origin https://github.com/KimTaeHyeong17/vapor-server.git master에 push 를 위한 add와 commit 깃헙 리모트 레포에 변경사항 확인 이제 맥에서 이 레포를 Clone 하고 맥의 LocalHost 에서.. 2020. 8. 16.
GCP - 무료 Vapor 서버 만들기 - Ubuntu+Swift+Vapor(3) ----- 이번 포스팅에서는 Hello World 성공했습니다. ------ 저번 포스팅까지 한것 GCP 무료 인스턴스 생성 (Ubuntu18.04) Ubuntu Swift5 환경 구축 Swift 컴파일되는거 확인 Vapor 프레임워크 설치 Vapor Build & Serve 확인 localHost 에서 Run 근데 VM 외부 ip 로 접속 했을 때 connection refused 가 뜬다. 생각해보니 Spring boot 서버 세팅할 때 순서가 로컬에서 스프링부트 init 로컬에서 API 개발 깃 리모트 레포에 푸쉬 클라우드 서버에 아파치2, Nginx 설치 해당 깃 풀 받기 뭐 서버 돌리기 였던걸로 기억난다. 문제점은 Vapor 를 서버에서 돌렸을때 돌아가는 하는데 외부 접속을 위한 단계가 빠진 것.. 2020. 8. 15.
GCP - 무료 Vapor 서버 만들기 - Ubuntu+Swift(2) ----- 주의: 삽질 기록이니 따라하지 마세요 ------ Vapor 다시 시도해보겠다. 일단 새마음 새뜻으로 vm 새로 만들어서 Swfit 설치까지 하겠다. 이전에 했던 Swift 까는 방법은 sudo apt-get update wget https://swift.org/builds/swift-5.2.5-release/ubuntu1804/swift-5.2.5-RELEASE/swift-5.2.5-RELEASE-ubuntu18.04.tar.gz tar xzf swift-5.2.5-RELEASE-ubuntu18.04.tar.gz sudo mv swift-5.2.5-RELEASE-ubuntu18.04 /usr/share/swift echo "export PATH=/usr/share/swift/usr/bin:$.. 2020. 8. 15.
GCP - 무료 Vapor 서버 만들기 - Ubuntu+Swift(1) ----- 주의: 삽질 기록이니 따라하지 마세요 ------ 필요할때 쓸 수 있는 서버가 있으면 좋겠다 생각을 했다. 그런데 대표적인 AWS의 경우 1년 마다 새로 회원가입을 해야되서 귀찮았다. 그런데 오라클 클라우드 평생 무료 티어가 있다길래 써보려다 하루를 날리고 계정은 로그인도 안되고 뭐 컨택 이메일은 답장도 안오고 비밀번호 변경 메일도 안오고 화가나서 때려치고 다른걸 검색해보니 GCP 도 1년이 아닌 평생 무료 사용이 가능했다. 오늘은 무료 VM에다 Swift 서버 프레임워크인 Vapor 로 Rest 서버를 세팅하려 한다. GCP 무료 VM 세팅 참고한글 구글 클라우드 프리티어 이후 항상(평생) 무료 사용하는 방법 예전에 구글 클라우드 프리티어를 1년간 사용했었는데요. 그리고 나서 AWS를 프리티.. 2020. 8. 14.
LeetCode - Detect Capital Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 문제 Given a word, you need to judge whether the usage of capitals in it is right or not. We define the usage of capitals in a word to be right when one of the following cas.. 2020. 8. 7.
Design Pattern - Delegation Pattern Delegate: 대리자 Delegation Pattern 은 한 객체가 다른 Helper 객체를 통해 데이터를 전송하거나 특정 업무를 대신 할 수 있게 해주는 패턴이다. (Delegation Pattern enables an object to use another "Helper" Object to provide data or perform a task rather than do the task itself) Delegation Pattern 의 3가지 부분 Object needing a delegate: delegating object 라고도 한다. Delegate 를 가진 객체를 말하며 delegating 객체가 delegate 를 retain 할때 발생할 수 있는 retain cycle 을 피하기 .. 2020. 8. 6.
Programmers - 타겟 넘버 코딩테스트 연습 - 타겟 넘버 n개의 음이 아닌 정수가 있습니다. 이 수를 적절히 더하거나 빼서 타겟 넘버를 만들려고 합니다. 예를 들어 [1, 1, 1, 1, 1]로 숫자 3을 만들려면 다음 다섯 방법을 쓸 수 있습니다. -1+1+1+1+1 = 3 +1-1+1+1+ programmers.co.kr 문제 문제 설명 n개의 음이 아닌 정수가 있습니다. 이 수를 적절히 더하거나 빼서 타겟 넘버를 만들려고 합니다. 예를 들어 [1, 1, 1, 1, 1]로 숫자 3을 만들려면 다음 다섯 방법을 쓸 수 있습니다. -1+1+1+1+1 = 3 +1-1+1+1+1 = 3 +1+1-1+1+1 = 3 +1+1+1-1+1 = 3 +1+1+1+1-1 = 3 사용할 수 있는 숫자가 담긴 배열 numbers, 타겟 넘버 targ.. 2020. 8. 3.
💯 Daily LeetCode Challenge Day_20 - Remove Linked List Elements Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 문제 Remove all elements from a linked list of integers that have value val. Example: Input: 1->2->6->3->4->5->6, val = 6 Output: 1->2->3->4->5 Swift 로 풀려니 Optional 처리가 걸린다... 2020. 7. 29.
💯 Daily LeetCode Challenge Day_19 - Add Binary Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 문제 Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only characters 1 or 0. Example 1: Input: a = "11",.. 2020. 7. 29.
Swift - Graph Implemetation Swift Algorithm Club: Graphs with Adjacency List Learn how to implement directed and undirected graphs in Swift using adjacency lists. www.raywenderlich.com Adjacency List 구현 인접리스트 구현 방식 Storing an array of arrays Storing an array of linked-lists Storing a dictionary of arrays 인접 리스트 구현 #1 Vertex import Foundation public struct Vertex { var data: T } extension Vertex: Hashable { public var hashV.. 2020. 7. 20.
💯 Daily LeetCode Challenge Day_17 - Top K Frequent Elements Account Login - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input: nums = [1], k = 1 Output: [1] Note: You may assume k is always .. 2020. 7. 18.
💯 Daily LeetCode Challenge Day_16 - Pow(x, n) Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 문제 Implement pow(x, n), which calculates x raised to the power n (xn). Example 1: Input: 2.00000, 10 Output: 1024.00000 Example 2: Input: 2.10000, 3 Output: 9.26100 Exampl.. 2020. 7. 18.
💯 Daily LeetCode Challenge Day_15 - Reverse Words in a String Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 문제 Given an input string, reverse the string word by word. Example 1: Input: "the sky is blue" Output: "blue is sky the" Example 2: Input: " hello world! " Output: "world!.. 2020. 7. 16.
💯 Daily LeetCode Challenge Day_14 - Angle between hands of a clock Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 문제 Given two numbers, hour and minutes. Return the smaller angle (in degrees) formed between the hour and the minute hand. Example 1: Input: hour = 12, minutes = 30 Output.. 2020. 7. 14.
LeetCode - Container With Most Water Container With Most Water - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two li.. 2020. 7. 14.
Swift: 프로퍼티와 메서드 프로퍼티 클래스, 구조체 또는 열거형 등에 관련된 값 저장 프로퍼티: 인스턴스의 변수 또는 상수 (구조체, 클래스에만 사용 가능) 연산 프로퍼티: 특정 연산을 실행한 결괏값 타입 프로퍼티: 특정 타입에 사용되는 프로퍼티 (클래스 변수) - static *프로퍼티 감시자: 프로퍼티 값이 변할 때 값의 변화에 따른 특정 작업 실행 (저장 프로퍼티에 적용가능, 부모 클래스로부터 상속 가능) 지연 저장 프로퍼티 (lazy var) 호출이 있어야 값을 초기화 한다. 인스턴스를 초기화 하면서 굳이 모든 저장 프로퍼티를 사용할 필요가 없을 때 사용한다. 굳이 메서드를 쓰지않고 연산 프로퍼티를 쓰는 이유 인스턴스 외부에서 메서드를 통해 인스턴스 내부 값에 접근하려면 메서드 두개(접근자, 설정자)를 구현해야한다. (코드.. 2020. 7. 13.
Swift: 구조체 vs 클래스 Struct 구조체의 인스턴스는 값 타입 --> 전달될 값이 복사되어 전달된다. 스위프트 기본 타입(Bool, Int, Array, Dictionary, Set, String 등) 구조체로 구현되어 있음 Class 클래스의 인스턴스는 참조 타입 --> 전달될 값이 복사되지 않고 참조(주소)가 전달된다. *같은 곳을 참조하는지 확인을 위해 === 를 사용한다. 공통점 값을 저장하기 위해 property 를 정의 가능 기능 실행을 위해 method 정의 가능 subscript 문법을 통해 구조체 또는 클래스가 갖는 값에 접근하도록 서브스크립트를 정의 가능 초기화 될 때 상태를 지정하기 위한 init 정의 가능 기능 추가를 위한 extension 가능 특정 기능 실행을 위한 프로토콜 준수 가능 차이점 구조체는.. 2020. 7. 13.
💯 Daily LeetCode Challenge Day_11 - Subsets Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com 문제 Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The solution set must not contain duplicate subsets. Example: Input: nums = [.. 2020. 7. 12.
💯 Daily LeetCode Challenge Day_10 - Flatten a Multilevel Doubly Linked List Flatten a Multilevel Doubly Linked List - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 You are given a doubly linked list which in addition to the next and previous pointers, it could have a child pointer, which may or may not point to a separate doubly linked list. These chi.. 2020. 7. 10.