Tag: variables

About private instance variables in Objective-C

In xCode 3, I defined private instance variables in a class. When I directly access the private variables in the client codes, why does the compiler just show me a warning, not an error? The code can still run. The warning says this maybe a hard error in the future. What does the “hard error” […]

Global Variables in Objective C

I have a counter which I use to get an object at that counters index and I need to access it in another class. How are static variables declared in Objective C?

How to store molecules in memory?

I want to store molecules in memory. These can be simple molecules: Methane (CH4) C-H bond-length: 108.7 pm H-H angle: 109 degrees But also more complex molecules, like paracetamol (C8H9NO2): How can I store molecules in memory, including all bond-lengths and angles? A good idea to store atom-structs in an array? Or is there a […]

Passing Javascript Variable to Objective-C

I’ve seen how to pass an Objective-C variable to JavaScript right here, passing objective c variable to javascript in ios, but how do I pass a variable from JavaScript to Objective-C when I’m using something like this: [webView stringByEvaluatingJavaScriptFromString:@”var elems = document.body.getElementsByTagName(\”u\”);” “passThisVarToObjC = elems.length;”

iOS retrieving javascript variables from UIWebView

I have an html file that has a <div> and that I am loading into a UIWebView and I need to know how many lines of text are in the div, so I can check that with javascript: <script> function countLines() { var divHeight = document.getElementById(‘myDiv’).offsetHeight; var lineHeight = parseInt(document.getElementById(‘myDiv’).style.lineHeight); var lines = divHeight / […]

Pass variables from Objective-C to javascript function?

I have a simple javascript function that takes two variables. I need to pass two variables that I already have in my Objective-C (iOS) application to this javascript function. My line of code to run the javascript is: [webView stringByEvaluatingJavaScriptFromString:@”onScan()”]; The javascript function just applies the two variables to a HTML form and submits it. […]

Global variables in Objective-C – difference in extern and top of .m file declaration

I know you can define a global variable in Objective-C by using “extern“, but I just realized that the variables I had declared at the top of my .m file before my first method were also accidentally global (and that was causing some problems). I moved them into the @interface part of my header file, […]

In Objective-C, are int variables that haven't been assigned a value nil?

If I have this in my .h file: int index; And then in the .m file I have: if (index == nil) and I haven’t assigned a value to index, will that come up true? EDIT I guess nil is only used for objects. So what is the state of an int that hasn’t been […]

iPhone SDK Nonatomic and Atomic

Really quick and simple question: In Objective-C what is the difference between nonatomic and atomic? like when declaring properties like “@property (nonatomic, retain) id object”?

Declaring instance variables in iOS – Objective-C

Ok, I’ve read a lot around these days about this topic and I alwyas get confused because the answers is different every search I make. I need to know the best way to declare instance variables in iOS. So far I know I should only declare them inside .m file and leave .h clean. But […]