Skip to main content

Posts

Showing posts with the label objective-c

Why tack a protocol of NSObject to a protocol implementation

I have been seeing some code around that resembles the following: @protocol MyProtocol <NSObject> // write some methods. @end Is there any particular reason why MyProtocol conforms to the NSObject protocol? Isn't that rather redundant in that if you do something such as: id <MyProtocol> foo; // foo here conforms to NSObject AND MyProtocol? Just curious what the logic is. Source: Tips4all

In objective-C (iphone), how do I manage the memory of "@protocol" references?

I thought I had a pretty good handle on memory management for objective-c, but I can't figure out the following situation: @protocol MyProtocol @end @interface MyObject : NSObject { id<MyProtocol> reference; } @property (nonatomic, retain) id<MyProtocol> reference; @end @implementation MyObject @synthesize reference; -(void) dealloc { [reference release]; [super dealloc]; } ... @end This gives me a " warning: '-release' not found in protocol(s) ". Can I safely ignore this error? Or am I doing something horribly wrong? Source: Tips4all

Try-catch exception handling practice for iPhone/Objective-C

Apologies if this question has already been answered somewhere else, but I could not find any decisive answer when searching on it: I'm wondering when try-catch blocks are to be used in objective-c iPhone applications. Apple's "Introduction to the Objective-C Programming Language" state that exceptions are resource intensive and that one should "not use exceptions for general flow-control, or simply to signify errors." From reading a few related questions here I also gather that people are not often using this method in practice. So I guess the question is: what are the situations when it's appropriate to use try-catch blocks when developing for iPhone/Objective-C and when should they absolutely NOT be used? For example, I could use them to catch beyond bounds and other exceptions when working with objects in arrays. I have a method which performs are few tasks with objects that are passed on in a number of arrays. The method returns nil if an er

Objective C parse hex string to integer

I would like to know how to parse a hex string, representing a number, in objective c. I am willing to use both an objective, or a C based method, either is fine. example: #01FFFFAB should parse into the integer: 33554347 Any help would be appreciated!

Convert String to Int Objective-C?

Really basic iPhone Objective-C question. I'm trying to extract a string (which is really a int) from an array and then use it as an int in a function. I'm trying to convert it to a int using intValue. Here's the code I've been trying. NSArray *_returnedArguments = [serverOutput componentsSeparatedByString:@":"]; [_appDelegate loggedIn:usernameField.text:passwordField.text:(int)[[_returnedArguments objectAtIndex:2] intValue]]; I get the error passing argument 3 of 'loggedIn:::' makes pointer from integer without a cast Thanks for the help, Christian Stewart

How to embed iPhone-Wax into app

I have just learnt about iPhone-Wax (thanks to SO). Now the documentation is rather sparse for what I am trying to do. I want to embed it into an Objective-C app. I don't want it to be the main app. Has anyone done it and how can I achieve it? I would like to use it in the same way LuaObjectiveCBridge is used.

Asihttprequest 61 errors [closed]

it should be a simple problem. im using the ASIhttprequest in many project but sins 1 week each new project i'm trying to add the ASIhttprequest classes i got the following 61 error before using classes just when i'm trying to import them. Build finjan of project finjan with configuration Debug Ld build/Debug-iphonesimulator/finjan.app/finjan normal i386 cd /Users/Apple/Desktop/application/finjan setenv MACOSX_DEPLOYMENT_TARGET 10.5 setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.3.sdk -L/Users/Apple/Desktop/application/finjan/build/Debug-iphonesimulator -F/Users/Apple/Desktop/application/finjan/build/Debug-iphonesimulator -filelist /Users/Apple/Desktop/application/finjan/build/finjan.build/Debug-iphonesimulator/finj

What causes (and how can I fix) this odd Core Location error?

ERROR,Generic,Time,320195751.128,Function,"void CLClientHandleRegistrationTimerExpiry(__CFRunLoopTimer*, void*)",Registration timer expired, but client is still registering! There are only a few mentions of this problem that I was able to dig up in the wider Internet, and nobody has useful info. Here's the context: I have an app that monitors the device's location via CLLocationManager's startUpdatingLocation method. It starts monitoring, runs for a little while, then this message pops up in the debug output. From that point forward, no more location updates are delivered. This error is killing the location functionality of the app, and I'm at a loss as to what may be causing it. It even has an exclamation point at the end, which means it's clearly an exciting error. Update: Though I never found a solution to the problem, or figured out why it happens in the first place, I've also lost the ability to reproduce it. This seems to have h

When does an associated object get released?

I'm attaching object B via associative reference to object A. Object B observes some properties of object A through KVO. The problem is that object B seems to be deallocated after object A, meaning its too late to remove itself as a KVO observer of object A. I know this because I'm getting NSKVODeallocateBreak exceptions, followed by EXEC_BAD_ACCESS crashes in object B's dealloc. Does anyone know why object B is deallocated after object A with OBJC_ASSOCIATION_RETAIN? Do associated objects get released after deallocation? Do they get autoreleased? Does anyone know of a way to alter this behavior? I'm trying to add some things to a class through categories, so I can't override any existing methods (including dealloc), and I don't particularly want to mess with swizzling. I need some way to de-associate and release object B before object A gets deallocated. EDIT - Here is the code I'm trying to get working. If the associated objects were released

Setting an image for a UIButton in code

How do you set the image for a UIButton in code? I have this: UIButton *btnTwo = [UIButton buttonWithType:UIButtonTypeRoundedRect]; btnTwo.frame = CGRectMake(40, 140, 240, 30); [btnTwo setTitle:@"vc2:v1" forState:UIControlStateNormal]; [btnTwo addTarget:self action:@selector(goToOne) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btnTwo]; but don't see what will set the image for it. Any help appreciated, Thanks // :)

How to set the Navigation Bar Color of the Tab Bar Configure Menu

As you can see the view I need to change is the provided view to customize the tabbar order. I want to change the color of the navigation bar (displaying "Konfigurieren" which means "Configure"), I already found out how to change the color of the "More"-Navigation Controller, but not this one. Can anybody help me with that?

What is the state of non-Objective-C programming for iPhone?

After spending three weeks learning Objective-C and Cocoa programming for my work, I've been tasked with researching alternatives to it for iPhone development. I know of two existing alternatives, and one future possibility. C# MonoTouch is a C#.NET implementation with bindings for iPhone specific functionality such as touch screen and accelerometer. It integrates with Xcode and Interface Builder and also allows for custom Objective-C bindings to be made. Java alcheMo-for-iPhone generates C++ code to be compiled for iPhone from J2ME source. It also provides touch screen and accelerometer bindings. Flash / ActionScript 3 Adobe has announced that Flash Professional CS5 will allow Flash applications to be deployed for iPhone. No details have been given yet. I'd like to know if anyone has experience with any of these. Our company is looking into re-using code using these solutions if possible, rather than re-writing the same functionality in Objec

Prefixing property names with an underscore in Objective C

I've always avoided underscores in my variable names, perhaps because its just not what was done back in my learning Java in college days. So when I define a property in Objective C this is what I naturally do. //in the header @interface Whatever { NSString *myStringPorperty } @property (nonatomic, copy) NSString *myStringProperty; //in the implementation @synthesize myStringProperty; But in almost every example it is done like //in the header @interface Whatever { NSString *_myStringPorperty } @property (nonatomic, copy) NSString *myStringProperty; //in the implementation @synthesize myStringProperty = _myStringProperty; Should I get over my aversion to the underscore because that is the one way it should be done, is there a good reason for this style being the preferred one?

Great UIKit/Objective-C code snippets

New to Objective-C iPhone/iPod touch/iPad development, but I'm starting to discover lots of power in one-liners of code such as this: [UIApplication sharedApplication].applicationIconBadgeNumber = 10; Which will display that distinctive red notification badge on your app iphone with the number 10. Please share you favorite one or two-liners in Objective-C for the iPhone/iPod touch/iPad here. PUBLIC APIs ONLY .