Tag: declaration

Declaring variables inside a switch statement

This question already has an answer here: Why can't variables be declared in a switch statement? 23 answers

can variables be set randomly when declaring them again?

In my method, I declare some variables, including int blockCount;. I call this method more than once. Using the Xcode debugger, I found out that after the second time the method was called, the value of blockCount was set to 364265, while it was set to 2, just a few milliseconds earlier. It’s not a […]

Synthesize error “Missing Context for Property Implementation Declaration”

Anyone have any ideas? When I try to synthesize a property I have declared in the .h file its not letting me synthesize it. Any ideas? Thanks!

Private Methods in Objective-C, in Xcode 4.3 I no longer need to declare them in my implementation file ?

I have a lot question marks tolling above my head. What I don’t get is before xcode 4.3 I needed to declare forward declarations (for private methods) in my implementation file. Like in my .m file: // deleting this with xcode 4.3 the below code still does work // in previous versions i had to […]

swift dictionary population issue: type 'AnyObject' does not conform to protocol 'NSCopying'

I am trying to migrate the next code from Objetive-C to Swift: NSArray *voices = [AVSpeechSynthesisVoice speechVoices]; NSArray *languages = [voices valueForKey:@”language”]; NSLocale *currentLocale = [NSLocale autoupdatingCurrentLocale]; NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; for (NSString *code in languages) { dictionary[code] = [currentLocale displayNameForKey:NSLocaleIdentifier value:code]; } And I did the following: var voices:NSArray = AVSpeechSynthesisVoice.speechVoices() var languages:NSArray=voices.valueForKey(“language”) […]

What is the 'open' keyword in Swift?

The ObjectiveC.swift file from the standard library contains the following few lines of code around line 228: extension NSObject : Equatable, Hashable { /// … open var hashValue: Int { return hash } } What does open var mean in this context, or what is the open keyword in general?

What's the _ underscore representative of in Swift References?

In the reference section of Apple’s docs there’s lots of instances of this sort of thing: func runAction(_action: SKAction!) The Objective-C ‘equivalent’ of this is: – (void)runAction:(SKAction *)action It strikes me that it’s probably important that (in the Swift reference) there’s a space after the underscore and “action” is written in italics. But I can’t […]

use of @property and @synthesise?

I was wondering what the point of @property and @synthesise were. At the moment I use the following to declare something: //Class.m #import “Class.h” CCNode *node; @implementation //init, etc.. But I have seen others use: @property (nonatomic, etc..) CCNode* node; @synthesise (nonatomic, etc..) node; //I am not too sure on how this type of declaration […]

Declaring UI Objects in Switch Cases

I’ve read about the scope of switch cases, being jump labels and all, but the suggested solutions here at SO seem to imply that adding curly braces would circumvent the issue. However, this still doesn’t seem to work: switch (objectType) { case label: //label is an integer constant NSLog(@”statement before declaration”); UILabel *control = [[UILabel […]