objective-c

Parsing XML from an HTTPS URL using NSXMLParser?

I'm trying to parse XML directly from an HTTPS URL, as follows: NSString *const URL = @"https://some/HTTPS/url"; NSURL* url = [NSURL URLWithString:URL]; NSXMLParser* parser = [[NSXMLParser alloc] initWithContentsOfURL:url]; [parser setDelegate:self]; [parser parse]; I have the following delegate method for the parser: - (void) parser...

Is there a simple way to emulate Objective-C Categories in C#?

I have a weird design situation that I've never encountered before... If I were using Objective-C, I would solve it with categories, but I have to use C# 2.0. First, some background. I have two abstraction layers in this class library. The bottom layer implements a plug-in architecture for components that scan content (sorry, can't be m...

Regular expressions in an Objective-C Cocoa application.

Initial Googling indicates that there's no built-in way to do regular expressions in an Objective-C Cocoa application. So four questions: Is that really true? Are you kidding me? Ok, then is there a nice open-source library you recommend? What are ways to get close enough without importing a library, perhaps with the NSScanner class? ...

Simple string parsing in Cocoa / Objective-C: parsing a command line into command and arguments.

Here's a piece of code to take a string (either NSString or NSAttributedString) input that represents a command line and parse it into two strings, the command cmd and the arguments args: NSString* cmd = [[input mutableCopy] autorelease]; NSString* args = [[input mutableCopy] autorelease]; NSScanner* scanner = [NSScanner scannerWithStri...

How to disable forward class compiler warning (undocumented class)

I'm currently writing an iPhone application that uses a UITabBarController with more than 5 Tab Bar Items. Thus, a 'more' tab is automatically generated (like in the YouTube Application). I found out that the corresponding view controller class is UIMoreListController, but I don't have any corresponding .h files. So, my code looks like t...

Use of properties in Objective C 2.0 for Primitive types

I'm having trouble understanding when to use properties in Objective C 2.0. It seems you do not need a property for a primitive type such as: int, bool, float. Is this true? I have seen examples showing properties for these types and other leaving them out. For example, in Apple's sample code they have: ... @interface Book : NSObject { ...

How to free a C struct with Objective-C?

Given a struct, e.g. typedef struct { int value; } TestStruct; Why does the following code (in the context of an Objective-C class running on the IPhone) throw a "non-aligned pointer being freed" exception? TestStruct ts = {33}; free(&ts); N.B. My uber goal is to use a C library with many vector-math functions, hence the need to ...

On which kind of memory a C struct is allocated when initialized as a class variable in Objective-C

Consider the following: typedef struct { float m00, m01, m02, m03; float m10, m11, m12, m13; float m20, m21, m22, m23; float m30, m31, m32, m33; } Matrix; @interface TestClass : NSObject { Matrix matrix; } - (TestClass *) init; @end @implementation TestClass - (TestClass *) init { self = [super init]; matrix = (Matri...

HowTo for newbie: Managing currency in iPhone app

I'm building a app that need manage money datatype. I'm new on Obj-c, so I can't see the ligth in the use of NSDecimalNumber. For example, in my unit test I do this: @interface SamplePerson : NSObject { NSString *name; NSDate *birthDate; NSInteger size; NSNumber *phone; NSDecimal balance; BOOL *isOk; } @proper...

Is there something similar to LINQ in Objective-C?

I wonder if it is possible (and how) to provide a class in Objective-C with something like: Person.Select(@"Name").OrderAsc(@"Name").Where(@"Id").EqualTo(1).And(@"Id").NotEqualTo(2).Load<Array> That could be very handy for a project I'm doing. I like this way of coding present in Django & SubSonic. ...

Using pointers in Objective C for NSMutableArray objects

When retrieving objects from an NSMutableArray in cocoa-touch is the below code ok? Should I be allocating([alloc]) new Page objects each time or is just pointing to it alright? Do I need to do anything to the Page *pageObj after, such as set it to nil? const char *sql = "insert into Page(Book_ID, Page_Num, Page_Text) Values(?, ?, ?)"; ...

How do I call a method from an instance of a class?

Hi, I have this: -(NSDictionary *)properties; +(NSDictionary *)ClassProperties; Now, how can I call ClassProperties from sub-classes? -(NSDictionary *)properties { return [? ClassProperties]; } The point is that ClassProperties gets the list of properties in the class, so i can't call the base class definition. ...

What is an "Abort trap" & how do I debug it?

I'm getting this message each time I compile my project: RunIPhoneUnitTest.sh: line 92: 31389 Abort trap "$TARGET_BUILD_DIR/$EXECUTABLE_PATH" -RegisterForSystemEvents I understand is a problem in my code, but then I don't figure how solve or found it. The strange thing, is that I get this with this call: -- This is the ...

Programmatically Update an attribute in Core Data

I've looked through all the class documentation for Core Data and I can't find away to programmatically update values in a core data entity. For example, I have a structure similar to this: id | title ============ 1 | Foo 2 | Bar 3 | FooFoo Say that I want to update Bar to BarBar, I can't find any way to do this in any ...

Is possible send a array in Obj-c for a variable arguments function?

Hi, in python is easy build a dictionary or array and pass it unpacked to a function with variable parameters I have this: - (BOOL) executeUpdate:(NSString*)sql, ... { And the manual way is do this: [db executeUpdate:@"insert into test (a, b, c, d, e) values (?, ?, ?, ?, ?)" , @"hi'", // look! I put in a ', and I'm not escaping i...

"stringWithString" vs "alloc ... initWithString ... autorelease" in Cocoa Objective-C.

I've seen it claimed that the following are "pretty much equivalent": foo([NSString stringWithString:@"blah"]) # version 1 foo([[[NSString alloc] initWithString:@"blah"] autorelease]) # version 2 Are the above in fact literally equivalent or are there any subtle differences? What are reasons to prefer one or th...

Returning a pointer to memory allocated within a function in Cocoa Objective-C.

In C, something like the following would be a disaster (ie, a memory leak) because you're returning a pointer to memory that you will never be able to free: NSString* foo() { return [NSString stringWithFormat:@"%i+%i=%i", 2, 2, 2+2]; } Is that in fact totally fine in Objective-C since the memory that the returned pointer points to w...

iPhone SDK: Set Max Character length TextField

Hi there, anybody know how I can set the maximum amount of characters in a TextField on the iPhone SDK when I load up the UIView ? ...

NSDictionary initWithContentsOfFile: messes up NSDecimalNumbers, why?

In my iPhone app I employ NSDecimalNumber to store some some currency rate values. I pull the data from the web the first time the app is launched and then again when they become obsolete, and I store them in a NSDictionary; then I use writeToFile:atomically:. When the app is launched for the first time, my rate conversion method works ...

What's the difference between Objective-C and Cocoa?

I'm just learning Objective-C/Cocoa programming for the Mac. All of the tutorials, books, blogs, podcasts, etc. I've been using really cover the two together. Is there an easy way to tell which pieces are vanilla Objective-C and which come from Cocoa? ...