2015년 4월 17일 금요일

2.옵저버 패턴 (Observer Pattern)

하나의 객체가 변경사항이 생기면 다른객체에 전달하여 적절한 액션을 취할수 있도록 하는 패턴이다.

주로 발행한다. 는 의미가 강함

http://warmz.tistory.com/751 , http://wiki.gurubee.net/pages/viewpage.action?pageId=1507370 의 알람옵저버패턴을 보면이해가 될것이다.

http://hyeonstorage.tistory.com/165

http://tiboy.tistory.com/entry/Observer-Pattern

자바스트립트 옵저버 패턴? http://jsfiddle.net/vasco989k/HPsFp/

http://www.javajigi.net/display/SWD/ch02_observerpattern

object-c 옵저버패턴 http://kyejusung.com/2015/09/%EB%94%94%EC%9E%90%EC%9D%B8-%ED%8C%A8%ED%84%B4-2-observer-pattern/

1.디자인패턴-strategy pattern( 전략,전술 패턴)

Stat 패턴과 차이점이 잇는데 , 패턴내부에서 스스로 객체로 변경하는 것은 state 패턴이고

외부에서 객체를 지정해줘야 상태변경이 가능한 것이 strategy 이다

-------------------------------

Strategy 패턴은 주요객체는 공통된 기능(메쏘드)을 상속공유한다는 전제로서, 각 객체의 행동이 독립적인 속성을 가지고자 할때 유용한 패턴이다.

또한 abstract  로 선언된 공통된 기능을 포함한 추상클래스에
고정적으로 선언된 독립된 인터페이스(또는 레퍼런스)를  통해 하위 속성을
지정하는 것만으로도 객체의 특징속성(차는 원래 굴러다니지만, 날개를 붙이면 날라다닐수도 있다)을
변경가능한것이 용이하다는 장점이 있다.

이를 통해 객체의 속성을 실시간으로 변경할수도 있다.

다만 최상위 클래스에서 미리 행동양식들을 계산하고 정의해야 되기때문에,
최상위 클래스를 어떻게 설계하고, 바뀔수 있는 각각의 독립적인 행동양식들을 구분해 내느냐가 관건이다.

게임을 만든다고 치자.

주인공은 처음에는 걷는것만 할수있지만, 점점 아이템을 장착함에 따라 빨리 뛰고,날수 있게된다.
따라서  NPC 에서 MOVE 액션에 걷기를 빨리뛰기로, 또 날개가 장착되었을때는 날라가기로 바꾸기만 하면 해당액션을 할수있다.

물론 상속으로도 해결되지만, 재상속에 의한 스트레스를 줄이기 위해선 그냥 전략패턴을 쓰는게 좋다.

-------------------------------

 

 

http://hyeonstorage.tistory.com/146

굳이 전략 이라는 단어에 끼워 맞춘다면 이렇다.

일단 공격일자는 정해져 있다.
다만 공격 아이템들은 보병,스나이퍼, 자동차, 탱크,오토바이, 비행기, 배 등 다양한다.
보통은 자동차 클래스 따로, 탱크 클래스 따로 따로 만들어서 제어하는게 맞다.

하지만 이렇게 하면 공격아이템들이 늘어날때마다(수륙양용 호버크래프트,드론등..)
같은 행동을 하는 클랙스를 생성해야 한다면 매우 귀찮을 것이다.

따라서 전략 패턴을 적용해서.!!!

일단 병기 라는 추상 클랙스를 만들자.
그리고 나서 병기가 가져야할 공통 부분을 뽑아내 보자. 단 뽑아낸 공통 부분이 각 병기에 따라서 다른 값과 행동으로 구분된다면 이를 별도의 클래스 로 구분할 생각을 하자.
그럼 공통된 부분은
이동
전투
휴식
자멸
등이 있겠다.
이중 이동,전투 는 동일하다. 다른 행동을 취하는 것은 휴식,자멸이다. 비행기나 배 등은 휴식이 없으니까..
따라서 휴식,자멸은 별도의 행동패턴이라고 치부하고, 별도의 클래스로 만들어서 해당되는 병기들에게만 적용한다.

결국 보병,자동차,오토바이 들은 병기 추상클래스의 휴식 인터페이스를 지정하여 주면된다. 인터페이스로 지정해 주었으므로 각 병기에 맞게 쉬는 형태를 설정하면된다.

쉰다 인터페이스

-> 보병:앉아서 메쏘드 ,
-> 자동차,오토바이:시동을 끈다

따른 애들은 지정 안하면 된다.

 

http://jongyoungcha.tistory.com/entry/%EB%94%94%EC%9E%90%EC%9D%B8-%ED%8C%A8%ED%84%B4-state-%ED%8C%A8%ED%84%B4%EA%B3%BC-strategy-%ED%8C%A8%ED%84%B4%EC%97%90-%EB%8C%80%ED%95%B4

2015년 4월 7일 화요일

유니티 최적화팁

http://www.slideshare.net/agebreak/141206-42456391

2015년 4월 5일 일요일

https://github.com/wasabeef/awesome-android-ui

https://github.com/wasabeef/awesome-android-ui

2015년 3월 18일 수요일

열두번째 날: MySQL을 NoSQL로 사용하기

http://advent.perl.kr/2012/2012-12-12.html

2015년 3월 16일 월요일

Node.js로 푸시서비스 구현하기 1. 아이폰(iOS) 푸시서버 구현하기

http://blog.saltfactory.net/215

get-todays-photo-from-album-in-ios

http://stackoverflow.com/questions/26320876/get-todays-photo-from-album-in-ios

2015년 3월 12일 목요일

일본인이 정리한 ios 기능 설명서

http://iphone-tora.sakura.ne.jp/index.html

cocos 강좌가 많이 있는 중국 사이트

http://cn.cocos2d-x.org/tutorial/lists?id=49&per_page=27

2015년 3월 11일 수요일

망할놈의 autolayout

http://minsone.github.io/mac/ios/nslayoutconstraint/

2015년 3월 10일 화요일

Listview에 헤더 구현

http://warmz.tistory.com/673

ImageView 라운드(둥근 테두리) 처리

http://warmz.tistory.com/740

UIActivityViewController를 이용하여 다른 앱과 컨텐츠 공유하기

http://warmz.tistory.com/825

[View Animation] Flip Left/Right, Curl Up/Down

http://warmz.tistory.com/827

[Tip] Universal App 개발시 현재 단말기가 아이폰인지 아이패드인지 구별하 는 방법

http://warmz.tistory.com/830

IOS GDC , BLOCK-Coding 아주 좋은글.

http://warmz.tistory.com/831

영상처리-수학-기본

http://moguwai.tistory.com/entry/%EC%98%81%EC%83%81%EC%B2%98%EB%A6%AC-%EC%88%98%ED%95%99-%EA%B8%B0%EB%B3%B8

[IOS] UUID 생성 및 키체인 저장

http://reysion.tistory.com/55

고급 오토레이아웃(auto layout) -AutoLayout Programmatically 사용하기

http://www.letmecompile.com/advanced-auto-layout/

animating-an-uiimageview-view-from-point-a-to-point-b-with-constraints-program

http://stackoverflow.com/questions/14913949/animating-an-uiimageview-view-from-point-a-to-point-b-with-constraints-program

2015년 3월 9일 월요일

xcode 에서 에러의 위치를 보여주지 않을때

http://leo81.tistory.com/5

xcode 에서 svn 연동하기

http://leo81.tistory.com/41

위처럼 한다음

checkout 에서  임포트했던 프로젝트를 선택한다음 , 다시 맥에서 새로운 폴더에 받으면

자동으로 xcode 가 열리면서 보임.

이제 작업하고 commit 하면 됨.

아이폰에서 화면터치 무시하기

http://dongss.tistory.com/entry/iOS-%EC%95%84%EC%9D%B4%ED%8F%B0-%EA%B0%9C%EB%B0%9C-%ED%99%94%EB%A9%B4%EC%83%81%EC%97%90%EC%84%9C-%ED%84%B0%EC%B9%98-%EC%9D%B4%EB%B2%A4%ED%8A%B8-%EB%B0%9C%EC%83%9D%EC%8B%9C-View%EC%97%90%EC%84%9C-%EB%AC%B4%EC%8B%9C%ED%95%98%EA%B8%B0-%EB%B0%A9%EB%B2%95

cocos2dx 모노폴리 예제 > _ < -중국어

http://blog.csdn.net/lideguo1979/article/month/2015/03

NSURLRequest-서버에-POST-요청-쿠키정보까지 가능

http://xcode5.tistory.com/entry/NSURLRequest-%EC%84%9C%EB%B2%84%EC%97%90-POST-%EC%9A%94%EC%B2%AD

connecting-to-php-service-from-ios.html

http://divcode.blogspot.kr/2012/08/connecting-to-php-service-from-ios.html

NSThread 를 통한 데이터 병렬처리

http://yoogomja.tistory.com/entry/NSThread%EB%A5%BC-%ED%86%B5%ED%95%9C-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EC%B2%98%EB%A6%AC%EC%99%80-%ED%99%94%EB%A9%B4-%EC%A0%9C%EC%96%B4-%ED%8C%81

2015년 3월 4일 수요일

cocos2dx 동영상강좌 무료인곳

http://www.sonarlearning.co.uk/coursepage.php?topic=game&course=cocos2d-x-v3

iOS - Uploading image by HTTP POST

http://stackoverflow.com/questions/24182573/ios-uploading-image-by-http-post

http://parangma.tistory.com/109 -한글

screen 캡춰

http://redhan.tistory.com/37

ios webview 쿠키

http://www.picomax.net/xe/study/22881

ios multipart http post

http://stackoverflow.com/questions/8564833/ios-upload-image-and-text-using-http-post

http://stackoverflow.com/questions/24250475/post-multipart-form-data-with-objective-c

http://vulpecula.tistory.com/40 한글

2015년 3월 3일 화요일

collection view 에서 멀티셀렉트

http://www.appcoda.com/ios-collection-view-tutorial/

2015년 3월 2일 월요일

컬렉션 뷰(UICollectionView) #5. Layout, 그리고 Flow Layout-설명이잘되어 있는...

http://covelist.tistory.com/9

아이폰용 오픈소스 링크들

http://blueamor.tistory.com/818

아이폰 자잘한팁들

http://inhoda.blogspot.kr/2012/02/blog-post.html

2015년 3월 1일 일요일

[objc] 앨범에서 마지막으로 찍은 사진 가져오기

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];



    // Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.


    [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group,BOOL *stop) {



        // Within the group enumeration block, filter to enumerate just photos.


        [group setAssetsFilter:[ALAssetsFilter allPhotos]];



        // Chooses the photo at the last index


        [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:([group numberOfAssets] - 1)]options:0 usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {



            // The end of the enumeration is signaled by asset == nil.


            if (alAsset) {


                ALAssetRepresentation *representation = [alAsset defaultRepresentation];


                UIImage *latestPhoto = [UIImage imageWithCGImage:[representation fullScreenImage]];


                [latestPhoto resizeImageToWidth:50];



                if (latestPhoto){


                    [self.imgBtn setBackgroundImage:latestPhoto forState:UIControlStateNormal];


                    [self.imgBtn setBackgroundImage:latestPhoto forState:UIControlStateHighlighted];


                }


            }


        }];


    } failureBlock: ^(NSError *error) {


    }];

tableview 에 앨범 제목표시

http://www.appcoda.com/uitableview-tutorial-storyboard-xcode5/

http://www.mindfiresolutions.com/Using-Groups-How-to-retrieve-data-from-Photos-Application-in-iOS-device-1720.php

앨범에서 마지막 찍은 사진 가져오기

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];



    // Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.


    [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group,BOOL *stop) {



        // Within the group enumeration block, filter to enumerate just photos.


        [group setAssetsFilter:[ALAssetsFilter allPhotos]];



        // Chooses the photo at the last index


        [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:([group numberOfAssets] - 1)]options:0 usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {



            // The end of the enumeration is signaled by asset == nil.


            if (alAsset) {


                ALAssetRepresentation *representation = [alAsset defaultRepresentation];


                UIImage *latestPhoto = [UIImage imageWithCGImage:[representation fullScreenImage]];


                [latestPhoto resizeImageToWidth:50];



                if (latestPhoto){


                    [self.imgBtn setBackgroundImage:latestPhoto forState:UIControlStateNormal];


                    [self.imgBtn setBackgroundImage:latestPhoto forState:UIControlStateHighlighted];


                }


            }


        }];


    } failureBlock: ^(NSError *error) {


    }];

인스턴스 마다 의 공유 값들은 프로토타입에 저장

인스턴스 마다 의 공유 값들은 프로토타입에 저장

커링 함수에 bind 사용하기

bind 는 기존의 함수나  메소드 에 영향을 주지않고 임시로 추가적인 함수를 만들어서 기존의 함수에 적용 을 시킨다.

function SimpleURL(protocol, domain, path){
return protocol + "://"+domain+"/"+path;
}

1.ㅂㅏ인드를 ㅅㅏ용하지  않는 일반적인 방법

var urls=paths.map(function(path){
return SimpleURL("http",sitedomain,path);
});

2.바인드를 사용 하여 심플 하게 변경

기 존의 함수에 bind(this, arg,arg) 식으로 선언하면,  arg 개수 를 가진 무명의 함수를 생성하여 이를 리 턴하고 다시 원래의 함수 를 호출(위임)하여   준다.

아래 예제에서는 simpleURL 에서는 this 등이 사용되지  않기 때문에 null  을 첫번째 인자로,

protocol과 domain 을 두번쨰 인자로 취하여 bind 가 새로운 함수를  생성한다음 함수리턴을 하고,

리턴된  함수 의 마지막에 path(map 에 의해 추출된 변수..여기서는  무명변수) 를  인자로 붙여 simpleurl 을 실행한다.

var urls=paths.map(SimpleURL.bind(null,"http",sitedomain));

고차함수

익명함수를  이용한  고차함수

------------

var a=[3,1,4,5,6].sort(function(x,y){
if(x<y) {return -1;}
if(x>y) {return 1;}
return 0;
});
console.log(a);

----------------------

맵을 이용한 고차함수

var a=["Fred","Willar","Peblle"].map(function(name){

return name.toUpperCase();
});
console.log(a);

----------------------

callback 이용한 고차함수

var aIndex="a".charCodeAt(0);
function buildString(n,callback){
var result="";
for(var i=0;i<n;i++){
result +=callback(i);
}
return result;
}

var alphabet=buildString(26,function(i){
return String.fromCharCode(aIndex+i);
});
var digit=buildString(10,function(i){
return i;
});
console.log(alphabet);
console.log(digit);

this 에 대한 심플예제1

-  this  의 범위를 이용하여 공유변수등을 만들때

obj 의 this 는 obj2,obj3 에서 사용될 때  호이스트 규칙에 의해 자신 을 포함하는 객체가 된다.

var obj={
hello:function(){
return "hi,"+this.username;
},
username:"hehe"
};
var obj2={
hello:obj.hello,
username:"taeho"
};
var obj3={
hello:obj.hello,
username:"yejin"
};
console.log(obj2.hello());
console.log(obj3.hello());

지연변수 스코프를 만들기위해 즉시 실행함수 표현식 사용법

반복문등에서 클로져를  이용하 여 지역변수를 참조하려할때, 클로저에서 변수값을 복사가 아닌 참조를 ㅎㅏ는 특성때 문에 반복 문의 마지막 변수만 참조하는 문제점이 있다.

--------------

function wrapElements(a){
var result=[];
for(var i=0,n=a.length;i<n;i++){
result[i]=function(){return a[i];};
}

}
var wrapped=wrapElements([10,20,30]);
var f=wrapped[0];
f();

이때,클로 져를  즉시실행함수로 감싸서  즉 시 실행함수에서  별도의 변 수 에 반복문의 반복 변수등을 복사저장한다음 클로져를 사용하면 된다.

function wrapElements(a){
var result=[];
for(var i=0,n=a.length;i<n;i++){
//즉시실행함수에서 i 값을 j 로 복제한다.
(function(j){
//result[i] 값이 객체로 온다는 것 주의
result[i]=function(){return a[j];};
})(i);

}
return result;

}
var wrapped=wrapElements([10,20,30]);
//리턴
var f=wrapped[1];
console.log(f());

클로저 심플예제

클로저는 외부 변수의 값을 복사하지 않고 참조한다.


1.자바스크립트는 현재함수의 외부에 있는 변수를 가져와서 사용할수도 있다.


----------------------------------------


function makeSandwich(){
var magicIngredient="peanut butter";
function make(filling){
return magicIngredient + "and "+ filling;
}
return make;
}
var f=makeSandwich();


console.log(f("hehe"));
console.log(f("jelly"));
console.log(f("bananas"));


--------------------------------------


2.함수는 외부함수가 무언가ㄴ를 리턴한 이후에도 외부함수에 선언도니 변수를 참조할수 있다. 즉 함수내의 변수를 지속적으로 고정,공유할수 있다.


function makeSandwich(magicIngredient){
return function (filling){
return magicIngredient + " and "+ filling;
}
return make;
}
var f=makeSandwich("ham");


console.log(f("hehe"));
console.log(f("jelly"));


-----------------------------------


3.클로져는 외부 변수의 값을 변경할수 있다.


function box(){
var val=undefined;
return {
set:function(newVal){ val=newVal;},
get:function(){return val;},
type:function(){return typeof val;}
}

}
var b=box();
b.type();
b.set("76.1");
console.log(b.get());
console.log(b.type());

2015년 1월 20일 화요일

안드로이드 오픈소스 프로젝트들.

https://github.com/Trinea/android-open-project/tree/master/English%20Version

2014년 12월 22일 월요일

게임기본기

http://codeincomplete.com/games/

outrun 스타일

outrun 스타일 ㅎㅠㅇ내내기 ...배울게 암ㅎ다.

https://github.com/jakesgordon/javascript-racer

2014년 12월 9일 화요일

폰갭에서 아이폰용 프로젝트 추가하기

--;

ios ㅍㅡㄹ랫폼을 추가한뒤에

ios-deploy , ios-sim 을 npmㅇㅡ로 설치하는데, 이때 xcode의 preference에서 ㅊㅜ가모듈 다운되었는지 확인하고 다운로드 하면 gcc가 서ㄹ치ㄷㅚㅁ

cordova run ios 하면됨