w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Objective C private instance variables error
You're getting an error because ivars needs to be declared in the interface. By the way, you're using a veeeeery old version of xcode (probably too old to submit to the appstore), so you might want to look into getting xcode 4.6. There's also been many updates to the Objective-C language. In modern objective-c, there is no longer a need to manually declare ivars like this. If you REALLY would like to keep ivars out of the header file, you can declare them in an empty category interface (also called a "class extension") like this, in the .m file: @interface YourClass() { ivars here } @end

Categories : Objective C

How/where do I declare instance variables in the interface, implementation, program format for writing objective-c code?
please check this link n develop your program according to this author Take a Look at Your First App all things are describe step by step in this tutorial

Categories : IOS

Use and Access Global/Extern Variables in Objective C
In .h @interface SOViewController : UIViewController{ NSString * variable; } in .m you can set it wherever. For example, viewDidLoad. You can also declare this in the .m file by putting the declaration @interface SOViewController(){ NSString * variable; } // @property (strong, nonatomic) NSString * myString; might be appropriate here instead @end Before the @implementation. Ideally, since this is object-oriented programming, though, best practice would be to make the string a property of the class. If you are really set on the extern keyword here is a stackoverflow post on how to use it Objective C - How to use extern variables? EDIT The question came down to how to pass variables around. You can look at this article ios5 how to pass prepareForSegue: an object to s

Categories : Objective C

Callback method cannot access member variables or instance
You need to pass a pointer to method, but the uvarupdate is pointer to function, these are different types. Pointer to a method contains implicit pointer to this of an instance, it doesn't fit into function-pointer. You need to pass this in some another way. If you do not change signature of the callback, you have to calculate an instance (this) somehow. If it can be determined from name parameter, well, it's easy. Another way is to create a trampoline for each instance you have. If there are only few instances, you can write a separate trampoline function for each instance. Creating trampolines dynamically (in run-time) is tricky and non-portable: in fact, you need to write some machine instructions into RAM so that they call your method with the correct this parameter. But that's also

Categories : C++

Ruby on Rails rendering access to instance variables
In fact you don't access your controller's instance variables present in the controller actions directly, what happens is that rails clones them and passes them to the view. You then can access their values through these clones. You can only access these cloned variables in the correspondent view of your controller action during the request. However, your application has a session for each user in which you can store small amounts of data that will be persisted between requests.

Categories : Ruby On Rails

Is it possible to get an access to variables captured in a closure associated with a function instance in JavaScript
I'm not sure that it's exactly what you want but the next code works fine. function getFunction(x) { var closureMember = x; return function() { return closureMember * 2; }; } function changeClosure(x, closure){ var closureMember = x; return eval("(" + closure.toString() + ")"); } var f = getFunction(5); var g = changeClosure(42, f); g();

Categories : Javascript

Controlling number of AppWidget instance
there are multiple ways to count the app widgets that i can think of: send an intent to all of your app widgets to see that they still exist, and count them, and only in the end you would know how many there are. however, i'm not sure how you would know when to stop counting. not sure if it works but maybe you could use:     final ComponentName cn=new ComponentName(context,YourAppWidgetProviderClass.class); int[] appWidgetsIds=appWidgetManager.getAppWidgetIds(cn); and check the size of the result. update the counter based on receving the ACTION_APPWIDGET_DELETED (or ACTION_APPWIDGET_DISABLED) and ACTION_APPWIDGET_BIND (or ACTION_APPWIDGET_ENABLED) actions in the intents on the onReceive() method of your AppWidgetProvider class. anyway, if there are too many (4 or more in your

Categories : Android

Controlling activity instance visibility through a service?
I think you're misunderstanding how services and activities relate. A service runs in the background, doing it's thing. It has no UI and no way for the user to interact with it. The activity can send the service messages and query its state but the service has no way to push information to an activity. If you want the service to notify the user of something you can post a notification. Then have that notification launch your activity which will then connect to the service. There is no way to force open an activity from a service because there is no way to know if your user is even looking at their device at that time.

Categories : Java

controlling the value (TRUE or FALSE) of dummy variables in interaction terms when using lm()
R isn't flipping the sign on the dummy variable as such. When you fit ~ Girth + cGirth:dHeight, the cGirth variable is confounded with the intercept term. You can see what's going on by removing the intercept: > lm(Volume ~ -1 + Girth + cGirth:dHeight, data = trees) Call: lm(formula = Volume ~ -1 + Girth + cGirth:dHeight, data = trees) Coefficients: Girth cGirth:dHeightFALSE cGirth:dHeightTRUE 2.199 2.053 3.339

Categories : R

Controlling access to the graphics card in X.Org
If your games start slow, it's time to optimize that. If a game is inactive and not using GPU resources the driver will eventually swap all OpenGL resources out of GPU memory, so when the game resumes it will experience some noticable delay, when the OpenGL driver is swapping resources back into GPU meory. Just unmapping a window is not enough, you also have to stop the main game loop, so that they don't consume CPU memory. How can I disallow a Linux X11 application access to the graphics card, such that their draw calls to the graphics card are simply ignored. With current generation X11 and drivers: Switch to another VT than the X11 server it runs on. You can start any number of X11 servers you like, but only one can be active on a display VT at any given time. Note that given t

Categories : Linux

Controlling access to static content using node.js
Use an S3 signed URL. A signed URL is a temporary URL for private files that you can send to a single user that references an S3 object. You can also put an expiration time on a signed URL so it doesn't stick around forever. So the flow would look like this: Handle incoming request look up authentication in database make API call to S3 to generate signed URL redirect user to S3 signed URL Here's a related blog post: Amazon S3 Signed URLs with NodeJS.

Categories : Node Js

Controlling Access to Official Repository in BitBucket
Did you try the settings in https://bitbucket.org/{user}/{repo}/admin/access? I'm pretty sure if you set the user to read they can fork and create pull requests and then your seniors with the write permission could do the merging.

Categories : GIT

Instance methods and thread-safety of instance variables
There are many situations in which an instance may be accessible from multiple classes. For example, if your instance is a static variable in another class, then all threads would share that instance, and you can get into big trouble that way. That's just the first way that pops into my mind...

Categories : Java

Changing object variables in an array of instance variables in Ruby
class Cell attr_accessor :values @arrs = [] #Creates a "class instance variable" class <<self #Creates an accessor for the "class instance variable" attr_reader :arrs end def initialize(values) @values = values self.class.arrs << @values #Add the @values array to the "class instance variable" end end test_array = [1, 2, 3] @cells = test_array.map do |num| #Create the cells Cell.new(test_array.dup) end p @cells --output:-- [#<Cell:0x0000010085ffd8 @values=[1, 2, 3]>, #<Cell:0x0000010085ff88 @values=[1, 2, 3]>, #<Cell:0x0000010085ff60 @values=[1, 2, 3]>] @cells.each_with_index do |cell, i| #Change the last value of each cell's @values array cell.values[-1] = i end p Cell.arrs #Show all the @values arrays of

Categories : Ruby

How to convert class variables into instance variables in Python?
Can only provide you some hints as you are trying to achieve something complex: Try creating your own Options class - _meta is actually an instance of django.db.models.options.Options, some things in _meta just seem to behave like lists etc, but you should look into subclassing Django's class and overriding the stuff that's necessary for you. Guess you are on the right way with working with Django's model meta class, but you should also look what magic is built into the field classes, the field's contribute_to_class is something quite essential... Also try to use Django's Field class as a base class, as there might be code checking if a field is really something like that... Well that's no real answer, just trying to provide a few hints!

Categories : Python

Can a child instance access dynamic parent instance attributes and attribute values?
You're misusing inheritance. Rule doesn't need to inherit from Map to access a Map's attributes, and attaching a Rule to a Map won't make it see the Map's attribute values as its own. Inheriting from Map means a Rule is a Map, not that it's linked to or managed by a Map. If you want a Rule to know about its Map, have it record which Map it's associated with: class Rule(object): def __init__(self, number, map): super(Rule, self).__init__() self.number = number self.map = map def __str__(self): # __str__, not __repr__, because __repr__ should be unambiguous, # have a clear beginning and ending, and obviously indicate the type. return "Map {} rule number {}".format(self.map.mapName, self.number) Rule(1, map) # makes a rule associated

Categories : Python

python: class variables and instance variables
This is all assuming your init is meant to be: def __init__(self,i): Other wise it doesn't work. In the third case, abc.i the class hasn't been initialized so i acts as a static variable for which you set the value at 10 in the class definition. In the first two instances, when you called init you created an instance of abc with a specific i value. When you ask for the i value of each of those instances you get the correct number.

Categories : Python

Class variables, instance variables and inheritance
I'm not sure what you're confused about. C3 defines an __init__ method that increases the value of self.w. So, both instances will get instance variables with a value of 4, whereas the class object itself has a class variable with the value of 3.

Categories : Python

class variables v/s instance variables in python
When you assign to a1.cl_var you rebind cl_var associated with a1. This does not affect a2.cl_var. >>> id(a1.cl_var), id(a2.cl_var) (11395416, 11395416) As you can see, a1.cl_var and a2.cl_var are the same object. However, when you assign to a1.cl_var, they become different objects: >>> a1.cl_var=23 >>> id(a1.cl_var), id(a2.cl_var) (11395200, 11395416) This does not happen in the a/b example because there you modify foo via a reference. You don't rebind (i.e. assign to) it.

Categories : Python

Objective-C: Instance variable used while 'self' not set... but it is
Do not use -> to access instance variables, especially when the ivar is from some other object. Do this: _buffer = [[attr string] mutableCopy]; Same goes for that nasty attr->_attributes. Apparently, ZAttributedStringexposesattributes` as a property in the private header. That compiler warning does seem, at the very most optimistic, entirely misleading and, likely, quite wrong in description. Filing a bug to have that clarified would be useful. Note that @maddy's claim that using -> to access the instance variables directly in the attr string passed as it acts like a copy constructor is incorrect. The incoming attr may be a ZAttributedString instance or an instance of a subclass or, really, an instance of any class that implements the same interface as ZAttributedStr

Categories : Objective C

Objective C: instance variable as reference
If you do not copy objects explicitly the are passed by reference in Objective-C: void addWorld(NSMutableString *stringReference) { [stringReference appendString:@"world!"]; } passed by reference: NSMutableString *greeting = [NSMutableString stringWithString:@"Hello, "]; addWorld(greeting); NSLog(@"%@", greeting); See also the answer "How to pass values by reference in objective C".

Categories : IOS

About naming the instance variable in Objective C
Just to avoid confusion (see comments): Using the = _variable part of the @synthesize is not required, nor is the @synthesize itself required any more. This effort is only requied, when you want to link the property to a specific instance variable. With earlier Objective-C versions this part of the statement was required to set the name to something different from the property name, so when you want to call the iVar _variable and the property variable. The default would be variable (unlike your question). Without that = something ivar and property have the same name. BTW, there is nothing wrong with using the same name for both. But having different names, a leading _ would do, makes it more clear to the programmer whether he/she accesses the ivar directly or though the accessor method

Categories : Objective C

Objective C instance methods not found
Please delete your or rename your another DataHandler file and give the reference in your buildPhases (Compile sources) As you can see log is showing no visible interface that means definition of method is not available in your another DataHandler.h, therefore receiver isn't able to get the declaration of your method.

Categories : IOS

Observe changes of instance variable in Objective-c
I've done a similar thing before, with variable cell heights depending on the content from your web-service, and I'd advise that keeping an array of cell heights might not be the best idea. What I did was to create a 'fake' cell in the viewDidLoad: method, that I use just to calculate cell heights. Then I use the 'heightForRowAtIndexPath' method to specify how tall cell should be by populating the 'fake' cell with the data for the index path, then finding out how tall that cell is. For example: @interface MyTableViewController() @property (nonatomic, strong ) MyCustomTableViewCell *cellForTestingHeight; @end @implementation MyTableViewController - (void)viewDidLoad { [super viewDidLoad] self.cellForTestingHeight = [[MyCustomTableViewCell alloc] initWithStyle:UITableVi

Categories : Objective C

Need to declare a public instance variable in Objective C
To make instance variables public, use @public keyword, like this: @interface PatientIDButton : UIButton { // we need 'class' level variables @public NSUInteger patientID; } @end Of course you need to remember all the standard precautions of exposing "raw" variables for public access: you would be better off with properties, because you would retain flexibility of changing their implementation at some later time. Finally, you need to remember that accessing public variables requires a dereference - either with an asterisk or with the -> operator: PatientIDButton *btn = ... btn->patientID = 123; // dot '.' is not going to work here.

Categories : Objective C

Is it possible to define method for a class instance in objective-c
Simple answer: No. There is no simple way to dynamically add a method to one particular instance of a class. If you drop both the requirement to do it dynamically and the to do it for only one instance, then you can use a category - which is a compile-time way of adding methods to an existing class, and hence all instances of that class. Complicated answer: Yes. In Objective-C the runtime provides a set of functions to do just about anything, you can create new classes on the fly, add methods to them, and change the class of an instance dynamically. Using facilities such as these you could achieve the equivalent of your Ruby code. The Objective-C key value observing (KVO) mechanism is built on these features. Using the runtime functions in this way is a non-trivial undertaking, best to

Categories : Objective C

Problems with Variables in Objective-C
You should really define them as a property instead @interface AppDelegate : NSObject <NSApplicationDelegate> @property (nonatomic, weak) IBOutlet NSMenu *statusMenu; @property (nonatomic, strong) NSStatusItem * statusItem; ... @end 'Why?', you may ask. Multiple reasons, but it's mainly because they do work, and because ARC now knows how to manage those variables.

Categories : Objective C

Pointers and Variables in Objective C
In your example testString is a variable of type "pointer to NSString". All Objective C objects are handled through fields and variables of pointer type. When they say "init returns an object", an expanded version of this statement should be "init returns a pointer to an object". However, since all objects are dealt with through pointers, the "pointer to" clarification can be safely dropped.

Categories : Objective C

Objective-C - Returning an NSArray from custom instance method returns nil
try by doing this: NSString *tmp = [NSHomeDirectory() stringByAppendingPathComponent:@"tmp"]; NSArray *listOfFiles = [myFileManipulator listFilesForURL:[NSURL fileURLWithPath:tmp]];

Categories : Objective C

Class global variables in Objective-C
In Objective-C, classes have no static members. The best I can imagine is creating a getter and setter class method with an utterly ugly global variable: static T _member = initialValue; + (T)someStaticMember { return _member; } + (void)setSomeStaticMember:(T)newVal { _member = newVal; } If you only need a getter, i. e. emulation of a read-only member, then move the static variable inside the function, at least you will have one less global that way. BUT: if you only need integer constants, why not use an enum? Or at least some macros?

Categories : Objective C

Protected variables with modern objective-C?
Your best option is to use a category in a second header file, e.g. MyClass_protected.h, and include it in the main class and subclasses, as suggested in the solution you link. It's really quite straightforward, not "overcomplicated" at all, just one additional file. Objective-C has very strong introspection characteristics. No matter how or where you declare a property (or any other function, for that matter), you can access it from anywhere. You will get a compiler warning unless the code you're writing can see the corresponding declaration or implementation (unless you use an introspective method like one of the performSelector... family). The only reasons for the interface are name-safety, type-safety, and preventing compiler warnings. Therefore, you have a few options: The main clas

Categories : Objective C

Objective-C Shared variables between classes
Better to have a delegate method / block which is called on completion, or to post a notification (if multiple instances are interested in the event). This will allow you to break the dependency you currently have by making the actions performed as a result of the completion event anonymous to the WhosWhereConnection class. The simplest change will be to replace the table view parameter with a block. Using a delegate requires the most code. The other answers show the code for the other options. For delegation, we want: A protocol to define method(s) that will be called A property to hold the delegate object reference Usage of the delegate Implementation of the delegate method(s) 1, 2 & 3 are on WhosWhereConnectionDelegate class. 4 is on the table view controller. 1. @protocol

Categories : Objective C

Am I doing this the Objective-C way? (no static class variables)
Yes, this is the Objective-C way (although the example scenario is questionable). When you have a value that is guaranteed to be the same for all instances of a class, but may change depending on subclass, use a class method to return the value. (This is not the only use of class methods.) Here are some examples from Apple's frameworks. There are others. +[UIView layerClass] +[UIView requiresConstraintBasedLayout] +[NSObject classFallbacksForKeyedArchiver] +[NSObject classForKeyedUnarchiver] +[NSObject accessInstanceVariablesDirectly] +[NSValueTransformer allowsReverseTransformation] +[NSValueTransformer transformedValueClass] +[NSCell defaultFocusRingType] +[NSCell defaultMenu] +[NSCell prefersTrackingUntilMouseUp] +[NSDocument autosavesDrafts] +[NSDocument autosavesInPlace]

Categories : Objective C

Showing non Objective-C variables in debug watch
Use p, instead of po. po is for objects, p is for plain C variables. If it complains about not knowing the type, just explicitly cast it.

Categories : IOS

What are the pitfalls and caveats of global variables in Objective-C?
If you frequently access your root view controller via the shared app delegate, then you might was well add a global variable as a shortcut. It's essentially the same thing. It doesn't waste resources or compromise security. That said, I would argue that it encourages bad design. Instead of accessing a global variable, why not pass references only to the controllers that need them? Or perhaps work on decoupling your controllers with NSNotifications, delegates, or block callbacks? It's up to you based on your app's needs. Try to walk the line between over-engineering and a good, decoupled design.

Categories : IOS

Objective-C: Different ways of declaring private variables. Any differences between them?
You can declare a private @interface in the .m file. //DataExtract.m @interface DataExtract () //your variables @end @implementation DataExtract @end For more info you can go here

Categories : Objective C

Can a class instance created by another class instance access the creator's members?
You can do this, and you've almost done it, with one minor problem: class Created(): def __init__(self, creator): self.parameter = self.creator.parameter There is no self.creator. If you never need to access it again after this __init__ call, just use the creator parameter directly: class Created(): def __init__(self, creator): self.parameter = creator.parameter If you need it later, store it as self.creator, and then of course you can access it there: class Created(): def __init__(self, creator): self.creator = creator self.parameter = self.creator.parameter … although you probably don't even need to copy over parameter in that case, because you can always get to it as self.creator.parameter. This is a very common pattern. The only

Categories : Python

How to add constraints to linear programming on variables not from objective function in matlab
The fact that x4 and x5 do not appear explicitly in the objective function does not necessarily mean they do not exist. Think about this objective function min 2*x1 + 3*x2 - 5*x3 + 0*x4 + 0*x5 Now you have a linear program with 5 variables. Bottom line: just add two zeros to your objective function and you are done.

Categories : Matlab

Set value - instance variables
You can access your variable in two ways: Using the setter or getters with self. : self.x = 10; [self setX:10] Both are equivalent, but Apple recommends you to use the setter with self. Or accessing the ivar directly. The ivar name depends on how you shynthesize it. If you use the default synthesize (or you don't synthesize it yourself), is like this: _x = 10; In you example, the second way is accessing the ivar directly, and the first way is using the setter (same as self.x = 10), The first way is recommended (using self or using the setter) because it takes care of memory issues, releases previous values, protect from threads if you want, etc. And it's more comfortable to use self. than calling the setter. Only use the ivar when you are in the init method, for the rest, use th

Categories : Objective C

Basic pointer/reference issue in Objective-C - accessor methods in one instance affect all instances at class level
XYPoint *origin; is a global variable, which means it is shared throughout whole program. You need to declare it as a property, just like you did with x, y, width and height.

Categories : Objective C



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.