Search Results

Search found 6745 results on 270 pages for 'objective c 2 0'.

Page 32/270 | < Previous Page | 28 29 30 31 32 33 34 35 36 37 38 39  | Next Page >

  • Implementing the ‘defer’ statement from Go in Objective-C?

    - by zoul
    Hello! Today I read about the defer statement in the Go language: A defer statement pushes a function call onto a list. The list of saved calls is executed after the surrounding function returns. Defer is commonly used to simplify functions that perform various clean-up actions. I thought it would be fun to implement something like this in Objective-C. Do you have some idea how to do it? I thought about dispatch finalizers, autoreleased objects and C++ destructors. Autoreleased objects: @interface Defer : NSObject {} + (id) withCode: (dispatch_block_t) block; @end @implementation Defer - (void) dealloc { block(); [super dealloc]; } @end #define defer(__x) [Defer withCode:^{__x}] - (void) function { defer(NSLog(@"Done")); … } Autoreleased objects seem like the only solution that would last at least to the end of the function, as the other solutions would trigger when the current scope ends. On the other hand they could stay in the memory much longer, which would be asking for trouble. Dispatch finalizers were my first thought, because blocks live on the stack and therefore I could easily make something execute when the stack unrolls. But after a peek in the documentation it doesn’t look like I can attach a simple “destructor” function to a block, can I? C++ destructors are about the same thing, I would create a stack-based object with a block to be executed when the destructor runs. This would have the ugly disadvantage of turning the plain .m files into Objective-C++? I don’t really think about using this stuff in production, I’m just interested in various solutions. Can you come up with something working, without obvious disadvantages? Both scope-based and function-based solutions would be interesting.

    Read the article

  • Are there any libraries similar to Three20? [closed]

    - by GoldFire
    Are there any libraries similar to Three20? Three20 does not work for me on iOS 5; it gives me warnings. Three20 provides powerful view controllers such as the Launcher, the popular Photo Browser, and internet-aware tables. The library is modular, meaning you choose which elements of the library to include in your app. This modular design allows Three20 to be one of the only Objective-C frameworks that encourages what are called 'extensions' from the community.

    Read the article

  • Which programming language to get into?

    - by user602479
    I'm ending my third term in a few weeks so I have some spare time coming up. I'd like to spend it seriously digging into programming. My problem: I'm not sure which language to begin with. Just to be clear, I don't want to start a language-y-compared-to-language-z discussion. There are a some other issues that play a major role. In my 5th term I'm going to be participating in a major practical course which will include either Java or C programming. It will take a lot of time and energy, as I found out while talking to a few students who passed the final exams (only 15% pass on their first try). Which practical course I will take is randomly decided. My skills so far are the absolute basics of Java and C programming. I know the different data types and how to handle them, objects, pointers, thread programming, etc. All of that is on a very low level, though. My question now is, what language should I start seriously practicing? Java: I did my first GUIs with this language. I'm familiar with Eclipse but I need a project to work on (which I don't have) to really keep me pushing. Besides that, I don't think it would help me if I have to do C in a year. C: As with Java, I can't think of a personal project to keep me working and keep me interested in programming. If I get assigned to Java in a year, this wouldn't give me any advantages either, would it? (No objects, etc.) Objective-C: I recently came up with this idea. I have a Mac; I'm not really familiar with Xcode but I have one or two personal projects I'd like to work on. Further, I would be working with objects (as in Java) and C language constructs which would both be great for this practical course in a year. What do you think I should begin with? Should I just stick to Java and hope for the best, force myself through C or start (nearly) completely from the beginning with Objective C? Maybe you folks could give me some good advice that would stop me from switching from one language to the next?

    Read the article

  • How do I use sqlite3 PRAGMA user_version in Objective-c?

    - by mobibob
    I am trying to check the user_version of the sqlite DB. I have an admin tool to bump the version, but I don't understand the syntax of the pragma statement. I am expecting to test the value in an if-statement. Can someone provide a code sample? When I embed the pragma statement in my objective-c code, the compiler throws an error.

    Read the article

  • In Objective C, what's the best way to extract multiple substrings of text around multiple patterns?

    - by Matt
    For one NSString, I have N pattern strings. I'd like to extract substrings "around" the pattern matches. So, if i have "the quick brown fox jumped over the lazy dog" and my patterns are "brown" and "lazy" i would like to get "quick brown fox" and "the lazy dog." However, the substrings don't necessarily need to be delimited by whitespace. I have a hunch that there's a very easy solution to this, but I admit a disturbing lack of knowledge of Objective C string functions.

    Read the article

  • What's the performance penalty of using isKindOfClass in Objective C?

    - by durcicko
    I'm considering introducing: if ([myInstance isKindOfClass:[SomeClass class]]) { do something...} into a piece of code that gets called pretty often. Will I introduce a significant performance penalty? In Objective C, is there a quicker way of assessing whether a given object instance is of certain class type? For example, is the following quicker? (I realize the test is somewhat different) if (myInstance.class == [SomeClass class]) { do something else...}

    Read the article

  • How do I declare an array as a constant in Objective-c?

    - by Andrew
    The following code is giving me errors: // constants.h extern NSArray const *testArray; // constants.m NSArray const *testArray = [NSArray arrayWithObjects: @"foo", @"bar"]; The error I get is initializer element is not constant Or if I take away the pointer indicator (*) I get: statically allocated instance of Objective-C class 'NSArray'

    Read the article

  • Change window title to the one in text box in Objective-C?

    - by Nick Brooks
    I'm just getting started with Objective-C and I'm writing a simple application. I made two outlets : wnd - main window display - the text box Then I've tried using this code: [wnd setTitle:[display value]]; Unfortuanately it didn't work ... The debugger said : 2010-05-22 XX:XX:08.577 HelloWorld[2536:a0f] -[NSTextField value]: unrecognized selector sent to instance 0x102e032a0 Does anyone know how to get it to work?

    Read the article

  • Setting default values for inherited property without using accessor in Objective-C?

    - by Ben Stock
    I always see people debating whether or not to use a property's setter in the -init method. I don't know enough about the Objective-C language yet to have an opinion one way or the other. With that said, lately I've been sticking to ivars exclusively. It seems cleaner in a way. I don't know. I digress. Anyway, here's my problem … Say we have a class called Dude with an interface that looks like this: @interface Dude : NSObject { @private NSUInteger _numberOfGirlfriends; } @property (nonatomic, assign) NSUInteger numberOfGirlfriends; @end And an implementation that looks like this: @implementation Dude - (instancetype)init { self = [super init]; if (self) { _numberOfGirlfriends = 0; } } @end Now let's say I want to extend Dude. My subclass will be called Playa. And since a playa should have mad girlfriends, when Playa gets initialized, I don't want him to start with 0; I want him to have 10. Here's Playa.m: @implementation Playa - (instancetype)init { self = [super init]; if (self) { // Attempting to set the ivar directly will result in the compiler saying, // "Instance variable `_numberOfGirlfriends` is private." // _numberOfGirlfriends = 10; <- Can't do this. // Thus, the only way to set it is with the mutator: self.numberOfGirlfriends = 10; // Or: [self setNumberOfGirlfriends:10]; } } @end So what's a Objective-C newcomer to do? Well, I mean, there's only one thing I can do, and that's set the property. Unless there's something I'm missing. Any ideas, suggestions, tips, or tricks? Sidenote: The other thing that bugs me about setting the ivar directly — and what a lot of ivar-proponents say is a "plus" — is that there are no KVC notifications. A lot of times, I want the KVC magic to happen. 50% of my setters end in [self setNeedsDisplay:YES], so without the notification, my UI doesn't update unless I remember to manually add -setNeedsDisplay. That's a bad example, but the point stands. I utilize KVC all over the place, so without notifications, things can act wonky. Anyway, any info is much appreciated. Thanks!

    Read the article

  • Does iPhone SDK Objective C support functions inside of functions?

    - by Moshe
    I know that javascript, for example supports functions inside of functions, like so: function doSomething(){ function doAnothingThing(){ //this function is redefined every time doSomething() is called and only exists inside doSomething() } //you can also stick it inside of conditions if(yes){ function doSomethingElse(){ //this function only exists if yes is true } } } Does objective-c support this? Theoretical example: -(void) doSomething:(id) sender{ -(void) respondToEvent: (id) sender{ //theoretically? ... please? } } BONUS: What is the proper term for a "local" function?

    Read the article

  • Is developing iPhone apps in any language other than Objective-C ever a truly viable solution?

    - by David Foster
    I hear all this stuff about crazy ways to build iPhone apps using Ruby or C# under .NET or the like. Even stuff about developing apps on Windows using Java, or auto-generated apps using Flash CS5 or something. Now, I've never really spent any time at all investigating these claims—I just brushed them off as clumsy or cumbersome or down-right claptrap—but I'm a proud Objective-C programmer who's perhaps a little worried as to whether there's any truth in all of this?

    Read the article

< Previous Page | 28 29 30 31 32 33 34 35 36 37 38 39  | Next Page >