初学mac开发

昨天看来一天官方文档.由于从ios转向mac开发.有很多相似之处.


相似之处:mac os 10.7开始使用sandbox.


不同之处:

1,路径问题:

Applications directory     (/Applications)

Regardless, you should not need to use this path directly. To access resources inside your application bundle, use an NSBundle object instead.

应用程序路径,官方说没用,有用没用以后再说.

Home directory

10.7使用sandbox,这个路径是只sandbox的根目录

10.7以前,这个路径是/Users

NSHomeDirectory()函数获得

Library directory

10.7中和ios中一样.有个library的文件夹

10.7以前文档中也没说.猜测是/Library和~/Library

NSLibraryDirectory()函数获得

Application Support directory

分为所有用户和当前用户.如果想要所有用户都使用,那就要使用NSLocalDomainMask,如果是当前用户NSUserDomainMask

NSFileManager* fileManager = [NSFileManager defaultManager];

NSURL* appSupportDir = nil;

NSArray *urls = [fileManager URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask];

if ([paths count] > 0) {

   appSupportDir = [[urls objectAtIndex:0] URLByAppendingPathComponent:@"com.example.MyApp"];

}

或者也可以查找

NSArray * temparray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);


Caches directory

Movies directory

Music directory

Pictures directory

上述几个和application support的获得方法一样.

Temporary directory

路径通过NSTemporaryDirectory()获得


2,Automatic and Sudden Termination

Automatic Termination,在用户点击红叉的时候,自动退出.

2种开启方式

  • Include the NSSupportsAutomaticTermination key (with the value YES) in the application’s Info.plist file.
  • Use the NSProcessInfo class to declare support for automatic termination dynamically. You can also use this class to change the default support of an application that includes the NSSupportsAutomaticTermination key in its Info.plist file.

Sudden Terminnation,在系统关机,或注销的时候使用.

2种开启方式

  • Include the NSSupportsSuddenTermination key (with the value YES) in the application’s Info.plist file.
  • Use the NSProcessInfo class to declare support for sudden termination dynamically. You can also use this class to change the default support of an application that includes the NSSupportsSuddenTermination key in its Info.plist file.

3,Garbage Collection

在build setting中搜索garbage可以找到它的设置
unsupport,关闭
support,同时支持retain/release和垃圾回收机制
required,只开启垃圾回收机制,retain,release失去作用.

GC的优缺点:

Garbage collection offers some significant advantages over a reference-counted environment:

  • Most obviously, it typically simplifies the task of managing memory in your application and obviates most of the memory-related problems that occur, such as retain cycles.
  • It reduces the amount of code you have to write and maintain, and may make some aspects of development easier—for example, zeroing weak references facilitate use of objects that may disappear.
  • It usually makes it easier to write multi-threaded code: you do not have to use locks to ensure the atomicity of accessor methods and you do not have to deal with per-thread autorelease pools. (Note that although garbage collection simplifies some aspects of multi-threaded programming, it does not automatically make your application thread-safe. For more about thread-safe application development, see Threading Programming Guide.)

Garbage collection does though have some disadvantages:

  • The application’s working set may be larger.
  • Performance may not be as good as if you hand-optimize memory management (for more details, see “Performance”).
  • A common design pattern whereby resources are tied to the lifetime of objects does not work effectively under GC.
  • You must ensure that for any object you want to be long-lived you maintain a chain of strong references to it from a root object, or resort to reference counting for that object.
个人习惯,不开启..影响效率,类内成员调用不方便..也可能是我以前用C++的原因.可能java程序员喜欢..
把GC开启后,我有种用java写android的感觉,每次调用控件,还要重新获得其指针,才能使用.不在我掌握中啊..
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值