做 self = self init; return 自我;在 objective-C 中与 swift 中的 self.init() 具有相同的效果吗?
Does doing self = self init; return self; in objective-C have the same effect as self.init() in swift?
正在做:
self = self.init;
return self;
在objective-C中的效果与:
相同
self.init()
在 swift?
例如,在这种情况下:
else if([format.dateFormatType compare: ISO8601DateFormatType] == NSOrderedSame) {
NSString *isoFormat = ISO8601DateFormatType;
NSString *dateFormat = (isoFormat != nil) ? isoFormat : ISO8601DateFormatType;
NSDateFormatter *formatter = [DateFormat CustomDateFormat: dateFormat];
formatter.locale = [NSLocale localeWithLocaleIdentifier: (@"en_US_POSIX")];
formatter.timeZone = [NSTimeZone localTimeZone];
formatter.dateFormat = dateFormat;
NSDate *date = [formatter dateFromString:(string)];
if (date != nil){
return [self initWithTimeInterval: 0 sinceDate: date];
}
else {
self = self.init;
return self;
}
}
self.init()
在 Objective-C 的同一范围内调用指定或默认初始化程序的等价物是
if (date != nil) {
return [self initWithTimeInterval: 0 sinceDate: date];
} else {
return [self init];
}
正在做:
self = self.init;
return self;
在objective-C中的效果与:
相同self.init()
在 swift?
例如,在这种情况下:
else if([format.dateFormatType compare: ISO8601DateFormatType] == NSOrderedSame) {
NSString *isoFormat = ISO8601DateFormatType;
NSString *dateFormat = (isoFormat != nil) ? isoFormat : ISO8601DateFormatType;
NSDateFormatter *formatter = [DateFormat CustomDateFormat: dateFormat];
formatter.locale = [NSLocale localeWithLocaleIdentifier: (@"en_US_POSIX")];
formatter.timeZone = [NSTimeZone localTimeZone];
formatter.dateFormat = dateFormat;
NSDate *date = [formatter dateFromString:(string)];
if (date != nil){
return [self initWithTimeInterval: 0 sinceDate: date];
}
else {
self = self.init;
return self;
}
}
self.init()
在 Objective-C 的同一范围内调用指定或默认初始化程序的等价物是
if (date != nil) {
return [self initWithTimeInterval: 0 sinceDate: date];
} else {
return [self init];
}