private

About private instance variables in Objective-C

两盒软妹~` 提交于 2019-12-04 19:18:00
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" mean? Thanks. Hard Error means that sometime in the future the compiler will behave the way you expect it to behave (i.e., it won't compile the source file when you directly access an instance variable outside the defined visibility scope). Right now the compiler simply isn't enforcing Objective-C the

Private properties vs instance variables in ARC [duplicate]

。_饼干妹妹 提交于 2019-12-04 18:21:56
This question already has an answer here : Best way of declaring private variables in cocoa (1 answer) Closed 6 years ago . Having ARC enabled for an iOS app, if I want a class to have a private value/object, it should be better to declare this: // .m file @interface MyClass () @property (strong, nonatomic) NSString *name; @end or this?: @implementation MyClass { NSString *name; } What memory management considerations should I have? Thanks! You can use either approach. In the first case you are declaring a private property--which has some benefits. For instance you could expose that private

Java: Accessing private fields directly from another instance of the same class

丶灬走出姿态 提交于 2019-12-04 17:43:03
问题 I'm writing a equals(Object obj) function for a class. I see that it is possible to access the private fields of obj from the caller. So instead of using a getter: Odp other = (Odp) obj; if (! other.getCollection().contains(ftw)) { } I can just access the field directly: Odp other = (Odp) obj; if (! other.collection.contains(ftw)) { } Is this bad practice? 回答1: No, it's not. The reason that private variables and methods are not accessable from other classes is to allow you to change the

why private static methods exists those are not being called in any static context?

末鹿安然 提交于 2019-12-04 16:31:59
Since static things loaded at time of class loading,and can be used even before object creation as ClassName.member but if static method is private,so you can only do this thing ClassName.method() inside class which is also accessible by directly method() without appending classname. Hence making a private method static has no significance untill it is not being used in any static method of same class.since only private can not be use in some other static method of same class. But I seen some method those are not being use in any other static stuff and still they are static .For Example

returning reference to private vs public member

ⅰ亾dé卋堺 提交于 2019-12-04 16:05:59
I would like to know what could be reasons to provide a public access method returning a reference instead of making the member public. QPoint has methods int& rx and int& ry that let me directly manipulate the coordinates. I guess the implentation looks similar to this: public: int& rx(){return x;} private: int x; The only idea I had so far is the following: By keeping the member private and "only" providing a reference, the class can still change to use a different data type for its coordinates and while still "somehow" returning a reference to an int. However, this "somehow" would always

Using the YouTube API v3 to list all private videos

霸气de小男生 提交于 2019-12-04 15:46:25
Currently I'm building a site that will use a small number of user uploaded videos. These videos are uploaded to the server, then moved on to YouTube via the API v3. The private tag is set, and all videos are uploaded into one central account. My problem is; how can I access and list all these private videos via the API to display on my site? I'm not sure if this is possible. Any feed back would be much appreciated. After looking into it more I found this . After looking through the docs I couldn't find a PHP specific example of how I could do this: getuserUploads. Get the ZF Gdata Library @

Marking instance variables @private

强颜欢笑 提交于 2019-12-04 15:33:00
I've noticed that a lot of Apple's interfaces use @private before their instance variable declarations. Is there a good design reason for this, and is it something I should do? Private instance variables are used to separate interface from implementation. In Objective-C, since the class declaration must show all of the instance variables, there needs to be a way to prevent subclasses from accessing the ones that are part of the internal implementation. Otherwise, other programmers could write code that depends on those internal variables, which would make it impossible for the class designer

Why can test private methods/fields in Spock without problems?

折月煮酒 提交于 2019-12-04 15:18:45
问题 package com.example.dev; public class AClass { private Integer a =10; ...//other code } and when I try to access a in my Spock method: package com.example.dev; def 'test a'() { AClass aClassVar = new AClass() aClassVar.a = new Integer(100); ...//other testing stuff } It works fine. Why this happens? Is Spock use reflection for accessing the private fields? Or my encapsulation in not written well? 回答1: Spock isn't guilty, it's groovy itself, see: Private method in groovy is not private. While

PubNub best practice: How to manage private rooms?

淺唱寂寞╮ 提交于 2019-12-04 14:31:00
问题 I'm learning pubnub and I read their documentation but I just can't find how to manage a multi room chat box. By default, a channel can be listened by anyone. Subscribing to it and publishing on it is easy. What I want is to have a main public room (so far so good) but anyone should also be able to talk privately to anyone else without the risk of being read by other users. These dynamic rooms would be tabbed and the user should be able to go from one to another. Another requirement would be

Importing Package-Private Classes to JShell

痴心易碎 提交于 2019-12-04 09:27:41
I was playing around with JShell after the Java 9 release, and I tried importing a package I made. As the entire application I'm coding it for will be contained in that package, every class but one (which I haven't coded yet) is package-private. My classpath is correct, but I still can't use any of the types declared in the package in JShell (it throws a "cannot find symbol" error). Do I need to make them public for them to be accessible, or is there some way I can test package-private classes ? Here's the exact code I tried. My current directory is C:\Users\Sylvaenn\OneDrive\Documents