h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote {
margin: 0;
padding: 0;
}
body {
font-family: "Helvetica Neue", Helvetica, "Hiragino Sans GB", Arial, sans-serif;
font-size: 13px;
line-height: 18px;
color: #737373;
background-color: white;
margin: 10px 13px 10px 13px;
}
table {
margin: 10px 0 15px 0;
border-collapse: collapse;
}
td,th {
border: 1px solid #ddd;
padding: 3px 10px;
}
th {
padding: 5px 10px;
}
a {
color: #0069d6;
}
a:hover {
color: #0050a3;
text-decoration: none;
}
a img {
border: none;
}
p {
margin-bottom: 9px;
}
h1,
h2,
h3,
h4,
h5,
h6 {
color: #404040;
line-height: 36px;
}
h1 {
margin-bottom: 18px;
font-size: 30px;
}
h2 {
font-size: 24px;
}
h3 {
font-size: 18px;
}
h4 {
font-size: 16px;
}
h5 {
font-size: 14px;
}
h6 {
font-size: 13px;
}
hr {
margin: 0 0 19px;
border: 0;
border-bottom: 1px solid #ccc;
}
blockquote {
padding: 13px 13px 21px 15px;
margin-bottom: 18px;
font-family:georgia,serif;
font-style: italic;
}
blockquote:before {
content:"\201C";
font-size:40px;
margin-left:-10px;
font-family:georgia,serif;
color:#eee;
}
blockquote p {
font-size: 14px;
font-weight: 300;
line-height: 18px;
margin-bottom: 0;
font-style: italic;
}
code, pre {
font-family: Monaco, Andale Mono, Courier New, monospace;
}
code {
background-color: #fee9cc;
color: rgba(0, 0, 0, 0.75);
padding: 1px 3px;
font-size: 12px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
pre {
display: block;
padding: 14px;
margin: 0 0 18px;
line-height: 16px;
font-size: 11px;
border: 1px solid #d9d9d9;
white-space: pre-wrap;
word-wrap: break-word;
}
pre code {
background-color: #fff;
color:#737373;
font-size: 11px;
padding: 0;
}
sup {
font-size: 0.83em;
vertical-align: super;
line-height: 0;
}
* {
-webkit-print-color-adjust: exact;
}
@media screen and (min-width: 914px) {
body {
width: 854px;
margin:10px auto;
}
}
@media print {
body,code,pre code,h1,h2,h3,h4,h5,h6 {
color: black;
}
table, pre {
page-break-inside: avoid;
}
}
Category And Extension(二)
Category And Extension(二)
add property to category
上一篇文章说不能加category添加属性,最近做的一个项目刚好有这个需求,google了一下,其实category是有办法添加属性的-_-,而且还有多种方法,在这里总结一下.
1>.methods1
直接在category的.h中添加,这时xcode会有warning。
Property ‘test1‘ requires method ‘test1‘ to be defined - use @dynamic or provide a method implementation in this category
按照提示在.m文件在@dynamic关键字修改就OK了。dynamic在编译时不会检查setter/getter的实现,在运行时setter/getter会动态绑定,在需要setter/getter的class中自己实现就OK了。
#import <Foundation/Foundation.h>
@interface NSObject (AddProperty1)
@property(nonatomic,strong)NSString *test1;
@end
----------------------------------------------------------------------
#import "NSObject+AddProperty1.h"
@implementation NSObject (AddProperty1)
@dynamic test1;
@end
(在用这种方法添加proprety,使用setter/getter的class如果不implementation会crash的)
2>.methods2
//只用在.h文件添加协议
#import <Foundation/Foundation.h>
@protocol NSObjectProtocol <NSObject>
@optional
@property(nonatomic,strong)NSString *test3;
@end
@interface NSObject (AddProperty3)<NSObjectProtocol>
@end
同上一种方法一样,在使用setter/getter的class中要implementation,否则会crash
3>.methods3
#import <Foundation/Foundation.h>
@interface NSObject (AddProperty2)
@property(nonatomic,strong)NSString *test2;
@end
----------------------------------------------------------------------
#import "NSObject+AddProperty2.h"
#import <objc/runtime.h>
@implementation NSObject (AddProperty2)
-(NSString*)test2{
return objc_getAssociatedObject(self, @selector(test2));
}
-(void)setTest2:(NSString *)test2{
objc_setAssociatedObject(self, @selector(test2), test2, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@end
利用objctive-c的runtime特性。个人更偏好于第三种方法,改动最小,而且在不知道源码的源码的情况下也能add property
附上Demo省得以后自己忘记了
category and extension(二)