[Mac OSX]Mac OS X Developer分享与实践
来源:互联网 发布:淘宝主播排名榜在哪看 编辑:程序博客网 时间:2024/05/20 05:57
转自
http://hi.baidu.com/hesper/blog/item/da9975ec6820e8d62e2e2102.html
是类似Objective-C的JavaScript扩展,运行在客户端,内建了一个强大的图形引擎,方便地支持打开或保存文档,或者拷贝和粘帖等任务。
Objective-C
什么是Objective-C
扩充C的面向对象编程语言
Mac OS X,OpenStep主要开发语言
1980年代Brad Cox在Stepstore发明
如果是初学Cocoa,请安装XCode 3(iPhone2发布后会更新会XCode 3.1,Interface Builder renew)学习Foundation.framework(Foundation全称Foundation Framework,是Cocoa的一个子开发框架。Foundation里包含了Cocoa中最基本的一些类,它们在一个Mac应用程序中通常负责对象管理、内存管理、容器等相关数据结构的操作。),就像学习.net framework或者JSDK一样,深入学习后可以开始学习CoreFoundation.framework。
Cocoa Framework简称Cocoa,它是Mac OS X上的快速应用程序开发(RAD, Rapid Application Development)框架,一个高度面向对象的(Object Oriented)开发框架。Cocoa是Mac OS X上原生支持的应用程序开发框架,苹果公司强烈推荐所有Mac开发人员使用。Cocoa Framework都是由Objective-C/C实现的。
OS X程序框架
?View Code OBJECTIVEC
#import
int main (int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
[pool release];
}
命令行编译:cc -o test -framework Foundation file-name.m
Hello World!
import <Foundation/Foundation.h>
?View Code OBJECTIVEC
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Hello, World!");
[pool drain];
return 0;
}
//NSAutoreleasePool是可控制的延迟对象释放的内存管理。方括号中间的内容表示对对象(或类)进行一次方法的调用
函数
例子,返回最佳的文件大小格式
?View Code OBJECTIVEC
- (NSString *)stringFromFileSize:(int)theSize
{
float floatSize = theSize;
if (theSize<1023)
return([NSString stringWithFormat:@"%i bytes",theSize]);
floatSize = floatSize / 1024;
if (floatSize<1023)
return([NSString stringWithFormat:@"%1.1f KB",floatSize]);
floatSize = floatSize / 1024;
if (floatSize<1023)
return([NSString stringWithFormat:@"%1.1f MB",floatSize]);
floatSize = floatSize / 1024;
return([NSString stringWithFormat:@"%1.1f GB",floatSize]);
}
Objective-C 2.0有property和garbage collection(简化了多线程程序的内存管理,Leopard+)
定义一个类// Student.h
?View Code OBJECTIVEC
#import <Cocoa/Cocoa.h>
@interface Student : NSObject <NSCoding> {
NSString *name;
NSString *studentNO;
}
@property(copy) NSString *name;
@property(copy) NSString *studentNO;
@end
// Student.m
#import "Student.h"
@implementation Student
@synthesize name;
@synthesize studentNO;
@end
示范处理函数中调用该类:
?View Code OBJECTIVEC
Student *hayes = [[Student alloc] init];
hayes.name = @"hayes";
hayes.studentNO = @"00001";
NSLog(@"%@", hayes.name);
//NSLog就像printf,定义在NSObjCRuntime.h中,范例:
NSLog (@”string is :%@”, string);
NSLog (@”x=%d, y=%d”, 10, 20);
//需要注意的参数是NSString,如果是其他类型,参考:
%@ 对象
%d, %i 整数
%u 无符整形
%f 浮点/双字
%x, %X 二进制整数
%o 八进制整数
%zu size_t
%p 指针
%e 浮点/双字 (科学计算)
%g 浮点/双字
%s C 字符串
%.*s Pascal字符串
%c 字符
%C unichar
%lld 64位长整数(long long)
%llu 无符64位长整数
%Lf 64位双字
Cocoa处理消息的方法是Delegate和NSResponse类的重载实现。所有平台下的GUI程序都基本以消息驱动的,应用程序就是在处理消息的循环中进行的。键盘输入、鼠标点击或直接派发给应用程序的对象、控件,当一个对象接受到某个事件或者通知的时候,会向它的Delegate对象查询它是否能够响应这个事件或者通知,如果可以这个对象就会给它的Delegate对象发送一个消息。
?View Code OBJECTIVEC
if (delegate != nil && [delegate respondsToSelector:@selector(theEvent)])
{
[delegate performSelector:@selector(theEvent)];
}
淡入淡出窗口代码
?View Code OBJECTIVEC
#import
#import “FadeWindowController.h”
@implementation FadeWindowController
- (IBAction)showWindow:(id)sender
{
// If the window was hidden, animate its alpha value so it fades in.
if (![self.window isVisible])
{
self.window.alphaValue = 0.0;
[self.window.animator setAlphaValue:1.0];
}
[super showWindow:sender];
}
- (BOOL)windowShouldClose:(id)window
{
// Animate the window’s alpha value so it fades out.
[self.window.animator setAlphaValue:0.0];
// Don’t close the window immediately so we can see the animation.
return NO;
}
- (void)awakeFromNib
{
CAAnimation *anim = [CABasicAnimation animation];
[anim setDelegate:self];
[self.window setAnimations:[NSDictionary dictionaryWithObject:anim forKey:@"alphaValue"]];
}
- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag
{
if(self.window.alphaValue == 0.00) [self close]; //detect end of fade out and close the window
}
@end
OpenGL Programming on Mac
Addison.Wesley_-_OpenGL.programming.on.Mac.OS.X.Dec.2007.rar
CocoaCast (AppleTV HD) RSS
Podcast of Cocoa Programming for Mac OS X 2nd Edition
Mac外围和驱动开发
在HID 驱动开放接口上,或者开源的Darwin上找资料,实现的协议就参考各个平台支持的设备基础协议。
iPhone OS
Core OS
OS X Kernel
Lib System
BSD TCP/IP
Sockets
Security
Power Mgmt
KeyChain
Certificates
File System
Bonjour
Core Service
Collections
Address Book
Networking
File Access
SQLite
Core Location
Net Services
Threading
Preferences
URL utilites
Media
Core Audio
OpenAL
Audio Mixing
Audio Record
Video Playback
JPG,PNG,TIFF
PDF
Quartz(2D)
Core Animation
OpenGL ES
Cocoa Touch
Multi-Touch Events
Multi-touch Controls
Accelerometer
View Hierarchy
Localization
Alerts
Web View
People Picker
Image Picker
Camera
IPhone游戏开发
3D 性能30fps,Accelerometer,使用Instuments的OpenGL ES Measure
OpenAL Framework
Mediaplayer Framework
OpenGL ES Framework
Ref
iPhone Application And Website Development: All Tools And Tutorials You Need
文章 & 教程:
- Cocoa Dev Central - http://cocoadevcentral.com/
- Theocacao - http://theocacao.com/
- O’Reilly - MacDevCenter.com - http://www.macdevcenter.com/
- Roughly Drafted Magazine - http://www.roughlydrafted.com/
Podcasts:
- CocoaCast - http://www.cocoacast.com/
- Cocoa Radio - http://www.cocoaradio.com/
- Late Night Cocoa
- http://www.macdevnet.com/index.php?option=com_content&view=category&layout=blog&id=37&Itemid=160
- Mac Developer Roundtable
- http://www.macdevnet.com/index.php?option=com_content&view=category&layout=blog&id=38&Itemid=161
- Mac Software Business
- http://www.macdevnet.com/index.php?option=com_content&view=category&layout=blog&id=39&Itemid=162
Community
- Cocoabuilder - http://www.cocoabuilder.com/
- Cocoa Literature
- http://osx.hyperjeff.net/reference/CocoaArticles.php
- CocoaDev - http://www.cocoadev.com/
- Sinomac 渤麦堂 - http://www.sinomac.com/modules/news/
- MacPorts - http://www.macports.org/
- IndieHIG - http://indiehig.com/wiki/Main_Page
- Cocoaforge - http://forums.cocoaforge.com/
- [Mac OSX]Mac OS X Developer分享与实践
- IOS与Mac OS X
- Mac OS X 10.5系统部署实践
- Mac OS 的一点历史: Mac OS, Mac OSX 与Darwin
- 64位与Mac OS X Tiger
- Mac OS X Server 安装与应用
- mac os X 与 iOS备忘录
- ios8与mac os x yosemite协同
- Mac OS X 用户与账号介绍
- Mac OS X - Miscellaneous
- Securing Mac OS X
- Mac OS X Programming
- mac os x自动关机
- Mac OS X 快捷键
- MAC OS X系统
- Mac OS X截图
- Mac OS X快捷键
- Mac OS X 命令行
- sql 函式
- web developer tips (8):创建web用户控件并包含在web页面里
- jBPM中的assignment
- Head First C# 中文版 第12章 回顾与前瞻 page537
- BMP位图文件结构及VC操作
- [Mac OSX]Mac OS X Developer分享与实践
- WML 参考手册
- HTML精确定位
- 二元二次 - 有待通用化为N元N次
- sql操作access时出现 MSDTC错误,服务器 'SERVER' 上的 MSDTC 不可用。
- 在Visual Studio IDE的输出窗口中写入跟踪信息
- 股票T+0的运用技巧
- 自动光学检查(AOI) 的核心——快速准确对目标进行定位配准
- 35岁之前成功12条法则收藏