For many of you, this sounds like a stupid thing. But for those that just use gcc -I from command line, can be a pain find how to do it.
So, the problem is. How can I specify my Include path in XCode (gcc -I./mypath).
Tap on your project target, and click “Get Info“, tap on “Build” tab and search “Path” as showed in the figure above. Then click on the “Header Search Paths” options and add your favorite include paths for selected target.
In the last years I’ve always used a “parallel task” approach foreach loops that I’ve in the code, not always to speedup but even to clean-up the code. How to do it? Wrapping threads and Thread Pool like in this C# Parallel Forech Code.
Snow Leopard has introduced a new BSD-level infrastructure, with simple and efficient API to do this job. Here a little usage preview.
Block objects are a C-based language feature that you can use in your C, Objective-C, and C++ code. Blocks make it easy to define a self-contained unit of work. Blocks are something like Actions (delegate {}) in C#. Very useful to embed function in loops.
Blocks looks like a “private” function pointer, but you can access to the “parent” vars. (If you’re a Python coder, you’ve exactly the same thing).
/* Blocks in Python...
* def main():
* a = 10
* def test(k):
* print a, k
* test(128)
*/
int main (int argc, const char *argv[]) {
int a = 12;
void (^test_block) (int) = ^(int k) {
printf("A Block: PARENT(%d) ARG(%d)\n", a, k);
};
test_block(128);
return 0;
}
The GCD queue API provides dispatch queues from which threads take tasks to be executed. Because the threads are managed by GCD, Mac OS X can optimize the number of threads based upon available memory, number of currently active CPU cores, and so on. This shifts a great deal of the burden of power and resource management to the operating system itself, freeing your application to focus on the actual work to be accomplished.
#include <dispatch/dispatch.h>
#include <stdlib.h>
#include <stdio.h>
#define ITEM_VMIN (1)
#define ITEM_VMAX (200)
#define NR_ITEMS (100)
static void __fill_item (void *items, size_t n) {
int *i_items = (int *)items;
i_items[n] = (ITEM_VMIN + (int)(ITEM_VMAX * ((double)rand() / RAND_MAX)));
}
static void __work_on_item (void *items, size_t n) {
int *i_items = (int *)items;
i_items[n] *= 100; /* Do some Computation on this Item */
}
int main (int argc, const char *argv[]) {
dispatch_queue_t queue;
int data[NR_ITEMS];
/* Get Global Dispatch Queue */
queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
/* Initialize data Elements, and run computation on each element */
dispatch_apply_f(NR_ITEMS, queue, data, __fill_item);
dispatch_apply_f(NR_ITEMS, queue, data, __work_on_item);
/* Brief review of the items */
dispatch_apply(NR_ITEMS, queue, ^(size_t n) {
printf("Results: Item %lu = %d\n", n, data[n]);
});
return 0;
}
Yesterday I’ve played a bit with AVAudioRecorder, and this is a very small and funny example.
The main Idea is to create something like a wind mill that works with voice instead of wind.
The code below shows you how to record something. Then with the updateMeters() and peakPowerForChannel() you can extract the audio “noise”.
Yesterday, Fredrik has asked me something like “Drag & Drop with Hit Test” on the iPhone. Here’s a simple example. There’s a simple UIView class that handles the touch events and a protocol that says that if the “DragMe View” has hit or not the “HitMe View”. Below you can see the result and the Source Code Link.
In a time of REST protocols… I still love the Binary Communication. I don’t have much ideas this period, I need to find a different job (C# doesn’t fit my code necessity). The Example Source code, contains two Folder. One is the Qt4 TcpServer the second one is the ugly application that you can see below
Note: This example doesn’t have anything related to the Qt 4.5 Cocoa Support.
Run the Qt4 Server, and the Cocoa Application (Remember to change the SERVER_HOST in AppController.m) and try to send some binary data. The Qt Server will receive this data it will resend you. Protocol is Very easy 1 byte of Data Type (Int8, Int16, ..) and Data. Remember that Intel arch is Little Endian.
Note: This is just a “Draft” a “non complete” example only to give the idea on how it works.
Back to the real iPhone for a while… Gravatar, or globally recognized avatar, is an interesting free service. It can be integrated with AddressBook app or other apps that can have a picture related to email address. Here an Objective-C Example to retrive the Gravatar. It’s really simple!
The Apple Worldwide Developers Conference (WWDC) takes place June 8-12, 2009 held at Moscone Center West in San Francisco. http://developer.apple.com/WWDC/.
Joel asked me to revise the Sidebar, allowing to add/remove and do other operation at any time.
I’ve rewritten all the code of the Sidebar, and I’ve added a couple of new features, like the default action handler and obviously the ability to add, remove items and badges at any time.
All the past features, like Drag & Drop are still present, but there’s something else to do to improve it. If You’ve suggestions, patches or something else post a comment or send me a mail!