Month: September 2014
Core Data Transient Properties [MUST READ IF YOU USING CORE DATA]
UIBarButtonItem title 入 nil 唔好入 @””
用 code 整 nav button … 如果無 title 就入 nil … 入 @”” … 佢會因為其他有 component 郁 而 會移動並出現在 strange position
錯的
UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithTitle:@""
style:UIBarButtonItemStylePlain
target:self
action:@selector(showLeftMenu:)];
對的
UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithTitle:nil
style:UIBarButtonItemStylePlain
target:self
action:@selector(showLeftMenu:)];
utf8mb4, string (or say varchar) want create key, length = 191
why python string has b, u in prefix
decorator in python
http://www.dotblogs.com.tw/rickyteng/archive/2013/11/06/126852.aspx
class entryExit(object):
def __init__(self, f):
print 'entry init enter'
self.f = f
print 'entry init exit'
def __call__(self, *args):
print "Entering", self.f.__name__
r = self.f(*args)
print "Exited", self.f.__name__
return r
print 'decorator using'
@entryExit
def hello(a):
print 'inside hello'
return "hello world " + a
print 'test start'
print hello('friends')
>>> ================================ RESTART ================================
>>>
decorator using
entry init enter
entry init exit
test start
Entering hello
inside hello
Exited hello
hello world friends
property inheritance in ios
http://bhapca.blogspot.hk/2012/11/how-to-access-backing-ivars-for.html
How to access backing ivars for inherited properties in Objective-C
I had a superclass that declared and synthesized a read only property, meant to be set in its subclasses. The code was something like this:
@interface A : NSObject
@property (nonatomic, readonly) NSUInteger prop;
@end
@implementation A
@synthesize prop = _prop;
@end
@interface B : A
@end
@implementation B
- (void)establishValueForProp
{
_prop = 1; // PROBLEM !!!
}
@end
The instance variable backing the property seemed to be invisible in the subclass. The error was pretty unclear when compiling an iOS app: “Use of undeclared identifier ‘_prop'”. To get around the error I did the following:
@interface A : NSObject {
NSUInteger _prop;
}
@property (nonatomic, readonly) NSUInteger prop;
@end
That is, I explicitly declared the backing variable in the declaration of the superclass.
Interestingly, when I was preparing this blog post I compiled the code above as a “Command Line Tool” type of project, not an iOS app. The error was different, dare I say better, more telling of the root cause: “Instance variable ‘_prop’ is private”. So it’s a matter of the visibility of the ivar, so perhaps a better fix would be:
@interface A : NSObject {
@protected
NSUInteger _prop;
}
@property (nonatomic, readonly) NSUInteger prop;
@end
Kind of interesting though that properties are synthesized by default as private ivars. Learned something new.
Posted by Bogdan Hapca at 12:09 PM
Email This
BlogThis!
Share to Twitter
Share to Facebook
Share to Pinterest
Labels: iOS, Objective-C
1 comment:
Liviu Macsen said…
Thank your Bogdan for your solution. I found that you can also synthesize in subclass in order to solve this problem.
@implementation B
@synthesize prop = _prop;
- (void)establishValueForProp
{
_prop = 1; // Working !!!
}
@end