Skip to content

Commit ef33996

Browse files
committed
分类@Property的技巧
1 parent ef2e101 commit ef33996

File tree

9 files changed

+101
-77
lines changed

9 files changed

+101
-77
lines changed

属性相关问题/属性相关问题.xcodeproj/project.pbxproj

+11-27
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
04BA96C81F5FDFB200FECB55 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 04BA96C71F5FDFB200FECB55 /* Main.storyboard */; };
11+
04BA96CA1F5FE00600FECB55 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 04BA96C91F5FE00600FECB55 /* LaunchScreen.storyboard */; };
1012
2ACA7EAF1F5703200056D483 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2ACA7EAE1F5703200056D483 /* AppDelegate.m */; };
1113
2ACA7EB21F5703200056D483 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2ACA7EB11F5703200056D483 /* ViewController.m */; };
12-
2ACA7EB51F5703200056D483 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2ACA7EB31F5703200056D483 /* Main.storyboard */; };
1314
2ACA7EB71F5703200056D483 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2ACA7EB61F5703200056D483 /* Assets.xcassets */; };
14-
2ACA7EBA1F5703200056D483 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2ACA7EB81F5703200056D483 /* LaunchScreen.storyboard */; };
1515
2ACA7EBD1F5703200056D483 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2ACA7EBC1F5703200056D483 /* main.m */; };
1616
2ACA7EC71F57033D0056D483 /* Person.m in Sources */ = {isa = PBXBuildFile; fileRef = 2ACA7EC61F5703330056D483 /* Person.m */; };
1717
2ACA7EC81F57033D0056D483 /* Teacher.m in Sources */ = {isa = PBXBuildFile; fileRef = 2ACA7EC31F5703330056D483 /* Teacher.m */; };
1818
/* End PBXBuildFile section */
1919

2020
/* Begin PBXFileReference section */
21+
04BA96C71F5FDFB200FECB55 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
22+
04BA96C91F5FE00600FECB55 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
2123
2ACA7EAA1F5703200056D483 /* 属性相关问题.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "属性相关问题.app"; sourceTree = BUILT_PRODUCTS_DIR; };
2224
2ACA7EAD1F5703200056D483 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
2325
2ACA7EAE1F5703200056D483 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
2426
2ACA7EB01F5703200056D483 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
2527
2ACA7EB11F5703200056D483 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
26-
2ACA7EB41F5703200056D483 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
2728
2ACA7EB61F5703200056D483 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
28-
2ACA7EB91F5703200056D483 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
2929
2ACA7EBB1F5703200056D483 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3030
2ACA7EBC1F5703200056D483 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
3131
2ACA7EC31F5703330056D483 /* Teacher.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Teacher.m; sourceTree = "<group>"; };
@@ -72,9 +72,9 @@
7272
2ACA7EAE1F5703200056D483 /* AppDelegate.m */,
7373
2ACA7EB01F5703200056D483 /* ViewController.h */,
7474
2ACA7EB11F5703200056D483 /* ViewController.m */,
75-
2ACA7EB31F5703200056D483 /* Main.storyboard */,
75+
04BA96C71F5FDFB200FECB55 /* Main.storyboard */,
7676
2ACA7EB61F5703200056D483 /* Assets.xcassets */,
77-
2ACA7EB81F5703200056D483 /* LaunchScreen.storyboard */,
77+
04BA96C91F5FE00600FECB55 /* LaunchScreen.storyboard */,
7878
2ACA7EBB1F5703200056D483 /* Info.plist */,
7979
2ACA7EBC1F5703200056D483 /* main.m */,
8080
);
@@ -138,9 +138,9 @@
138138
isa = PBXResourcesBuildPhase;
139139
buildActionMask = 2147483647;
140140
files = (
141-
2ACA7EBA1F5703200056D483 /* LaunchScreen.storyboard in Resources */,
141+
04BA96CA1F5FE00600FECB55 /* LaunchScreen.storyboard in Resources */,
142+
04BA96C81F5FDFB200FECB55 /* Main.storyboard in Resources */,
142143
2ACA7EB71F5703200056D483 /* Assets.xcassets in Resources */,
143-
2ACA7EB51F5703200056D483 /* Main.storyboard in Resources */,
144144
);
145145
runOnlyForDeploymentPostprocessing = 0;
146146
};
@@ -161,25 +161,6 @@
161161
};
162162
/* End PBXSourcesBuildPhase section */
163163

164-
/* Begin PBXVariantGroup section */
165-
2ACA7EB31F5703200056D483 /* Main.storyboard */ = {
166-
isa = PBXVariantGroup;
167-
children = (
168-
2ACA7EB41F5703200056D483 /* Base */,
169-
);
170-
name = Main.storyboard;
171-
sourceTree = "<group>";
172-
};
173-
2ACA7EB81F5703200056D483 /* LaunchScreen.storyboard */ = {
174-
isa = PBXVariantGroup;
175-
children = (
176-
2ACA7EB91F5703200056D483 /* Base */,
177-
);
178-
name = LaunchScreen.storyboard;
179-
sourceTree = "<group>";
180-
};
181-
/* End PBXVariantGroup section */
182-
183164
/* Begin XCBuildConfiguration section */
184165
2ACA7EBE1F5703200056D483 /* Debug */ = {
185166
isa = XCBuildConfiguration;
@@ -291,6 +272,7 @@
291272
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
292273
DEVELOPMENT_TEAM = MYDTTEQ9YB;
293274
INFOPLIST_FILE = "属性相关问题/Info.plist";
275+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
294276
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
295277
PRODUCT_BUNDLE_IDENTIFIER = "yunjifen.------";
296278
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -304,6 +286,7 @@
304286
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
305287
DEVELOPMENT_TEAM = MYDTTEQ9YB;
306288
INFOPLIST_FILE = "属性相关问题/Info.plist";
289+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
307290
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
308291
PRODUCT_BUNDLE_IDENTIFIER = "yunjifen.------";
309292
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -330,6 +313,7 @@
330313
2ACA7EC21F5703200056D483 /* Release */,
331314
);
332315
defaultConfigurationIsVisible = 0;
316+
defaultConfigurationName = Release;
333317
};
334318
/* End XCConfigurationList section */
335319
};

属性相关问题/属性相关问题/Base.lproj/LaunchScreen.storyboard

-25
This file was deleted.

属性相关问题/属性相关问题/Base.lproj/Main.storyboard

-24
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
6+
<dependencies>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
9+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10+
</dependencies>
11+
<scenes>
12+
<!--View Controller-->
13+
<scene sceneID="sah-HZ-Euh">
14+
<objects>
15+
<viewController id="zOw-OK-6Lm" sceneMemberID="viewController">
16+
<layoutGuides>
17+
<viewControllerLayoutGuide type="top" id="SrZ-sd-klq"/>
18+
<viewControllerLayoutGuide type="bottom" id="4lI-co-0K6"/>
19+
</layoutGuides>
20+
<view key="view" contentMode="scaleToFill" id="CPx-yh-0B8">
21+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
22+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
23+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
24+
</view>
25+
</viewController>
26+
<placeholder placeholderIdentifier="IBFirstResponder" id="sgN-uD-5ct" userLabel="First Responder" sceneMemberID="firstResponder"/>
27+
</objects>
28+
<point key="canvasLocation" x="-214" y="125"/>
29+
</scene>
30+
</scenes>
31+
</document>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="e8I-jJ-C2a">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
6+
<dependencies>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
9+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10+
</dependencies>
11+
<scenes>
12+
<!--View Controller-->
13+
<scene sceneID="lW8-a1-E8E">
14+
<objects>
15+
<viewController id="e8I-jJ-C2a" customClass="ViewController" sceneMemberID="viewController">
16+
<layoutGuides>
17+
<viewControllerLayoutGuide type="top" id="wIA-hh-aZ4"/>
18+
<viewControllerLayoutGuide type="bottom" id="IEi-kZ-Pl7"/>
19+
</layoutGuides>
20+
<view key="view" contentMode="scaleToFill" id="TvE-qV-zDK">
21+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
22+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
23+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
24+
</view>
25+
</viewController>
26+
<placeholder placeholderIdentifier="IBFirstResponder" id="LzH-qt-gOL" userLabel="First Responder" sceneMemberID="firstResponder"/>
27+
</objects>
28+
<point key="canvasLocation" x="-302" y="-292"/>
29+
</scene>
30+
</scenes>
31+
</document>

属性相关问题/属性相关问题/Person.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@
4141
@property(nonatomic,copy) NSString *age;
4242
@property(nonatomic,copy) NSString *weight;
4343

44-
// 通过@property 自动生成的成员变量 相当于在.m文件 对外不可见
44+
// 通过@property 自动生成的成员变量 是私有的
4545
@property(nonatomic,copy) NSString *height;
4646

47+
@property(nonatomic,copy,readonly) NSString *wife;
48+
4749

4850

4951
@end

属性相关问题/属性相关问题/Person.m

+13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ @interface Person ()
1616

1717
@property(nonatomic,copy) NSString *hobby;
1818

19+
@property(nonatomic,copy,readwrite) NSString *wife;
20+
21+
1922
@end
2023

2124

@@ -42,6 +45,16 @@ - (instancetype)init{
4245
}
4346

4447

48+
- (void)setWife:(NSString *)wife{
49+
50+
_wife = [wife copy];
51+
52+
}
53+
54+
55+
56+
57+
4558
- (NSString *)description{
4659

4760
return [NSString stringWithFormat:@"sex:%@ name:%@ age:%@ weight:%@ height:%@ hobby:%@",self.sex,self.name,self.age,self.weight,self.height,self.hobby];

属性相关问题/属性相关问题/Teacher.m

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ - (instancetype)init{
5252
// _age = @"120";
5353
self.age = @"100"; // 间接访问私有成员变量
5454

55+
5556
_height = @"180cm";
5657

5758
// self->_hobby; // 不能直接访问_hobby 因为本类中没有这个成员变量

属性相关问题/属性相关问题/ViewController.m

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
#import "Person.h"
1212
#import "Teacher.h"
1313

14+
15+
@interface Person (wife)
16+
// 分类生成方法getter和seter声明
17+
@property(nonatomic,copy) NSString *wife;
18+
19+
20+
@end
21+
22+
1423
@interface ViewController ()
1524

1625
@end
@@ -29,6 +38,8 @@ - (void)viewDidLoad {
2938
NSLog(@"%@",p.description);
3039

3140

41+
p.wife = @"beauty";
42+
3243
}
3344

3445

0 commit comments

Comments
 (0)