---yarshure kong的珍藏
Model: Model classes describe your data. For example, if you write banking systems, you would probably create a model class called SavingsAccount that would have a list of transactions and a current balance. The best model classes include nothing about the user interface and can be used in several applications.
View: A view class is part of the GUI. For example, NSSlider is a view class. The best view classes are general-purpose classes and can be used in several applications.
Controller: Application-specific controller classes are responsible for controlling the flow of the application. The user needs to see the data, so a controller object reads the model from a file or a database and then displays the model by using view classes. When the user makes changes, the view objects inform the controller, which subsequently updates the model objects. The controller also saves the data to the filesystem or database.
@property (attributes) type name;
The attributes can include readwrite (the default) or readonly. A property marked readonly gets no setter method.
To describe how the setter method should work, the attributes can also include one of the following: assign, retain, copy. Let's look at each in turn:
assign (the default) makes a simple assignment happen. assign does not retain the new value. If you are dealing with an object type and you are not using the garbage collector, you probably don't want assign.
retain releases the old value and retains the new value. This attribute is used only for Objective-C object types. If you are using the garbage collector, assign and retain are equivalent.
copy makes a copy of the new value and assigns the variable to the copy. This attribute is often used for properties that are strings.
Finally, the attributes can also include nonatomic. If your application is multithreaded, it is sometimes important that your setter methods be atomic. That is, the execution of the setter method from one thread will not conflict with the execution of the same setter method on another thread. By default, the @synthesize call will generate accessors with this property. On an application that is not using the garbage collector, this involves using a lock to ensure that only one thread at a time is executing the setter. Creating and using the locks introduces some overhead. If you know that the accessors for a property don't need to be atomic, you can eliminate the overhead by adding nonatomic to the attributes.
The Cocoa bindings technology offers a way to increase the functionality and consistency of your application while at the same time decreasing the amount of code you have to write and maintain. It takes care of most aspects of user interface management for you by allowing you to off load the work of custom glue code onto reusable pre-built controllers. It helps you build polished, easy-to-use applications that leverage object relationships, provide sortable tables, and include intelligent selection management.
Typically you do not need to completely rewrite your application in order to adopt Cocoa bindings. For example, it is likely that you can factor out User Preferences to be managed by Cocoa bindings without affecting the rest of an application. You will find it easier to make use of Cocoa bindings if your application adopts the recommended design patterns.
Cocoa applications generally adopt the Model-View-Controller (MVC) design pattern. When you develop a Cocoa application, you typically use model, view, and controller objects, each of which performs a different function. Model objects represent data and are typically saved to a file or some other permanent data store. View objects display model attributes. Controller objects act as go-betweens, to make sure that what a view displays is consistent with the corresponding model value and that any updates a user makes to a value in a view are propagated to the model. An understanding of the MVC design pattern is essential to fully understand and leverage Cocoa bindings. If you need to know more, read "The Model-View-Controller Design Pattern."
If you adopt the MVC design pattern, much of your application code is easier to reuse and extend--you can reuse model and view classes in different applications. Much of the implementation of a controller object consists of what is commonly referred to as "glue code." Glue code is the code that keeps the model values and views synchronized, and is unique to each application. It is typically tedious and cumbersome to write, contributes little to the fundamental function of the application, but you must do it well to provide a good user experience.
七月关于 iPhone 的消息一直围绕着 2.0 firmware, iPhone 3G, official SDK 1.0 这几个关键词,而非官方关心的也只是 Pwnage Tool 2.0,却对没有 iPhone Developer Program 的开发进展甚少介绍,我想在这里做一点记录。
随着 SDK 1.0 的正式发布 (遗憾的是,因为 NDA 的存在,甚至它都算不上发布..),iPhone 2.0 firmware 和 App Store 的上线,在 Apple 监视下的 iPhone OS/Cocoa Touch 程序开发的局限性暴露得越来越明显,saurik, NerveGas 等开发者坚持开发 Open Toolchain 的重要性也越来越明显。为什么在拥有一个如此完善的 SDK 的情况下我们还需要 Open Toolchain 和相关工具?因为:
因为上面这些原因,我一直非常关注 open toolchain 的开发,到了 4 月份的时候,有半个月的时间一直在跟踪 saurik 在这方面开发的结果,其结果是这篇 Upgrading the iPhone Toolchain,可惜的是因为 saurik 一直不满意用 git 来跟踪上游代码的修改,所以这篇文章其实相当难付诸实施,不过,考虑到 SDK 1.0 的发布后上游代码应该有一个相对稳定期,所以希望 saurik 能够尽快整理出更新的文档和代码来吧。
不过 saurik 在他的 Cydia repo 里提供了 iPhone 上完整的 toolchain,你可以在自己的 iPhone/iPod Touch 上用 gcc 编译,用 gdb 调试.... 当然考虑到有限的硬件资源,这种方式对很多人来说太 geeky 了,包括我。
然而,目前用官方 SDK 提供的编译器和调试器来给编写在 pwn 过的 iPhone 上免费分发的应用程序已经完全可行了,详情可以参考 saurik 的 Bypassing iPhone Code Signatures 和 246tNt 的说明。未 pwn 的 iPhone 因为目前事实上只有通过 App Store 一条路安装应用程序,所以谈怎么分发也是没有意义的。
简单的说,这种方式是因为 pwn 过的 iPhone 的内核已经被打上了 patch,弱化了签名校验----不再要求非要有 Apple 的签名了,可是签名校验依然存在,要完全去掉不大现实,所以现在你可以通过 Apple 自己提供的 codesign 工具来给应用自行签名,或者在别的平台下用 saurik 开发的 ldid 签名工具来保证通过 iPhone 的签名检查。对于大部分 Mac 开发者而言,这也只是在 Xcode 的项目中,新增一个 Build Phase 的事情,所以不会增加什么工作量。
而 246tNt 进一步延展了 saurik 的工作,分析了 entitlements 文件在签名后的 iPhone App 中对安全控制的作用,使得这种自签名的应用程序也能像有 Dev Program 的应用一样,可以用 Xcode 自带的 gdb 进行远程调试。此外,246tNt 还找出了办法对 iPhone OS 中的 SpringBoard 和 MobileInstallation 打上补丁,使得我们可以直接把应用程序用 Xcode Organizer (或者 Build and Go!) 上传到 iPhone 上,并自动开始调试。
感谢这些开发者的工作,目前我们获得的开发环境和支付了 $99 美元的 Dev Program 开发者毫无二致了。可是,分发环境还是有区别,假定我们的程序并没有做任何逾越 SDK 授权的事情,如果还希望通过 App Store 分发,那还是只能去购买 Dev Program。不过毫无疑问,对于开放的应用程序而言,Cydia 应该是更好的分发方式,考虑到因为 Pwnage Tool 2.0 的包含,Cydia 几乎已经成为了标准的应用分发方式。
(待续)
The new solution, introduced in 10.5, is a garbage collector, which babysits the entire object graph, looking for objects that can't be reached from the variables that are in scope. The unreachable objects are automatically deallocated
为什么不一直使用GC? If you use the garbage collector, your application will not run on any version of Mac OS before 10.5. Also, the garbage collector requires some CPU time to scan through the objects, looking for garbage. This can sometimes result in poorer performance. In an application that does a lot of audio or video processing, the garbage collector can cause hiccups in the processing while it is doing a scan.
Rules Concerning Release Objects created by alloc, new, copy, or mutableCopy have a retain count of 1 and are not in the autorelease pool. If you get an object by any other method, assume that it has a retain count of 1 and is in the autorelease pool. If you do not wish it to be deallocated with the current autorelease pool, you must retain it.


Objective-C programmers use a few types that are not found in the rest of the C world.
BOOL is the same as char but is used as a Boolean value.
NO is 0.
IBOutlet is a macro that evaluates to nothing. Ignore it. (IBOutlet is a hint to Interface Builder when it reads the declaration of a class from a .h file.)
IBAction is the same as void and acts as a hint to Interface Builder.
nil is the same as NULL. We use nil instead of NULL for pointers to objects.
- (void)setCalendarFormat:(NSString *)format
This method sets the default calendar format for the receiver. A calendar format is a string formatted with date-conversion specifiers, as given in Table 3.2.





char *str="Hello, world!"; // 我們想提供建立的字串
CFStringRef cfstr=CFStringCreateWithCString(NULL, str, kCFStringEncodingUTF8);
// 用字串...
CFRelease(cfstr); // 把建立好的字串釋放掉
char *str="Hello, world!";
NSString *nsstr=[[NSString alloc] initWithCString: str];
// 用字串
[nsstr release];
NSString *s=[NSString stringWithContentsOfURL: [NSURL URLWithString: @"http://www.google.com"]];
printf ("%s\n", [s UTF8String]);