ラベル 脱初心者の道 の投稿を表示しています。 すべての投稿を表示
ラベル 脱初心者の道 の投稿を表示しています。 すべての投稿を表示

2013年3月31日日曜日

arrayはまず初期化(自分への戒め)


ヘッダファイルでNSArrayやNSMutableArrayを用意して、
implementationで使おうと思ったら、うまくいかない。

で、
    NSMutableArray *array=[NSMutableArray array];

といった準備をしなくてはいけないことを思い出す。。。。

前にもやりましたが、またやりました。
ハズカシイ初心者ぶりです。
intなどなら、そのまま使えるので、油断。

戒めのため、覚えておくため、記事化。

2013年2月16日土曜日

iOSアプリの開発にとても役立つサイト「raywenderlich.com」

このサイト、
http://www.raywenderlich.com/tutorials
iOSアプリのチュートリアルが非常に秀逸であることに気づいた。

色々良い記事が載っている。。
自分が必要なものにリンクを貼っておきます。

drag and dropの実装で、自分のやり方は甘いと感じていたので、以下が参考になりそうだった。
http://www.raywenderlich.com/2343/how-to-drag-and-drop-sprites-with-cocos2d

中級のチュートリアル。
http://www.raywenderlich.com/tutorials#cocos2d-intermed

Box2DとCocos2dのチュートリアル。
http://www.raywenderlich.com/tutorials#physics

Core Dataの使い方等の「saving and loading data」。web serviceとの同期なども。
http://www.raywenderlich.com/tutorials#saving

「Graphics and Animation」。UIKitについてなど。
その中で、ToDoアプリのサンプルが気になった。


2013年2月15日金曜日

Fruits Ninja的なアプリづくりの記事

fruits ninjaのようなゲームのサンプルコードを3ページにわたって解説しておられる記事があった。
http://www.raywenderlich.com/14302/how-to-make-a-game-like-fruit-ninja-with-box2d-and-cocos2d-part-1

かなり勉強になる。

physicsEditorを使って、Spriteに頂点を振ってゆき、
範囲を作って、BOX2Dで制御。

PRKitというライブラリを使って、ポリゴンでSpriteをカットする部分を制御。

いろいろ、とても勉強になる。

ちょくちょく記事とソースを読んで、勉強しましょう自分、ということでメモでした。

:::::::::::::::::::::::::::::::
追記

PRKitは、上記記事だとcocos2d 1.x系に対応していて、2.x系はまだ、ということでしたが、
https://github.com/asinesio/cocos2d-PRKit
を見ると、2.xへのcompatibilityを向上、ということを書いているので、対応しつつあるようですね。自分でインストールして確かめていませんが。

2013年2月11日月曜日

CoconutKitの解説ページ調べ。Core data情報を探して。

coconutkitという便利そうなライブラリを使ってみるため、
調査開始。

まず、以下のwikiが初歩の解説。
https://github.com/defagos/CoconutKit/wiki/Introduction

containerに関するページ。
https://github.com/defagos/CoconutKit/wiki/Containers

残念!Core Dataに関する解説は、まだwikiにはありませんでした。
https://github.com/defagos/CoconutKit/wiki/Core-Data-extensions

Core Data関連のコードは、ここに掲載されていました。コードを読んで解読するしかないですね。(作者の方は、「コードに解説を書いているのでそれを参考にして欲しい。」といったことをどこかに書いておられました。コードのコメントで最新情報を書いておくから、ということで)
https://github.com/defagos/CoconutKit-CocoaPods/tree/master/Sources/CoreData

CoconutKitをcocoa podを使ってインストールする解説はこちら。
https://github.com/defagos/CoconutKit/wiki/Getting-started

私は特にCore Dataに関する情報が欲しいので、
wikiのintroductionページから、以下にコピっておきます。自分用に日本語メモもつけますが、意味の正確性は、怪しいところがあり、訳は断片的で不十分です。ご了承ください。

Core Data management

Core Data is a wonderful framework. In too many projects I worked on, I started with a custom lightweight object model fulfilling exactly my needs. As usual, I then discovered I needed a way of requesting objects, persisting them or checking their consistency. And in all cases, I ended up rewriting part of Core Data, regretting not to have used it right from the start.
このライブラリの作者defagoさんは、Core Dataを非常に素晴らしい、といっていますね。最初から使っていれば良かった、と。私と同じ間違いはしないで、とも。Core Dataの全ての機能が必要なくても、かかる時間と頭痛を減らしてくれる、とも。
You should never make the same mistakes as I made. Even if you do not need all of Core Data features at the time you start a project, you can be sure that Core Data will save you a lot of time and headaches later. You just need a few model objects, nothing more? Well, that's not a reason not to use Core Data and an in-memory persistent store, which lets your conveniently design your model using the Xcode Core Data editor. When you later discover that your objects must finally be persisted on disk, all that is basically required is to change a single setting.
There are usually a few issues when working with Core Data, though:
Core Dataを使う場合、幾つかの課題がある、と。
  • There is a lot of boilerplate code to write, and the Xcode Core Data template is rather poor(boilerplate、すなわち決まり文句をたくさん書かなくてはならず、XcodeのCore Dataのテンプレートはやや貧弱)
  • The code becomes cluttered with managed object contexts, and issues can arise in multi-threaded applications if you use the wrong context by mistake
  • Validation is poorly implemented and leads to a lot of boilerplate code (e.g. for proper error-chaining), especially if you want to perform validation both interactively (when a model field is edited using a text field) or when an object is saved to the persistence store (ヴァリデーションの実装が貧弱で、お決まりのコードをたくさん書かなくてはならない。特に、インタラクティブなテキストフィールドを扱う場合や、persistence storeにセーブする場合。)
To solve all those issues, CoconutKit provides with:
で、CoconutKitが提供する解決策は、
  • HLSModelManager, a class which manages context and persistence store creation for you. (HLSModelManagerというクラスは、コンテクストを制御し、persistence storeをあなたのために作成してくれます)No more Xcode templates to use, everything has been done once for all.(Xcodeテンプレートを使う必要が無く、全てのことを一度に行います) To eliminate issues with explicit managed contexts thrown all over the place, you now never interact with managed contexts directly.  Instead, stacks of HLSModelManager objects are managed on a thread basis.(managed contextsに直接触れることなく、HLSModelManagerオブジェクトは、スレッドベースでマネージします) Context-free methods then allow you to perform usual CRUD operations with the managed object context associated with the top model manager only.
  • A validation runtime layer, which makes it possible to write validation methods once for all in a single place, and to call them both interactively and when saving objects to the store. Error-chaining has been implemented correctly, and text field bindings have been implemented so that form creation is made as easy as possible (it is just a matter of saying which model object field is edited by a text field, CoconutKit takes care of the rest)
また、作者さんのブログにCoconutKit1.1の時のCore Dataに関する記述もあったので、メモ。
(実装の具体例はないのが、残念。どこかにないかな。。)



Easy Core Data validation

Usually, when writing Core Data validation methods, you need to add a lot of boilerplate code to handle error chaining. Not only is error chaining easy to make wrong, it also clutters your precious business logic with Core Data code, making validation methods more difficult to maintain and reuse. Most notably, such validation methods cannot be reused for simple needs like validation of values entered interactively. Core Data validations are namely meant to be triggered by Core Data in a row once an object is saved to the store. It is often not what you want. 



CoconutKit 1.1 therefore introduces a new way to write validation methods, without the need to care about the usual Core Data boilerplate code. Your methods now can focus on business logic only, and can be easily called to validate fields individually when needed. 

But there is more. If you often write forms for editing Core Data objects (most notably made of text fields), you probably always end up writing the same kind of code: 

Calling the validation logic when the user exits edit mode for a text field
Synchronizing model fields with text fields in both model-to-view and view-to-model directions
Writing formatting code if values need to be formatted

These days are over. You now simply bind a text field to a model object field (providing an optional NSFormatter if needed), all the rest is handled for you. Your code will be faster and easier to write, understand, and maintain. 

I put a lot of effort to get this feature right, testing it extensively and ensuring it is really easy to use. I sincerely hope it will help you write better Core Data validation code.

:::::::::::::::::::::::::::::::

ソースを見ると、以下のファイル群あたりで実装されている様子。


HLSManagedTextFieldValidator.m
HLSModelManager.m
NSManagedObject+HLSExtensions.m
NSManagedObject+HLSValidation.m

まあ、まず自分で、Core Dataの基礎を学ばないと、手がつけられない感じです。
最初から楽をしよう、という心を反省して、基礎をまず学びます。

2013年2月4日月曜日

サンプルコード用実験遊び場、作成

作り途中のアプリに、サンプルコードを書いていくことは効率が今ひとつなので、
サンプルコードをガンガン書いて、適当に消していくProjectを作った。

遊び場は、大事ですね。
適当に遊ぶところから、本当に使えるものも生まれやすい。

playGroundで、適当にコードをコピペしながら、開発効率を上げていきます。

2013年1月22日火曜日

ccTypesの設定をメモ。

ccTypes.hというところに、
ccc3やccc4などの設定が書いてあり、勉強になったので、メモ。
http://www.cocos2d-iphone.org/api-ref/0.99.2/cc_types_8h_source.html

こうやって、便利な拡張をしていくんですね。為になる。

00020 #import <objc/objc.h>                           // BOOL
00021 #import <CoreGraphics/CGGeometry.h>     // CGPoint
00022 #import <OpenGLES/ES1/gl.h>                     // GLenum, GLubyte
00023 
00027 typedef struct _ccColor3B
00028 {
00029         GLubyte r;
00030         GLubyte g;
00031         GLubyte b;
00032 } ccColor3B;
00033 
00035 static inline ccColor3B
00036 ccc3(const GLubyte r, const GLubyte g, const GLubyte b)
00037 {
00038         ccColor3B c = {r, g, b};
00039         return c;
00040 }
00041 //ccColor3B predefined colors
00043 static const ccColor3B ccWHITE={255,255,255};
00045 static const ccColor3B ccYELLOW={255,255,0};
00047 static const ccColor3B ccBLUE={0,0,255};
00049 static const ccColor3B ccGREEN={0,255,0};
00051 static const ccColor3B ccRED={255,0,0};
00053 static const ccColor3B ccMAGENTA={255,0,255};
00055 static const ccColor3B ccBLACK={0,0,0};
00057 static const ccColor3B ccORANGE={255,127,0};
00059 static const ccColor3B ccGRAY={166,166,166};
00060 
00064 typedef struct _ccColor4B
00065 {
00066         unsigned char r;
00067         unsigned char g;
00068         unsigned char b;
00069         unsigned char a;
00070 } ccColor4B;
00072 static inline ccColor4B
00073 ccc4(const GLubyte r, const GLubyte g, const GLubyte b, const GLubyte o)
00074 {
00075         ccColor4B c = {r, g, b, o};
00076         return c;
00077 }

2013年1月19日土曜日

複数のMacで開発しようと試行錯誤。

複数のMACで開発する場合、
証明書の件で、ハードルがある様子。
http://tomorrow4u.wiki2.jp/archives/tag/xcode/page/2
http://www.senote.org/archives/441

家と職場のMacで、Dropboxを使ってフォルダを同期させ、開発を進めようとしているが、
何故か上手く起動しない。
何が課題だか、要調査。そもそも無理かな?(出来ました。下記、追記参照。)

:::::::::::::::::::::::::::::::

実機インストール手順をかつてやっていたが忘れたので、
良くまとまったサイトへのリンクを。
https://sites.google.com/site/iphonetopics/home/provisioningprofiles

:::::::::::::::::::::::::::::::

追記:無事、二台のMacで開発でき始めました。
.p12で証明書を書き出して、もう一台に送り、それを使って認証させるのが鍵でした。
たくさんそれについて書いておられるサイトがあるので、割愛いたします。
(例えばこことか:http://d.hatena.ne.jp/tksthdnr/20110723/1311417829 )

ファイルをDropboxで同期して快適になりました。
シンボリックリンクで実体ファイルから、Dropboxフォルダへ。
Dropbox同期は、かなり快適です。

2011年1月27日木曜日

テンプレートに学ぶ

これまで、プロジェクトの制作時に選択するテンプレートにあまり注目していませんでした。
が、よく考えてみれば、いろいろな基礎コードの書き方を教えてくれる模範例だと気づき、
ちょっと使ってみたことの無かったテンプレートを使ってみました。

勉強になりますね。
やはり、餅は餅屋。

右も左もわからない状態を少し抜けたら、
各テンプレートを、ニーズに合わせて見てみると、とても勉強になると気づけて、少し幸せでした。