2017년 12월 19일 화요일

Xamarin 수업에서 사용하는 Visual Studio for mac이 업데이트 되면서 안드로이드 에뮬레이터의 속도가 빨라졌습니다.

기존 버전하고 다르게 Xamarin.Forms 2.5로 업데이트 되면서 에뮬의 속도도 많이 빨라졌습니다.
실제 디바이스가 있으면 좋겠지만 없어도 어느정도 테스트가 가능하게 좋아졌네요.

xCode 9.2의 경우도 다중으로 시뮬레이터를 실행할 수 있어서 아래와 같이 아이폰X과 아이폰8을 같이 비교할 수 있습니다.


2017년 12월 16일 토요일

Connect 2017 영상에 스캇 구슬리가 나오네요. 오랜만입니다.

https://channel9.msdn.com/Events/Connect/2017/K100

Xamarin과 Azure를 소개하고 있습니다.


자마린의 아버지 미겔 데 이카사
https://ko.wikipedia.org/wiki/%EB%AF%B8%EA%B2%94_%EB%8D%B0_%EC%9D%B4%EC%B9%B4%EC%82%AC


미겔 데 이카사 인터뷰 영상
https://www.youtube.com/watch?v=UuXIqeencdE

Xamarin Forms 2.5에서 추가된 아이폰 X관련 내용들입니다.

안전 영역에 대한 내용이 추가되면서 코드도 변경되었습니다.^^
아래의 주소에 자세한 내용들이 정리되어 있습니다.

https://blog.xamarin.com/making-ios-11-even-easier-xamarin-forms/


2
3
4
5
6
7
8
9
10
11
12
13
14
15
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
using Xamarin.Forms;
namespace iPhoneX
{
public partial class ItemsPage : ContentPage
{
public ItemsPage()
{
InitializeComponent();
On<Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);
}
}
}

2017년 12월 4일 월요일

파이썬의 유명한 웹 프레임워크인 django가 2.0으로 업데이트 되었습니다.

지금 테스트 중인데 아래의 블로그에 특징이 잘 정리되어 있습니다.

http://raccoonyy.github.io/django-2-0-release-note-summary/


비주얼스튜디오코드로 편집하는 화면입니다.



모바일에 대한 지원이 강화되었습니다. 작은 화면에서 관리 페이지 보기 입니다.


교재에 업데이트될 스크립트 입니다. 버전이 올라갔지만 변경된 부분은 약간입니다.
(장고를 설치)
pip install django

(폴더를 하나 생성하고 그 폴더로 이동한다)
cd \
mkdir c:\django
cd c:\django

(웹폴더를 생성)
django-admin startproject mysite

(웹서버 기동)
python manage.py runserver

(polls앱 생성)
python manage.py startapp polls

(웹서버 기동)
python manage.py runserver

(데이터베이스 동기화)
python manage.py migrate

(polls앱 동기화 추가)
python manage.py makemigrations polls

(SQL구문 보기)
python manage.py sqlmigrate polls 0001

(동기화)
python manage.py migrate

(쉘환경에서 API연습하기)
python manage.py shell
import django
django.setup()
from polls.models import Question, Choice
from django.utils import timezone
q = Question(question_text="What?", pub_date=timezone.now())
q.save()

Question.objects.all()
quit()

(모델에 약간의 코드를 추가한 후에 다시 쉘 환경에 접속)
python manage.py shell

from polls.models import Question, Choice
Question.objects.all()

q = Question.objects.get(pk=1)
q.choice_set.all()
q.choice_set.create(choice_text='Not much', votes=0)
q.choice_set.create(choice_text='The sky', votes=0)
c = q.choice_set.create(choice_text='Just hacking', votes=0)
c.question
c = q.choice_set.filter(choice_text__startswith='Just hacking')
c.delete()
q.choice_set.all()
quit()

(views.py를 아래와 같이 작성한다.)
from django.shortcuts import render
from django.http import HttpResponse
from .models import Question
from django.template import loader

# Create your views here.
def index(request):
    latest_question_list = Question.objects.order_by('-pub_date')[:5]
    template = loader.get_template('polls/index.html')
    context = {
        'latest_question_list':latest_question_list,
    }
    return HttpResponse(template.render(context, request))

def detail(request, question_id):
    return HttpResponse("상세 보기 %s" % question_id)

def results(request, question_id):
    return HttpResponse("결과 보기 %s" % question_id)

def vote(request, question_id):
    return HttpResponse("투표 하기 %s" % question_id)


(polls폴더에 templates폴더를 만들고 다시 여기에 polls를 만들고 index.html파일을 생성한다.
c:\django/mysite/polls/templates/polls/indexhtml이 전체 경로임)
{% if latest_question_list %}
<ul>
{% for question in latest_question_list %}
    <li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}



2017년 11월 2일 목요일

하이 시에라로 mac OS 클린 설치하기

주말에 시간을 내서 업데이트를 하고 있습니다.
용량이 항상 부족한 관계로 오랜만에 클린 설치를 합니다.

http://kimsungjin.tistory.com/173

위의 블로그에 클린 설치가 잘 설명되어 있네요. ~~


2017년 10월 18일 수요일

자마린 개발에 사용되는 Visual Studio for mac도 안드로이드 8.0, iOS 11.0지원 관련 업데이트가 되었습니다.

맥에서 사용하는 비주러 스튜디오 for mac에서 아이폰 텐을 지원합니다.




설치된 비주얼 스튜디오 for mac을 사용해서 체크해 보면 아래와 같이 다운로드 됩니다.


맥에 설치되어 있는 Xcode의 위치가 변경되었다면 아래와 같이 해당 위치를 지정해 주면 된다.



2017년 10월 9일 월요일

xCode 9.0도 출시되었고 iOS 11.0도 정식 버전이 출시되서 이전 코드들 테스트 중입니다.

생각보다 디테일한 부분에서 수정된 내용들이 많네요. 다행히 코드는 크게 수정된 부분이 없는데 오토레이아웃 관련된 내용들도 변경이 되었습니다.
아래의 화면을 보면 Add New Constraint에서 use standard value가 선택이 안됩니다.




다양하게 테스트 하면서 내용을 정리하고 있습니다.

2017년 7월 16일 일요일

Swift4에서 변경된 String형식에 대한 데모입니다.

    @IBAction func btn8(_ sender: Any) {
        //swift4에서 String은 컬렉션이다. 배열이나 시퀀스처럼 다룰 수 있다.
        let swift3String = "Swift 3"
        var filteredSwift3String = ""
        //문자열에서 각각의 문자를 보내면 문자열로 변환해서 처리하는 복잡한 과정
        for character in swift3String.characters {
            let string = String(character)
            let number = Int(string)
            
            if number == nil {
                filteredSwift3String.append(character)
            }
        }
        print("filteredSwift3String: \(filteredSwift3String)")
        
        //Swift4에서는 아래와 같이 처리가 가능하다.
        let swift4String = "Swift 4"
        let filteredSwift4String =
            swift4String.filter{Int(String($0)) == nil}
        print("filteredSwift4String: \(filteredSwift4String)")
//        filteredSwift3String: Swift
//        filteredSwift4String: Swift

        //Swift3에서 substring에서 문자열을 리턴
        let swift3SpaceIndex = swift3String.characters.index(of: " ")
        let swift3Substring = swift3String.substring(to: swift3SpaceIndex!)
        print("swift3Substring: \(swift3Substring)")
        
        //Swift4에서 substring
        let swift4SpaceIndex = swift4String.index(of: " ")
        //one sided range를 사용해서 추출한다.
        let swift4Substring = swift4String[..<swift4SpaceIndex!]
        print("swift4Substring: \(swift4Substring)")
        
        
        

    }

실행하면 결과는
filteredSwift3String: Swift 
filteredSwift4String: Swift 
swift3Substring: Swift
swift4Substring: Swift

Swift 4에서 강화된 Set, Dictionary입니다.

    @IBAction func btn4(_ sender: Any) {
        //swift4에서 튜플의 배열로부터 사전구조를 생성하는 방법
        let tupleArray = [("Monday",30), ("Tuesday",25),
            ("Wednesday",27), ("Thursday",20), ("Friday",24),
            ("Saturday",22), ("Sunday",26)]
        //dict의 init(uniqueKeyWithValues:)를 통해서
        //튜플 배열에서 새로운 사전구조를 생성한다.
        let dictionary = Dictionary(uniqueKeysWithValues:
            tupleArray)
        print("dictionary: \(dictionary)")
        
        //아래와 같이 사용할 수 도 있다.
        let keys = ["Monday", "Tuesday", "Wednesday",
            "Thursday", "Friday", "Saturday", "Sunday"]
        let values = [30, 25, 27, 20, 24, 22, 26]
        let newDictionary = Dictionary(uniqueKeysWithValues:
            zip(keys, values))
        print("newDictionary:\(newDictionary)")
        
        //swift3에서 사용하는 nil병합 연산자(??)
        var seasons = ["Spring": 20, "Summer": 30, "Autumn": 10]
        let winterTemperature = seasons["Winter"] ?? 0
        print("winterTemperature: \(winterTemperature)")
        //swift4에서 사용하는 코드
        let winterTemperature2 = seasons["Winter", default: 0]
        print("winterTemperature2: \(winterTemperature2)")
        
        //기존 swift3에서 기존에 있는 키를 통한 업데이트
        if let authumnTemperature = seasons["Autumn"] {
            seasons["Autumn"] = authumnTemperature + 5
        }
        //if let을 사용해서 옵셔널에서 nil을 체크하고 접근했는데
        //이제는 아래와 같이 default value subscript를 통해
        //접근할 수 있다.
        seasons["Autumn", default: 0] += 5
        print(seasons["Autumn"] ?? "")
        
        //map()과 filter()도 swift4에서 새롭게 디자인되었다.
        //swift3에서 사전이 아닌 배열을 리턴했다.
        //let mappedArrayValues = seasons.map{$0.value * 2}
        let mappedArray = seasons.map{key, value in (key, value*2)}
        print("mappedArray: \(mappedArray)")
        //swift4에서는 아래와 같이 사용한다.
        let mappedArray2 = seasons.map{season in
            (season.key, season.value * 2)}
        print("mappedArray2: \(mappedArray2)")
        //좀 더 축약을 하면
        let mappedArrayShorthandVersion = seasons.map{($0.0, $0.1 * 2)}
        print("mappedArrayShorthandVersion: \(mappedArrayShorthandVersion)")
        //아니면 아래와 같이 접근해도 된다.
        let mappedDictionary = seasons.mapValues{$0 * 2}
        print("mappedDictionary:\(mappedDictionary)")
        
        //swift3에서의 필터
        let filteredArray = seasons.filter{$0.value > 15}
        print("filteredArray:\(filteredArray)")
        //swift4에서의 필터
        //완벽하게 동일한 결과이지만 원본과 동일한 구조의 필터링된
        //사전을 리턴한다.
        let filteredDictionary = seasons.filter{$0.value > 15}
        print("filteredDictionary:\(filteredDictionary)")
        
        //swift4는 사전구조를 스플릿할 수 있다.
        let scores = [7, 20, 5, 30, 100, 40, 200]
        let groupedDictionary = Dictionary(grouping: scores,
                                           by:{String($0).count})
        print("groupedDictionary:\(groupedDictionary)")
        //후행 클로저를 사용하면 다음과 같이 작성할 수 있다.
        let groupedDictionaryTrailingClosure =
            Dictionary(grouping: scores)
            {String($0).count}
        print("groupedDictionaryTrailingClosure:\(groupedDictionaryTrailingClosure)")
        
        //swift3에서 초기 용량을 지정해서 사전을 생성하는 코드
        let ratings: Dictionary<String, Int> =
            Dictionary(minimumCapacity:10)
        //swift4에서 처리
        seasons.capacity
        seasons.reserveCapacity(4)
        
        //swift3에서 필터
        let categories: Set<String> = ["Swift", "iOS",
           "macOS", "watchOS", "tvOS"]
        let filteredCategories = categories.filter{$0.hasSuffix("OS")}
        print("filteredCategories: \(filteredCategories)")
        

    }

[1, 5]
[1, 5, 2]
openFirstSlice: [1, 5]
closedFirstSlice: [1, 5, 2]
openSecondHalf: [8, 4, 10]
closedSecondHalf: [8, 4, 10]
closedSecondSlice: [8, 4, 10]
1: 1
2: 5
3: 2
4: 8
5: 4
6: 10
1: 1
2: 5
3: 2
4: 8
5: 4
6: 10
Your favourite number is a positive one.
교환 이후:[5, 1, 2, 8, 4, 10]
dictionary: ["Tuesday": 25, "Saturday": 22, "Sunday": 26, "Friday": 24, "Monday": 30, "Wednesday": 27, "Thursday": 20]
newDictionary:["Tuesday": 25, "Saturday": 22, "Sunday": 26, "Friday": 24, "Monday": 30, "Wednesday": 27, "Thursday": 20]
winterTemperature: 0
winterTemperature2: 0
20
mappedArray: [("Summer", 60), ("Spring", 40), ("Autumn", 40)]
mappedArray2: [("Summer", 60), ("Spring", 40), ("Autumn", 40)]
mappedArrayShorthandVersion: [("Summer", 60), ("Spring", 40), ("Autumn", 40)]
mappedDictionary:["Summer": 60, "Spring": 40, "Autumn": 40]
filteredArray:["Summer": 30, "Spring": 20, "Autumn": 20]
filteredDictionary:["Summer": 30, "Spring": 20, "Autumn": 20]
groupedDictionary:[2: [20, 30, 40], 3: [100, 200], 1: [7, 5]]
groupedDictionaryTrailingClosure:[2: [20, 30, 40], 3: [100, 200], 1: [7, 5]]
filteredCategories: ["watchOS", "iOS", "macOS", "tvOS"]

Swift 4에 새롭게 추가된 prefix, postfix, One Sided Range 연산자 입니다.

    @IBAction func btn3(_ sender: Any) {
        //Swift4에 추가된 prefix와 postfix버전
        //half open range와 closed range operator
        //배열의 절반에 접근하려면 기존에 사용하던 코드
        let array = [1,5,2,8,4,10]
        let halfIndex = (array.count - 1) / 2
        let openFirstHalf = array[0..<halfIndex]
        let closedFirstHalf = array[0...halfIndex]
        print(openFirstHalf)
        print(closedFirstHalf)
        
        //Swift4에서는 시작 인덱스를 명시하지 않고
        //접근할 수 있다.
        let openFirstSlice = array[..<halfIndex]
        let closedFirstSlice = array[...halfIndex]
        print("openFirstSlice: \(openFirstSlice)")
        print("closedFirstSlice: \(closedFirstSlice)")
        
        //range의 시작 인덱스를 삭제할 수 있다. 이유는 모든 배열 요소를
        //halfIndex를 통해 처리하도록 하기 때문이다.
        //기존 Swift3의 코드
        let nextIndex = halfIndex + 1
        let lastIndex = array.count - 1
        let openSecondHalf = array[nextIndex..<lastIndex + 1]
        let closedSecondHalf = array[nextIndex...lastIndex]
        print("openSecondHalf: \(openSecondHalf)")
        print("closedSecondHalf: \(closedSecondHalf)")
        
        //Swift4의 코드
        //half open range와 closed range operator를 사용하면서
        //끝부분을 생략할 수 있다. range의 end index를 생략할 수 있다.
        let closedSecondSlice = array[nextIndex...]
        print("closedSecondSlice: \(closedSecondSlice)")
        
        //one sided range 연산자
        //swift3에서 배열의 인덱스와 값을 출력할 경우
        for (index, value) in array.enumerated() {
            print("\(index + 1): \(value)")
        }
        //swift4에서는 아래와 같이 처리한다.
        //더이상 enumerated()메서드를 호출할 필요가 없고
        //시작 첨자를 1로 변경하고 싶으면 아래와 같이 한다.
        //zip함수를 사용해서 one sided range의 인덱스와 배열의 값을
        //결합한다.
        for (index, value) in zip(1..., array) {
            print("\(index): \(value)")
        }
        
        //One sided range는 switch구문과도 매칭된다.
        let favouriteNumber = 10
        switch favouriteNumber {
        case ..<0:
            print("Your favourite number is a negative one.")
        case 0...:
            print("Your favourite number is a positive one.")
        default:
            break
        }

        //기존 swap함수는 swapAt메서드를 사용하도록 한다.
        var numbers = [1,5,2,8,4,10]
        //swap(&numbers[0], &numbers[1])
        
        numbers.swapAt(0, 1)
        print("교환 이후:\(numbers)")
        

    }


[1, 5]
[1, 5, 2]
openFirstSlice: [1, 5]
closedFirstSlice: [1, 5, 2]
openSecondHalf: [8, 4, 10]
closedSecondHalf: [8, 4, 10]
closedSecondSlice: [8, 4, 10]
1: 1
2: 5
3: 2
4: 8
5: 4
6: 10
1: 1
2: 5
3: 2
4: 8
5: 4
6: 10
Your favourite number is a positive one.
교환 이후:[5, 1, 2, 8, 4, 10]

Swift 4의 JSON 인코더와 디코더 사용 데모입니다.

Xcode 9.0 beta3에서 iOS 11.0에 대한 테스트들입니다.

JSON EncodingDecoding
좀 더 간편하게 JSON포맷을 처리할 수 있게 됨

DemoSwift4로 저장함

아래와 같이 Tutorial클래스 파일을 추가한다.
//
//  Tutorial.swift
//  DemoSwift4
//
//  Created by jong deok Kim on 2017. 7. 17..
//  Copyright © 2017 credu. All rights reserved.
//

import Foundation

class Tutorial: Codable {
    let title: String
    let author: String
    let editor: String
    let type: String
    let publishDate: Date
   
    init(title: String, author: String, editor: String, type: String, publishDate: Date) {
        self.title = title
        self.author = author
        self.editor = editor
        self.type = type
        self.publishDate = publishDate
    }
}


버튼을 3개 추가해서 아래와 같이 코딩한다.
//
//  ViewController.swift
//  DemoSwift4
//
//  Created by jong deok Kim on 2017. 7. 17..
//  Copyright © 2017 credu. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBAction func btn1(_ sender: Any) {
       
        let tutorial = Tutorial(title: "스위프트4 새로운 ", author: "papasmf", editor: "kim", type: "새로운 기능", publishDate: Date())
        //위의 객체를 바로 JSON포맷으로 인코딩해서 리턴한다.
        let encoder = JSONEncoder()
        do {
            let data = try encoder.encode(tutorial)
            let string = String(data: data, encoding: .utf8)
            print(string ?? "")
       
            let decoder = JSONDecoder()
            let article = try decoder.decode(Tutorial.self, from: data)
            let info = "\(article.title) \(article.author) "
                + "\(article.editor) \(article.type) \(article.publishDate)"
            print(info)
        } catch {
       
        }
       
    }
   
    @IBAction func btn2(_ sender: Any) {
    }
   
    @IBAction func btn3(_ sender: Any) {
    }
   
   
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

결과는 아래와 같이 출력된다.
{"author":"papasmf","title":"스위프트4 새로운 ","publishDate":522004473.74601197,"type":"새로운 기능","editor":"kim"}
스위프트4 새로운 papasmf kim 새로운 기능 2017-07-17 17:14:33 +0000







요즘 많이 들리는 RAG에 대한 멋진 정리가 있어서 공유합니다. ㅎㅎ

 작년에는 ChatGPT가 크게 유행을 했는데 올해는 Gen AI, LLM, 랭체인등이 유행하고 있습니다. ㅎㅎ  RAG라는 단어도 상당히 많이 들리고 있습니다. 멋진 정리의 링크입니다.  https://brunch.co.kr/@ywkim36/146?...