### Archive

Archive for April, 2010

## iPhone Simulator Screenshots

With this tool it’s really easy to take screenshots:
http://www.curioustimes.de/iphonesimulatorcropper/index.html

Categories: iOS, iOS Simulator, Xcode

## Mapping a shared folder

press cmd + k or open in „Finder“ the menu „Gehe zu“ -> „Mit Server verbinden…“

enter path to network drive

Example:

Categories: Mac OS X

## NTFS read and write

Categories: Mac OS X

## Standard-Setter

#import <Cocoa/Cocoa.h>

@interface Instrument : NSObject {
NSString*   name;
[…]
}
[…]

//  Accessoren
- (NSString*)name;
- (void)setName:(NSString*)name;
@end

#import "Instrument.h"
[…]
@implementation Instrument
- (void)setName:(NSString*)value {
if (name != value) {
[name autorelease];
name = [value retain];
}
}
@end

Categories: CodeSnippets, iOS

## Screenshots with Mac OS X

 Shortcut Description Command + Shift + 3 Screenshot of whole screen and save the created file on desktop Command + Shift + Ctrl + 3 Screenshot of whole screen and save in clipboard Command + Shift + 4 Choose area with crosshairs Command + Shift + 4 + space Sreenshot of active area Command + Shift + Ctrl + 4 Choose area with crosshairs and save in clipboard Command + Shift + F4 Screenshot of window

Screencapture

Execute the following command in terminal to start the screencapture program with:

screencapture -i ~/Desktop/screenshot

Changing the format of screenshot

• Execute the following command in terminal:

defaults write com.apple.screencapture type <type>

allowed types are: png, jpg, tiff, bmp, pdf

• Restart the UIServer:

killall systemuiserver

Categories: Mac OS X

## Core Data

– Add Core Data Framework and the SQlite library “libsqlite3.dylib” to your project.
– Create managed object model
– Use NSManagedObject as parent class of your entity classes or generate class out of the object model file/new file/…
– Add following to your App Delegate to set up the Managed Objects and the Managed Object Context:


...
@interface AppDelegate : NSObject <UIApplicationDelegate> {
...
NSManagedObjectModel *managedObjectModel;
NSManagedObjectContext *managedObjectContext;
NSPersistentStoreCoordinator *persistentStoreCoordinator;
...
}
@property (nonatomic, retain, readonly) NSManagedObjectModel
*managedObjectModel;
@property (nonatomic, retain, readonly) NSManagedObjectContext
*managedObjectContext;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator
*persistentStoreCoordinator;
...

@implementation AppDelegate
...
managedObjectModel = [[NSManagedObjectModel alloc] init];
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]
initWithManagedObjectModel:managedObjectModel];
managedObjectContext = [[NSManagedObjectContext alloc] init];
[managedObjectContext setPersistentStoreCoordinator:
persistentStoreCoordinator];
...


By convention, you can often get a context from a view controller. It’s up to you, though, to follow this pattern.
When you implement a view controller that integrates with Core Data, you can add an NSManagedObjectContext property.
A view controller typically shouldn’t retrieve the context from a global object such as the application delegate. This tends to make the application architecture rigid. Neither should a view controller typically create a context for its own use. This may mean that operations performed using the controller’s context aren’t registered with other contexts, so different view controllers will have different perspectives on the data.
When you create a view controller, you pass it a context. You pass an existing context, or (in a situation where you want the new controller to manage a discrete set of edits) a new context that you create for it. It’s typically the responsibility of the application delegate to create a context to pass to the first view controller that’s displayed.

Create and save a Managed Object:


ManagedObject* managedObject = (ManagedObject*) [NSEntityDescription
insertNewObjectForEntityForName:@"ManagedObject"
inManagedObjectContext:managedObjectContext];
NSError* error;
if(![managedObjectContext save:&error]) {
// Error handling
   NSLog(@"Unresolved Core Data Save error %@, %@",
error, [error userInfo]);
}


Create the Request:

NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event"
inManagedObjectContext:managedObjectContext];
[request setEntity:entity];

Set the Sort Descriptor:

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
initWithKey:@"creationDate" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc]initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
[sortDescriptors release];
[sortDescriptor release];

Set the predicate:


(NSPredicate *) predicate = [NSPredicate
predicateWithFormat:@"(Name == %@)", @"Fred"];
[request setPredicate:predicate];


Execute the Request:

NSError *error;
NSMutableArray *mutableFetchResults = [[managedObjectContext
executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil) {
// Handle the error.
}

Finish Up:

[self setEventsArray:mutableFetchResults];
[mutableFetchResults release];
[request release];

Update managed data object with key-value-coding:

[managedObject setValue:@"Tea Time with Moby" forKey:@"title"];
NSError* error;
if(![managedObjectContext save:&error]) {
// Error handling
}

Getting a value with key-value-coding:

[managedObject valueForKey:@"title"];

Deleting Managed Object:

[managedObjectContext deleteObject:managedObject];
NSError* error;
if(![managedObjectContext save:&error]) {
// Error handling
}


Request example:

+(NSMutableArray *) searchObjectsInContext: (NSString*)
entityName : (NSPredicate *) predicate : (NSString*) sortKey : (BOOL)
sortAscending : (NSManagedObjectContext *) managedObjectContext
{
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:entityName
inManagedObjectContext:managedObjectContext];
[request setEntity:entity];

// If a predicate was passed, pass it to the query
if(predicate != nil)
{
[request setPredicate:predicate];
}

// If a sort key was passed, use it for sorting.
if(sortKey != nil)
{
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
initWithKey:sortKey ascending:sortAscending];
NSArray *sortDescriptors = [[NSArray alloc]
initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
[sortDescriptors release];
[sortDescriptor release];
}

NSError *error;

NSMutableArray *mutableFetchResults = [[[managedObjectContext
executeFetchRequest:request error:&error] mutableCopy] autorelease];

[request release];

return mutableFetchResults;
}

+(NSMutableArray *) getObjectsFromContext: (NSString*) entityName : (NSString*)
sortKey : (BOOL) sortAscending : (NSManagedObjectContext *)
managedObjectContext
{
return [self searchObjectsInContext:entityName :nil :sortKey
:sortAscending :managedObjectContext];
}
Categories: CodeSnippets, iOS, Xcode

## Animating views

Example based on a PickerView.
Include Quartz framework (QuartzCore.framework) and import its header file (QuartzCore/QuartzCore.h) to your controller.


CATransition *animation = [CATransition animation];
[animation setDelegate:self];
// Set the type and if appropriate direction of the transition,
[animation setType:kCATransitionMoveIn];
[animation setSubtype:kCATransitionFromTop];
// Set the duration and timing function of the transtion --
// duration is passed in as a parameter,
// use ease in/ease out as the timing function
[animation setDuration:0.4];
[animation setTimingFunction:[CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionLinear]];
[[PickerView layer] addAnimation:animation forKey:@"transitionViewAnimation"];

PickerView.hidden = FALSE;

[[PickerView layer] removeAnimationForKey:@"transitionViewAnimation"];
animation = nil;


Categories: CodeSnippets, iOS

## Two macs. One iPhone Developer License

Step 1: To export your private key and certificate for safe-keeping and for enabling development on multiple systems, open up the Keychain Access Application and select the ‘Keys’ category.

Step 2: Control-Click on the private key associated with your iPhone Development Certificate and click ‘Export Items’ in the menu. The private key is identified by the iPhone Developer: public certificate that is paired with it.

Step 3: Save your key in the Personal Information Exchange (.p12) file format.

Step 4: You will be prompted to create a password which is used when you attempt to import this key on another computer.

Step 5: You can now transfer this .p12 file between systems. Double-click on the .p12 to install it on a system. You will be prompted for the password you entered in Step 4.

Categories: iOS

## Including eps graphics in pdfLaTeX

Traditionally, LaTeX users generate postscript output using dvips. An alternative is to use pdfTeX to generate PDF files directly. The PDF format offers a number of advantages over postscript:

• Smaller uncompressed file sizes.
• Much more efficient bitmap inclusion.
• Availability of hyperlinks.
• Better accessibility for inexperienced users.
• Adobe’s Acrobat reader offers facilities for electronic presentations

The postscript generated by dvips can be converted to pdf format with the Adobe software or ghostscript, but there are a number of disadvantages in comparison to using pdfTeX. In particular, the files are usually larger, and ghostscript prior to v6.0 converts the type-1 scalable fonts into type-3 bitmaps, resulting in poor appearance when viewing. The type-3 bitmaps will also occur if the dvips isn’t configured to use type-1.

The main limitation of pdfTeX is that postscript figures cannot yet be directly imported into documents. Instead, inclusions must be bitmaps (PNG or JPG), a simple format of PDF, or MetaPost output. Some EPS graphics may be converted to PDF and included, but I have had limited success with this approach in the pase. However, I have found that conversion through MetaPost is quite robust for vector graphics. For bitmaps you will want to instead convert to PNG for line-art or JPG for photos.

### via pdf

In more recent times, the later versions of epstopdf by Sebastian Rahtz et al. appear to quite successfully perform the translation to pdf directly. This means that the pdf generation process is quite easy:

• Convert the .eps files to .pdf using epstopdf
• Conditionally include the graphics package, as shown below.
• Include the images in the LaTeX file, perhaps following the example below
• The same file can then be used to generate dvi output with LaTeX, or pdf output with pdfTeX.

### via mps

I would consider this section now obsolete, and graphics would now be generally be included with pdf as described above. Hovewer, to instead perform the conversion via MetaPost, you will need both pstoedit and metapost. I suggest pstoedit v3.14 or later as it incorporates changes and bug fixes I made. Metapost is found in most TeX distributions. To generate a .mps file from a .eps file, use the following commands:

pstoedit -f mpost -fontmap /usr/local/lib/pstoedit/fontmap.mpost
file.eps file.mp

mpost file.mp
mv file.1 file.mps


You will need to alter the path to the fontmap.mpost file to suit you installation. The last line is necessary because metapost gives the output file the extension of “.1”, while it is more convenient to import it into pdfTeX with an extension of “.mps”.

With a little bit of trickery, it is possible to make metapost typeset any mathematics during the conversion. This means that it is possible to include LaTeX equations in graphic editor that does not natively support it (such as Sketch).

### The LaTeX File

To import graphics into pdfTeX, the easiest way is to simply use the graphics (or graphicx) package, and no option should now be required. So simply use this at the top:

\usepackage{graphics}


A figure may then be included by a command like:

\includegraphics{file}


If the extension is not specified, LaTeX will find the .eps file, and pdfTeX will find the .mps or .pdf file.

The following is an example of inserting a figure called FigureExample.eps, FigureExample.pdf or FigureExample.mps. If you leave the extension off, usually the best one is chosen automatically.

\begin{figure}[htb!]
\centering%
\includegraphics{FigureExample}
\caption{An Example Figure}
\label{fig:FigureExample}
\end{figure}


In order to keep files small, I recommend using the Times or Helvetica fonts, as these are built-in fonts on pdf readers, and don’t need to be included in the file. For example, use the times package (\usepackagetimes in the preamble).

Categories: LaTeX

## LaTeX Error: Cannot determine size of graphic (no BoundingBox)

### What’s a BoundingBox?

A BoundingBox is a entry that is located in PostScript files that tells the reader the scale limits of the file. LaTeX uses this entry to determine how to place the image in the document.

### How to fix the LaTeX problem

It is quite easy to fix this problem. The free software package ImageMagick is used in this case to convert the images from one form to another. ImageMagick is able to convert many image formats to many other types. To do the conversion just enter this into your console:

root@toor ~ # convert image.jpg image.eps

You can find a portable Win32 release ImageMagick-X.X.X-Q16-windows.zip here.

For converting jpgs to PostScript files there is also a free utility named jpeg2ps. You can download it from here.

Categories: LaTeX