foundation

How to Autorelease a CGImageRef?

北城以北 提交于 2019-12-19 04:10:51
问题 I have a method that returns a CGImageRef object. It contains this call: CGImageRef posterFrame = [avAssetImage copyCGImageAtTime:time actualTime:nil error:&error]; ... return posterFrame; This situation, as I understand it, calls for an autorelease. But I have no idea how to do it. I've tried using CFCollectable() , but it doesn't work. Any ideas? 回答1: If you're using garbage collection, use CFMakeCollectable(posterFrame) . If you're using traditional memory management, it's very

How for in loop works internally - Objective C - Foundation

為{幸葍}努か 提交于 2019-12-19 03:40:58
问题 I found this answer: https://stackoverflow.com/a/5163334/1364174 Which presents how for in loop is implemented. NSFastEnumerationState __enumState = {0}; id __objects[MAX_STACKBUFF_SIZE]; NSUInteger __count; while ((__count = [myArray countByEnumeratingWithState:&__enumState objects:__objects count:MAX_STACKBUFF_SIZE]) > 0) { for (NSUInteger i = 0; i < __count; i++) { id obj = __objects[i]; [obj doSomething]; } } The problem is that, I found it wrong. First of all, when you have Automatic

Visual Studio 2005的各个版本

爷,独闯天下 提交于 2019-12-18 16:02:23
支持正版,做DotNet开发,工具选择不二是Vistual Studio 2005,需要了解各个版本的内容相关的Licence: A:Visual Studio Express Products (a):Visual Web Developer 2005 Express Edition (b):Visual Basic 2005 Express Edition (c):Visual C# 2005 Express Edition (d):Visual J# 2005 Express Edition (e):Visual C++ 2005 Express Edition B:Visual Studio Standard Edition Intellisense, Code Editor, Code Snippets, All .NET lanaguages, Simplified Menu, Mobile Device Support, Local and Remote Database Design Tools, Class Designer/Object Test Bench, Local Debugging, SQL 2005 Express, MSDN C:Visual Studio Professional Edition Evertthing included in

How to integrate iCloud on a non Document-based app?

隐身守侯 提交于 2019-12-18 12:38:18
问题 I've read the Apple docs and Ray Wenderlich's tutorial. It seems that I'm forced to use UIDocument so I read it up in the docs. I've found that it's effective to use Document-based approach. My problem is I don't want to be tied in techniques specific to the platform (iOS) thus my app has its own models made from scratch that only inherit from NSObject. This includes saving/loading. Now, I need to integrate iCloud along with my old models. How will I do it in an elegant/effective way where I

How to delete the contents of the Documents directory (and not the Documents directory itself)?

百般思念 提交于 2019-12-18 12:19:19
问题 I want to delete all the files and directories contained in the Documents directory. I believe using [fileManager removeItemAtPath:documentsDirectoryPath error:nil] method would remove the documents directory as well. Is there any method that lets you delete the contents of a directory only and leaving the empty directory there? 回答1: Try this: NSString *folderPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSError *error = nil; for

Adding an object at a specific index of an NSMutableArray

橙三吉。 提交于 2019-12-18 11:14:06
问题 How can an object be added at a specific index of an NSMutableArray ? How is an object added to the front of the array? 回答1: [myMutableArray insertObject:myObject atIndex:42]; To add an object to the front of the array, use 0 as the index: [myMutableArray insertObject:myObject atIndex:0]; 回答2: Take a look at the insertObject:atIndex: method of the NSMutableArray class. Adding to the "front" of the array implies index 0. For example: NSMutableArray * array = [[NSMutableArray alloc]

Read input from a cocoa/foundation tool console?

时间秒杀一切 提交于 2019-12-18 04:26:09
问题 I wonder if Objective-C/Foundation has any special commands for reading user input from the console. Since it has NSLog for output maybe there is something else I could use instead of the scanf command. I need to read some numbers (user input) into my tool. What is the best way to get these input in types like double or int? And how do I get user input into an NSString? 回答1: I was bored earlier and came across this issue of 'use scanf'. since I wanted to see if I could do it without dropping

CFRunLoopRun() vs [NSRunLoop run]

别说谁变了你拦得住时间么 提交于 2019-12-18 03:12:26
问题 I have an NSRunLoop object, to which I attach timers and streams. It works great. Stopping it is another story alltogether. I run the loop using [runLoop run] . If I try to stop the loop using CRunLoopStop([[NSRunLoop currentRunLoop] getCFRunLoop]) , the loop won't stop. If I start the loop using CRunLoopRun() instead, it works. I have also made sure that the call is made on the correct thread (the one running my custom run loop). I have debugged this with pthread_self() . I found a mailing

How to list all folders and their subdirectories/files in iPhone SDK?

邮差的信 提交于 2019-12-17 23:33:13
问题 I want the user to select any file present in her/his iPhone so that it’s used as an e-mail attachment. For this purpose, I want to show the list of all files and folders present in iPhone. But how would I get the list of those files? Is there any way to get that list? 回答1: Take into account that your app runs in a sandbox and would not be able to get any folder/file outside of that sandbox. ObjectiveC NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,

What is the data structure behind NSMutableArray?

本小妞迷上赌 提交于 2019-12-17 22:34:22
问题 Usually, a "mutable array" class is implemented as a wrapper around a simple array. The wrapper allocates more memory when you add an element past the end. This is a common data structure and the performance of the various operations is well known. You get O(1) element access, O(N) insert and remove, or O(1) (on average) insert and remove at the end of the array. But NSMutableArray is something else. For example the docs say [emphasis mine]: Note: Most operations on an array take constant