objective-c

How to deal with double composition and inheritance?

I found this related question: http://stackoverflow.com/questions/279158/how-do-i-use-composition-with-inheritance I would like to do the same with Objective-C, that is to say that a GenericView knows that its property obj is a GenericObject, and that a SpecializedView knows that the very same obj property is a SpecializedObject. Here ...

Use of retain in initWithCoder?

I am reading up about Encoding and Decoding and I noticed that sometimes people miss the retain off the end, I have also noticed that retain is sometimes used on some varables but not others. Can I ask ... (1) What is the purpose of this retain and why is it sometimes not needed? (2) Does the use of the retain imply that I need to matc...

iPhone: "error: ABPerson.h: No such file or directory"... How to use the ABPerson class?

I'm trying to use the ABPerson object. The documentation tells me to include ABPerson.h. Here is basically my code: #import "ABPerson.h" [...] -(void) updateImageWithContact:(ABPerson)contact; The problem is that I get an error: error: ABPerson.h: No such file or directory I did include Addressbook.framework so I don't know what's...

Calling NSPathControl object in thread crashes

For some reason calling an NSPathControl object in a thread is causing crashes. - (IBAction) action5:(id)sender { [outlet_NSPathControl1 setURL: [NSURL fileURLWithPath: @"/Users/admin/"]]; // Works fine here [self performSelectorInBackground:@selector(background1) withObject:self]; // Jump to the thread } -(void) background1 { NSAut...

Objective-C Protocols within Protocols

I recently began trying my hand at using protocols in my Objective-C development as an (obvious) means of delegating tasks more appropriately among my classes. I completely understand the basic notion of protocols and how they work. However, I came across a roadblock when trying to create a custom protocol that in turn implements another...

NSKeyedArchiver write XML (or other human readable)?

I have been trying to get the NSKeyedArchiver to write out my data in a human readable form (i.e. not as a binary file) I understand that I can use ... setOutputFormat: NSPropertyListXMLFormat_v1_0 But ... I just can't seem to get the syntax right, can anyone point me in the right direction? NSData *artistData; NSLog(@"(*) - Save Al...

In Cocoa, do you have to do anything special to make sure you copy resource forks when copying files?

I had assume I could just do this, but I don't have a way to check that resource forks went along for the ride. NSFileManager *fm = [NSFileManager defaultManager]; [fm copyPath:absSourcePath toPath:absDestinationPath handler:err]; edit: I need to copy in a 10.4-6 compatible manner. (Yes, really 10.4.) ...

Why is my if statement not firing?

I have the following Objective-c Function - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger section = [indexPath section]; NSUInteger row = [indexPath row]; NSString *key = [keys objectAtIndex:section]; NSArray *nameSection = [mysearchdata objectForKey:key]; static...

Check existence of file on disk?

Currently I am loading data from a previous session into my application using the code below. To guard against there being no previous data I am using a temp variable to check the return value before making my assignment. I am just posting here as this feels a bit clunky, is there a way to check a file exists on disk so I can check befor...

is there an objective-c "equivalent" to ruby's send method?

I'm not sure this is possible, but in ruby, you can dynamically call a method using send e.g. if I want to invoke the bar method for the object, foo, I can use foo.send("bar") Is there any way of doing something similar using objective-c? tks! ...

Finding a word's frame (position and size) on the screen using Cocoa or Carbon

Here's a tough one: I need to be able to find a word's position and size (its frame) on the screen (its first occurence is enough, from there I should be able to get the next ones). For example, I would like to be able to detect word positions in (but not limited to) Word, Excel and PowerPoint for Mac, as well as Safari and others. Th...

Is there a better way to serialize plist-y objects in Objective-C?

I like the plist serialization capability for small collections of objects: it is simple, the storage is XML, etc. But I find setting values in dictionaries cumbersome: [myDict setObject:keepThis forKey:@"ivar"]; I'd much prefer to use object derived of classes (or even just structs): myObj.ivar = keepThis ... and then send a messa...

isEqualToString can the items be swapped?

I am just curious if there is a way to swap the two stings in this example? // This works for(eachArtist in artistCollection) { if([objFirName isEqualToString: [eachArtist firName]]) NSLog(@"DELETE ...."); } What I was trying to do was (see below) can this be done or is the above the only way? [eachArtist firName isEqualToString: obj...

Using client side certificates with objective-c under macosx with Cocoa

I am looking for sample code or documentation on how to use client side certificates with SSL under MacOSX. The server I want to connect to, does speak a custom ascii protocol but allows only ssl connections with registered client certificates. I already wrote a client in Java that works. In Java I initialized a SSLContext with a Ke...

Warning Pass-by-Value?

I am fairly new to Objective-C and whilst running the Clang static analyser this section of code gave me the following error warning: Pass-by-value argument in message expression is undefined [artistCollection removeObject:removeArtist]; Can anyone cast any light on this warning for me? case 6: NSLog(@"(*) - First Name:"); sc...

Change UIView Dynamically

Working on cs193p (stanford online videos of iphone programming), I am working on Presence1 exercise I am trying to change a UIView which is a subview of another view dynamically. For those of you who are not aware of the assignment posted on the course, Basically the architecture of the app is as follows: Nav Controller -> (Root) View ...

How do I detect if device doesn't have a sim card using iphone sdk?

i am using these methods to get my location.all works fine in simulator.but on real device it runs very fast.how do i slow this down,also how do i show error only once if the device have not sim inserted and also for user denied to use current location. here are the methods-- -(void)GetCurrentLocation { // Create the location manager i...

how to add hours in a nsdate?

i have a date converted to double value and saved in database.now i want to compare if cureentdate > myDataBaseDate+8 hours. means i want to get 8 hours more added in my database date. i'm converting date into double values.so how do i get 8 hours later time from my database saved date. how do i compare if(currentDateTime>DateFromdatabas...

Push different views from a top-level table view in iPhone SDK

I have a grouped tableview that then tries to push a new view depending on which cell is selected. The issue is, that cells drill-down to views that are not necessarily tables - thus using coding examples from the reference books available is not that helpful - the views I'm trying to push are webview, tableview, textview etc. I have ob...

Generate PDF from html file on iPhone

In my iPhone application I'm generating an HTML file. I would like to convert that HTML file to a PDF file programatically. The PDF will then be attached to an email. Does anyone know (have an example) how to convert the HTML file to a PDF? ...