Search Results

Search found 24043 results on 962 pages for 'private methods'.

Page 59/962 | < Previous Page | 55 56 57 58 59 60 61 62 63 64 65 66  | Next Page >

  • How are declared private ivars different from synthesized ivars?

    - by lemnar
    I know that the modern Objective-C runtime can synthesize ivars. I thought that synthesized ivars behaved exactly like declared ivars that are marked @private, but they don't. As a result, come code compiles only under the modern runtime that I expected would work on either. For example, a superclass: @interface A : NSObject { #if !__OBJC2__ @private NSString *_c; #endif } @property (nonatomic, copy) NSString *d; @end @implementation A @synthesize d=_c; - (void)dealloc { [_c release]; [super dealloc]; } @end and a subclass: @interface B : A { #if !__OBJC2__ @private NSString *_c; #endif } @property (nonatomic, copy) NSString *e; @end @implementation B @synthesize e=_c; - (void)dealloc { [_c release]; [super dealloc]; } @end A subclass can't have a declared ivar with the same name as one of its superclass's declared ivars, even if the superclass's ivar is private. This seems to me like a violation of the meaning of @private, since the subclass is affected by the superclass's choice of something private. What I'm more concerned about, however, is how should I think about synthesized ivars. I thought they acted like declared private ivars, but without the fragile base class problem. Maybe that's right, and I just don't understand the fragile base class problem. Why does the above code compile only in the modern runtime? Does the fragile base class problem exist when all superclass instance variables are private?

    Read the article

  • Problem with debug watch in Visual Studio with yield return enumerator methods

    - by Stuart
    I have a method which returns an IEnumerable<> which it builds up using the yield return syntax: public IEnumerable<ValidationError> Validate(User user) { if (String.IsNullOrEmpty(user.Name)) { yield return new ValidationError("Name", ValidationErrorType.Required); } [...] yield break; } If I put a breakpoint in the method, I can step over each line, but if I try to use the Watch or Immediate windows to view the value of a variable I get this error: Cannot access a non-static member of outer type '[class name].Validate' via nested type '[class name]' Does anyone know why this is and how I can get around it?

    Read the article

  • Why can't I *override* and *new* a Property (C#) at the same time?

    - by Tim Lovell-Smith
    According to this question it seems like you can do this for Methods. What I want to know is why it doesn't work when I try it with properties. public class Foo { public virtual object Value { get; set; } } public class Foo<T> : Foo { public override object Value { get { return base.Value; } set { base.Value = (T)value; //inject type-checking on sets } } public new T Value { get { return (T)base.Value; } set { base.Value = value; } } } Error message from C# 4.0 RC1 Error 1 The type 'ClassLibrary1.Foo' already contains a definition for 'Value' ClassLibrary1\Class1.cs 31 22 ClassLibrary1

    Read the article

  • C# delegate or Func for 'all methods'?

    - by Michel
    Hi, i've read something about Func's and delegates and that they can help you to pass a method as a parameter. Now i have a cachingservice, and it has this declaration: public static void AddToCache<T>(T model, double millisecs, string cacheId) where T : class public static T GetFromCache<T>(string cacheId) where T : class So in a place where i want to cache some data, i check if it exists in the cache (with GetFromCache) and if not, get the data from somewhere, and the add it to the cache (with AddToCache) Now i want to extend the AddToCache method with a parameter, which is the class+method to call to get the data Then the declaration would be like this public static void AddToCache<T>(T model, double millisecs, string cacheId, Func/Delegate methode) where T : class Then this method could check wether the cache has data or not, and if not, get the data itself via the method it got provided. Then in the calling code i could say: AddToCache<Person>(p, 10000, "Person", new PersonService().GetPersonById(1)); AddToCache<Advert>(a, 100000, "Advert", new AdvertService().GetAdverts(3)); What i want to achieve is that the 'if cache is empty get data and add to cache' logic is placed on only one place. I hope this makes sense :) Oh, by the way, the question is: is this possible?

    Read the article

  • NSAutoreleasePool carrying across methods?

    - by Tim
    I'm building an iPhone application where I detach some threads to do long-running work in the background so as not to hang the UI. I understand that threads need NSAutoreleasePool instances for memory management. What I'm not sure about is if the threaded method calls another method - does that method also need an NSAutoreleasePool? Example code: - (void)primaryMethod { [self performSelectorInBackground:@selector(threadedMethod) withObject:nil]; } - (void)threadedMethod { NSAutoreleasePool *aPool = [[NSAutoreleasePool alloc] init]; // Some code here [self anotherMethod]; // Maybe more code here [aPool drain]; } - (void)anotherMethod { // More code here } The reason I ask is I'm receiving errors that objects are being autoreleased with no pool in place, and are "just leaking." I've seen other questions where people didn't have autorelease pools in place at all, and I understand why an autorelease pool is needed. I'm specifically interested in finding out whether an autorelease pool created in (in this example) threadedMethod applies to objects created in anotherMethod.

    Read the article

  • Rails - Accessing model class methods from within ActiveRecord model

    - by aaronrussell
    I have a simple standalone model that doesn't inherit from ActiveRecord or anything else, called SmsSender. As the name suggests, it delivers text messages to an SMS gateway. I also have an ActiveRecord model called SmsMessage which has an instance method called deliver: def deliver SmsSender.deliver_message(self) self.update_attributes :status => "Sent" end The above is returning uninitialized constant SmsSender. I'm sure this is dead simple, but how can I access the SmsSender class from within my model?

    Read the article

  • Create IEnumerable<T>.Find()

    - by Brian
    I'd like to write: IEnumerable<Car> cars; cars.Find(car => car.Color == "Blue") Can I accomplish this with extension methods? The following fails because it recursively calls itself rather than calling IList.Find(). public static T Find<T>(this IEnumerable<T> list, Predicate<PermitSummary> match) { return list.ToList().Find(match); } Thanks!

    Read the article

  • Methods of pulling data from a database

    - by kingrichard2005
    I'm getting ready to start a C# web application project and just wanted some opinions regarding pulling data from a database. As far as I can tell, I can either use C# code to access the database from the code behind (i.e. LINQ) of my web app or I can call a stored procedure that will collect all the data and then read it with a few lines of code in my code behind. I'm curious to know which of these two approaches, or any other approach, would be the most efficient, elegant, future proof and easiest to test.

    Read the article

  • Programatically WPF Fade In (via extension methods)

    - by Dinis Cruz
    I'm trying to write a simple (stand alone) C# extension method to do a Fade-In of a generic WPF UIElement, but the solutions (and code samples) that I found all contain a large number of moving parts (like setting up a story, etc...) For reference here is an example of the type of API method I would like to create. This code will rotate an UIElement according to the values provided (fromValue, toValue, duration and loop) public static T rotate<T>(this T uiElement, double fromValue, double toValue, int durationInSeconds, bool loopAnimation) where T : UIElement { return (T)uiElement.wpfInvoke( ()=>{ DoubleAnimation doubleAnimation = new DoubleAnimation(fromValue, toValue, new Duration(TimeSpan.FromSeconds(durationInSeconds))); RotateTransform rotateTransform = new RotateTransform(); uiElement.RenderTransform = rotateTransform; uiElement.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5); if (loopAnimation) doubleAnimation.RepeatBehavior = RepeatBehavior.Forever; rotateTransform.BeginAnimation(RotateTransform.AngleProperty, doubleAnimation); return uiElement; }); }

    Read the article

  • Fabric methods exceptions

    - by baobee
    I try to make Fabric func, which checks if Apache installed: from fabric.api import * def check_apache(): try: result = local('httpd -v', capture=True) except: print "check_apache exception" But if httpd not installed I get: [root@server-local ~]$ fab check_apache Fatal error: local() encountered an error (return code 127) while executing 'ahttpd -v' Aborting. check_apache exception Done. How can I get correct exception for Fabric local() method ? So I need to get exception and continue executing without any Fabric error messages: [root@server-local ~]$ fab check_apache check_apache exception Done.

    Read the article

  • Methods to Analyze Sell Orders (in a video game)

    - by Travis
    I'm building a market manager for EVE, but this problem should be solvable without any prior knowledge of the game. Basically, sell orders in EVE look like this: All I'm really concerned with is picking a good price. The numbers the program would pick are sent out to our production team so they can buy the items to build things. Just like in a real market, the numbers we send off need to reflect the cheapest price that still offers a good quantity. Also, available quantities change over time, so we can't just pick the lowest listed price. For example, in the screencap above, we would set the sell price between 2,800.00 ISK and 3,000.00 ISK, even if only 500 units were needed. Even though the cheapest order would fit the quantity, it would probably quickly disappear. It would be better to set the price a tad higher so we don't underpay the production people. The Question: It's easy enough to figure prices out just by looking at the data, but I can't figure out how to have a program [java] do it. Different items sell with much less or more quantities (i.e. 3 or 300 or 3000 items) so the program has to be able to modify itself based on the offerings. I don't really want code as much as I do a way to think this through. Thanks in advance.

    Read the article

  • Difference in casting in the following 2 methods

    - by Shrewd Demon
    hi, can somebody please tell me what is the difference between the following two statements, because both of them give me the same results. Also i want to know which is better. Label lblSome = e.Item.FindControl("lblMyLable") as Label; && Label lblSome = (Label)e.Item.FindControl("lblMyLable"); thank you so much.

    Read the article

  • Use of GORM methods in Integration test

    - by canotto90
    I'm trying to use gorm find method on my domain class, inside of an Spock Integration Spec. My code: class myDomainClassSpec extends IntegrationSpec{ ... def 'my test'() { when: ... then: MyDomainClass.find { id == 1 } } ... } This fails, throwing: groovy.lang.MissingPropertyException: No such property: id for class: grails.gorm.DetachedCriteria If instead I code: MyDomainClass.findAll().find { id == 1 } it works. Any ideas??

    Read the article

  • Wildcards vs. generic methods

    - by FredOverflow
    Is there any practical difference between the following approaches to print all elements in a range? public static void printA(Iterable<?> range) { for (Object o : range) { System.out.println(o); } } public static <T> void printB(Iterable<T> range) { for (T x : range) { System.out.println(x); } } Apparently, printB involves an additional checked cast to Object (see line 16), which seems rather stupid to me -- isn't everything an Object anyway? public static void printA(java.lang.Iterable); Code: 0: aload_0 1: invokeinterface #18, 1; //InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator; 6: astore_2 7: goto 24 10: aload_2 11: invokeinterface #24, 1; //InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object; 16: astore_1 17: getstatic #30; //Field java/lang/System.out:Ljava/io/PrintStream; 20: aload_1 21: invokevirtual #36; //Method java/io/PrintStream.println:(Ljava/lang/Object;)V 24: aload_2 25: invokeinterface #42, 1; //InterfaceMethod java/util/Iterator.hasNext:()Z 30: ifne 10 33: return public static void printB(java.lang.Iterable); Code: 0: aload_0 1: invokeinterface #18, 1; //InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator; 6: astore_2 7: goto 27 10: aload_2 11: invokeinterface #24, 1; //InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object; 16: checkcast #3; //class java/lang/Object 19: astore_1 20: getstatic #30; //Field java/lang/System.out:Ljava/io/PrintStream; 23: aload_1 24: invokevirtual #36; //Method java/io/PrintStream.println:(Ljava/lang/Object;)V 27: aload_2 28: invokeinterface #42, 1; //InterfaceMethod java/util/Iterator.hasNext:()Z 33: ifne 10 36: return

    Read the article

  • Objetive C - Calling Methods in objects.

    - by Mace
    I'm new to Objective C, and I seem to be struggling with accessing a method of an object I created. I'm checking out the documentation , but I'm not entirely sure tha tthis is a job for a delegate. For example I have an object (1) that creates another object (2). I can access a method of the object (2) after I create it, but I can't access it from a method of object (1). I get a error that the object was not defined in this scope. If anyone can help I greatly appreciate it. I just need a nudge in the right direction so that I can at least get a grasp on how to think about the interaction between the objects.

    Read the article

  • Ruby: Dynamically calling available methods raising undefined method (metaprogramming)

    - by user94154
    I have an Activerecord object called Foo: Foo.attribute_names.each do |attribute| puts Foo.find(:all)[0].method(attribute.to_sym).call end Here I'm calling all attributes on this model (ie, querying for each column value). However, sometimes, I'll get an undefined method error. How can ActiveRecord::Base#attribute_names return an attribute name that when converted into its own method call, raises an undefined method error? Thank

    Read the article

  • Testing InlineFormset clean methods

    - by Rory
    I have a Django project, with 2 models, a Structure and Bracket, the Bracket has a ForeignKey to a Structure (i.e. one-to-many, one Structure has many Brackets). I created a TabularInline for the admin site, so that there would be a table of Brackets on the Structure. I added a custom formset with some a custom clean method to do some extra validation, you can't have a Bracket that conflicts with another Bracket on the same Structure etc. The admin looks like this: class BracketInline(admin.TabularInline): model = Bracket formset = BracketInlineFormset class StructureAdmin(admin.ModelAdmin): inlines = [ BracketInline ] admin.site.register(Structure, StructureAdmin) That all works, and the validation works. However now I want to write some unittest to test my complex formset validation logic. My first attempt to validate known-good values is: data = {'form-TOTAL_FORMS': '1', 'form-INITIAL_FORMS': '0', 'form-MAX_NUM_FORMS': '', 'form-0-field1':'good-value', … } formset = BracketInlineFormset(data) self.assertTrue(formset.is_valid()) However that doesn't work and raises the exception: ====================================================================== ERROR: testValid (appname.tests.StructureTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/paht/to/project/tests.py", line 494, in testValid formset = BracketInlineFormset(data) File "/path/to/django/forms/models.py", line 672, in __init__ self.instance = self.fk.rel.to() AttributeError: 'BracketInlineFormset' object has no attribute 'fk' ---------------------------------------------------------------------- The Django documentation (for formset validation) implies one can do this. How come this isn't working? How do I test the custom clean()/validation for my inline formset?

    Read the article

  • MustOverride Shared Methods in .Net

    - by Ben
    Hi I have a few class's that inherit from a base class. I want to enforce that all of these Class's implement a shared method foo(). I am not able to create the following on the base class Public MustOvveride Shared Sub foo() as this is not allowed. I also cant create an Interface that defines a Shared Sub Foo() and implement that in my derrived class's, as this also is not allowed. Does anyone know how i should implement this? p.s i realise my example is in VB and i have also tagged C#, the same problem applies to both languages and presumably the same fix would apply.

    Read the article

  • virtual methods and template classes

    - by soxs060389
    Hi I got over a problem, I think a very specific one. I've got 2 classes, a B aseclass and a D erived class (from B aseclass). B is a template class ( or class template) and has a pure virtual method virutal void work(const T &dummy) = 0; The D erived class is supposed to reimplement this, but as D is Derived from B rather than D being another template class, the compiler spits at me that virtual functions and templates don't work at once. Any ideas how to acomplish what I want? I am thankfull for any thoughts and Ideas, especially if you allready worked out that problem this class is fixed aka AS IS, I can not edit this without breaking existing code base template <typename T> class B { public: ... virtual void work(const T &dummy) = 0; .. }; take int* as an example class D : public B<int*>{ ... virtual void work(const int* &dummy){ /* put work code here */ } .. }; Edit: The compiler tells me, that void B<T>::work(const T&) [with T = int*] is pure virtual within D

    Read the article

  • Calling delegate methods and calling selectors

    - by Crystal
    I'm new to the concept of delegates and selectors when used with notifications. So my first question is, 1) Let's say you have a button that has a delegate that implements some doWork method. If you want the same functionality that's in the method, is it 'ok' to just call that method? I didn't know if that was considered good coding practices and/or if you should do that, or do something different in getting that type of functionality. Like if that is ok architecture? 2) Similarly, with NSNotificationCenter, I see some code that posts a notification. Then there's a HandleSegmentedControl:(NSNotification *)notification method. If I want to manually have that functionality, but without pressing the segment control, is it 'ok' to just take that functionality out of that method and put it in a new method so it would look like this: Original: - (void)HandleSegmentedControl:(NSNotification *)notification { NSDictionary *dict = [userInfo notification]; // do stuff with the dictionary } New: - (void)HandleSegmentedControl:(NSNotification *)notification { NSDictionary *dict = [userInfo notification]; [self newMethod:dict]; } - (void)newMethod:(NSDictionary *)dict { // do stuff with the dictionary } - (void)myOtherMethodThatNeedsTheSameFunctionality { NSDictionary *dict = // create some dictionary [self newMethod:dict]; } Sorry if these are basic questions. I'm not sure what the best practices are for things like this and wanted to start the right way. Thanks.

    Read the article

  • java thread - run() and start() methods

    - by JavaUser
    Please explain the output of the below code: If I call th1.run() ,the output is EXTENDS RUN RUNNABLE RUN If I call th1.start() , the output is : RUNNABLE RUN EXTENDS RUN Why this inconsistency . Please explain. class ThreadExample extends Thread{ public void run(){ System.out.println("EXTENDS RUN"); } } class ThreadExampleRunnable implements Runnable { public void run(){ System.out.println("RUNNABLE RUN "); } } class ThreadExampleMain{ public static void main(String[] args){ ThreadExample th1 = new ThreadExample(); //th1.start(); th1.run(); ThreadExampleRunnable th2 = new ThreadExampleRunnable(); th2.run(); } }

    Read the article

< Previous Page | 55 56 57 58 59 60 61 62 63 64 65 66  | Next Page >