Í·Îļþ#importµÄ˳Ðò(ÉÌÁ¿)
д·¨Ä£°å
#import <ϵͳ¿â>
#import <µÚÈý·½¿â>
#import ¡°ÆäËûÀࡱ
¾¡Á¿°´ÕÕÏÈϵͳÀà µÚÈý·½Àà ×Ô¼ºÐ´µÄÀà˳Ðòµ¼Èë Öм䲻ÄÜÓпոñ
½¨ÒéµÄд·¨
#import <UIKit/UIKit.h>
#import <Google/Analytics.h>
#import "GBOrderEmptyView.h" |
²»½¨ÒéµÄд·¨
#import "GBOrderEmptyView.h"
#import <UIKit/UIKit.h>
#import <Google/Analytics.h> |
@ClassµÄд·¨
д·¨Ä£°å
@class class1, class2;
½¨ÒéµÄд·¨
²»½¨ÒéµÄд·¨
@class UIPress;
@class UIPressesEvent; |
@InterfaceµÄд·¨
д·¨Ä£°å
@interface ÀàÃû : ¸¸Àà <ÐÒé1, ÐÒé2>
@interfaceºÍÀàÃûÖмäÒ»¸ö¿Õ¸ñ
ÀàÃûºó½ô¸ú:Ö®ºó¿Õ¸ñ¼ÓÉϸ¸ÀàÐÒéÖ®¼äÓÃ,¿Õ¸ñ·Ö¸î
½¨ÒéµÄд·¨
@interface AppDelegate
: UIResponder <UIApplicationDelegate,
UITableViewDataSource> |
²»½¨ÒéµÄд·¨
@interface AppDelegate:UIResponder
<UIApplicationDelegate,UITableViewDataSource> |
@protocolµÄд·¨
д·¨µÄÄ£°å
@protocol ÐÒéµÄÃû³Æ <ÐÒé1, ÐÒé2>
@potocolºÍÐÒéµÄÃû³ÆÓпոñ ÐÒéµÄÃû³ÆºÍÆäËûÐÒéÓпոñ ÆäËûÐÒéÖ®¼äÓпոñ
½¨ÒéµÄд·¨
@protocol UIResponderStandardEditActions
<NSObject> |
²»½¨ÒéµÄд·¨
@protocol UIResponderStandardEditActions<NSObject> |
@propertyµÄд·¨
@property (¹Ø¼ü´Ê, ¹Ø¼ü´Ê) Àà *±äÁ¿Ãû³Æ;
¹Ø¼ü´ÊÓÃ,¿Õ¸ñ·Ö¸î Ààǰºó¿Õ¸ñ
Õýȷд·¨
@property (strong,
nonatomic) UIWindow *window; |
²»½¨ÒéµÄд·¨
@property(strong,
nonatomic) UIWindow * window; |
@property¹Ø¼ü´ÊµÄʹÓÃ
¶ÔÏó strong
»ù±¾±äÁ¿assign
XIB¿Ø¼þ ´úÀí weak
×Ö·û´®ºÍblockʹÓà copy
¶ÔÓÚһЩÈõÒýÓöÔÏóʹÓÃweak
¶ÔÓÚÐèÒª¸³ÖµÄÚ´æ¶ÔÏó copy
hÍ·Îļþ·½·¨Ð´·¨
д·¨Ä£°å
@interface
·½·¨µÄ²ÎÊýÔÚÒ»ÅÅÏÔʾ
·½·¨Ö®¼ä±£ÁôÒ»ÐÐ
µÚÒ»¸ö·½·¨ºÍ@interface±£Áô¿ÕÐÐ
×îºóÒ»¸ö·½·¨ºÍ@end±£Áô¿ÕÐÐ
½¨ÒéµÄд·¨
@interface Text
: NSObject
- (void)testFunction;
@end |
´íÎóд·¨
@interface Text
: NSObject
- (void)testFunction;
@end |
ÉùÃ÷constµÄ×Ö·û´®
¿ªÍ·ÓÃk±êʶ
ÍÆ¼ök+Ä£°åÃû×ÖÊ××Öĸ´óд+×÷ÓÃÃû³Æ ·ÀÖ¹ºÍÆäËûµÄÖØ¸´
±ÈÈç:CartViewModelÀàÐèÒªÉùÃ÷¸üйºÎï³µÁбíµÄ֪ͨ
kCVMNoticationUpdateCartList
Èç¹ûÊÇÉùÃ÷CellµÄÖØÓÃ×Ö·û
k+cellµÄÃû³Æ+identifier
±ÈÈç: GBHomeItemTableViewCellµÄ±êʶ·û
kGBHomeItemTableViewCellIdentifier
ConstÉùÃ÷×Ö·û´®Î»ÖÃ
Èç¹ûÊÇÐèÒªÉùÃ÷ÔÚhÀïÃæÈÃÆäËûµÄÀàÓõ½ÐèÒªÔÚhÉùÃ÷mʵÏÖ
ÉùÃ÷
UIKIT_EXTERN
NSString *const kNoticationUpdateCartList; |
ʵÏÖ
NSString *const
kNoticationUpdateCartList = @"kNoticationUpdateCartList"; |
¶ÔÓÚÈç¹ûµ¼ÈëÊÇUIKitÀà¾ÍʹÓÃUIKIT_EXTERN Èç¹ûÊÇFounctionʹÓùؼü´ÊFOUNDATION_EXTERN
Èç¹ûÖ»ÔÚ±¾ÀàʹÓÃÖ»ÓÃдʵÏÖ ²»ÓÃдÉùÃ÷¡£
·½·¨¾¡Á¿¿ØÖÆ×î¶àÎåÊ®ÐÐ
Ò»¸ö·½·¨ÄÚ²¿×î¶àÎåÊ®ÐÐ Èç¹û³¬¹ý¾Í¾«¼ò´úÂë ¾Í·Ö¿ª·½·¨Ð´
·½±ãÖ®ºó½øÐÐÈÈÐÞ¸´ ´úÂëÖØ¹¹
×¢ÊÍÒ»¶¨ÒªÐ´
×Ô¼º¹ÜÀíµÄÀàÒ»¶¨×¢ÊÍÊôÐÔÓÃ; ·½·¨µÄÓÃ; ²ÎÊýµÄ˵Ã÷
ÊôÐÔÈç¹ûÉèÖÃĬÈÏÖµ Ò»¶¨×¢Ã÷ĬÈÏÖµÊÇʲô
Èç¹û·½·¨ÄÚ²¿´æÔÚÂß¼ÅÐ¶Ï ·½·¨Ìø×ª Ò»¶¨×¢ÊÍÅжÏÓ÷¨ ·½·¨Ìø×ªÓ÷¨
³ýÁ˳õʼ»¯²Ù×÷
ÆäËûÉùÃ÷±äÁ¿ ¸³Öµ ÅÐ¶Ï Ó¦¸Ã×¢Ã÷×¢ÊÍÓÃ;
×¢Ê͵Äд·¨
ClassÀà×¢ÊÍ
/**
¶©µ¥µÄcell
*/
@interface OrdersCell : UITableViewCell |
propertyÊôÐÔµÄ×¢ÊÍ
/**
ÏÔʾ״̬
*/
@property (nonatomic,strong) UILabel *statusLabel; |
·½·¨µÄ×¢ÊÍ
Èç¹ûÓзµ»ØÖµ Çë¼ÓÉÏreturn
/**
ÏÔʾµ¹¼ÆÊ±Îı¾
@param timerLabel µ¹¼ÆÊ±Îı¾
@param countTime Ê£Óàʱ¼ä
*/
-(void)timerLabel:(MZTimerLabel*)
timerLabel finshedCountDownTimerWithTime:
(NSTimeInterval)countTime { |
¾Ö²¿±äÁ¿ºÍÈ«¾Ö±äÁ¿×¢ÊÍ
BOOL _isOfflinePay;
// ÊÇ·ñÊÇÀëÏßÖ§¸¶ |
Block×¢ÊÍ
/*!
ÑéÖ¤ÊäÈëµÄÊÇ·ñÕýÈ·
@param inputText ÊäÈëµÄÎı¾
@return Èç¹û·µ»ØÖµ´æÔھʹú±íÑé֤ʧ°Ü ·ñÔò¾Í´ú±í³É¹¦
*/
typedef NSString * (^ATFVValidateInputCorrectComplete)(NSString
*inputText); |
NSUMµÄ×¢ÊÍ
/*!
µ±Ç°ÊäÈë¿òµÄ״̬
- ATFVEditStateNormal: ĬÈÏ »¹Ã»ÓÐÊäÈëÈκεÄÎÄ×Ö
- ATFVEditStateEditing: ÕýÔÚ½øÐÐÊäÈë
- ATFVEditStateEdited: ÊäÈëÍê±Ï
- ATFVEditStateEditedError: ÊäÈëÍê±Ï´íÎó
- ATFVEditStateNoEdit: Ö»ÔÊÐí±à¼
*/
typedef NS_ENUM(NSUInteger, ATFVEditState) {
ATFVEditStateNormal,
ATFVEditStateEditing,
ATFVEditStateEdited,
ATFVEditStateEditedError,
// ATFVEditStateNoEdit
}; |
²»ÔÊÐíÍâ½ÓÐ޸ĵÄÊôÐÔÒªÉèÖÃreadonly
´ó¼ÒƽʱÉèÖÃÊôÐÔĬÈÏÊǿɶÁ¿Éд µ«ÊÇÕâÑùÈÝÒ×¶ÔÓÚ±ðÈËÔì³ÉÎó½â ÒÔΪ¿ÉÒÔ¸³Öµ
¶ÔÓÚÖ»ÄÜ»ñÈ¡µÄÊôÐÔ Ò»¶¨Ð´readonly
ÕýÈ·µÄд·¨
@property (nonatomic,
copy, readonly) NSString *name; |
´íÎóµÄд·¨
@property (nonatomic,
copy) NSString *name; |
Í·ÎļþÒýÈëµÄÆäËûÀà ҪʹÓÃ@class
Í·ÎļþÒýÈëµÄÀàʹÓÃ@classÉùÃ÷²»ÊµÓÃ#importÒýÈë
¿ÉÒÔ·ÀÖ¹»¥ÏàÒýÈë ±àÒëʧ°Ü ²»ÈÝÒײéÕÒµÄBUG
Ôì³ÉµÄȱµã
mÎļþ»¹Òª#import ÆäËûÀàµ÷ÓÃÕâ¸öÀàÊôÐÔÒ²Òª#import¶ÔÓ¦µÄÀà
×ÛºÏÀ´ËµÄþÔ¸×Ô¼º¶à²Ù×÷ Ò²Òª·ÀÖ¹ÕâÖÖÑ»·ÒýÈëµÄBUGµÄ³öÏÖ
½¨ÒéµÄд·¨
@class GBHomeViewController; |
²»½¨Òéд·¨
#import "GBHomeViewController.h" |
pragma markµÄʹÓÃ
¶ÔÓÚÊôÐԵIJ»Í¬×÷Óà ±ÈÈçÉèÖÃÑÕÉ«µÄ ÉèÖÃ×ÖÌåµÄ ÉèÖÃÆäËûÑùʽ µÄ¿ÉÒÔ½øÐзÖ×é
¶ÔÓÚ·½·¨µÄ×÷Ó÷ÖÀà ±ÈÈçÌí¼Ó¹¦ÄÜ É¾³ý¹¦ÄܵÄ
¶ÔÓÚÆäËûµÄ´úÀí·½·¨ Get Set·½·¨ Init³õʼ»¯·½·¨
½¨ÒéµÄд·¨
#pragma mark
- Init
#pragma mark - Request
#pragma mark - Delegate
#pragma mark - DataSource
#pragma mark - Setter
#pragma mark - Getter |
BOOLÀàÐÍÊôÐÔµÄÉùÃ÷
ÊôÐÔset²»Òª´øis getÒª´øis
½¨Òéд·¨
@property(nonatomic,
assign, getter=isUserLogin) BOOL userLogin; |
²»½¨Òéд·¨
@property(nonatomic,
assign) BOOL userLogin; |
·½·¨ÃüÃûµÄ¹æ·¶
²»ÄÜÓÃinit set ¿ªÍ·½øÐÐÃüÃû
Èç¹û²»ÊÇд³õʼ»¯·½·¨²»ÒªÓÃinit½øÐпªÍ·
Èç¹û²»ÊÇÊôÐÔµÄset·½·¨²»ÒªÓÃset×÷Ϊ·½·¨µÄǰ׺
{}µÄд·¨
½¨ÒéµÄд·¨
if(YES) {
doing something
} |
²»½¨ÒéµÄд·¨
if(YES)
{
doing something
} |
¼ÆËã·ûºÅÁ½±ßÒªÓпոñ
±ÈÈç + - * / =µÈÔËËã·û×óÓÒÓпոñ
½¨ÒéµÄд·¨
²»½¨ÒéµÄд·¨
¿Ø¼þÃüÃûµÄ¹æ·¶
¶ÔÓÚÃüÃûÒ»¶¨²»Òª¼òд ÄÇÆªºÜ³¤µÄµ¥´Ê µ«ÊÇһЩµ¥´Ê¾ÍÊǼòдµÄ³ýÍâ ±ÈÈçWTO
RMB
UILabel½áβ¼ÓÉÏLabel;
UIImageView½áβ¼ÇÉÏImageView
µÈµÈÈÃÆäËûµÄ±à³ÌÈËÔ±¿´Ãû×Ö¾ÍÖªµÀ±äÁ¿µÄÓ÷¨ ºÍÊôÓÚʲô¿Ø¼þ
½¨ÒéµÄд·¨
@property (nonatomic,
strong) UILabel *userNameLabel; |
²»½¨ÒéµÄд·¨
@property (nonatomic,
strong) UILabel *name; |
ifÅжÏÀïÃæµÄÌõ¼þÒªÌáÈ¡³öÀ´
¶ÔÓÚifÀïÃæºÜ¶àµÄÅжÏÌõ¼þ ÒªÌáÈ¡³öÀ´ ·½±ãÖ®ºó½øÐжϵã²âÊÔ
½¨ÒéµÄд·¨
BOOL isTrue =
5 > 3;
if(isTrue) {
} |
²»½¨ÒéµÄд·¨
enumµÄ¶¨Òå
¶ÔÓÚ¹éÊôËùÔÚµÄenum ҪдÔÚ¶ÔÓ¦µÄÀà
ÎÒÃÇÏÖÔÚ¾ÍÈ«²¿enum·ÅÔÚÒ»¸öÎļþ ¾õµÃºÍÆ»¹ûµÄ±àÂë¹æ·¶Î¥±³ ²¢ÇÒ·ÖÀë´úÂëÓеãÂé·³
ʹÓÃNS_ENUM½øÐж¨Òå
½¨ÒéµÄд·¨
typedef NS_ENUM(NSUInteger,
GBAppRunDeveloperMode) {
GBAppRunDeveloperModeDebug,
GBAppRunDeveloperModePreRelease,
GBAppRunDeveloperModeRelease
}; |
²»½¨ÒéµÄд·¨
typedef enum
{
GBAppRunDeveloperModeDebug,
GBAppRunDeveloperModePreRelease,
GBAppRunDeveloperModeRelease
}GBAppRunDeveloperMode; |
¶ÔÓÚ³õʼ»¯Ò»¶¨ÒªÊ¹ÓÃÀà¶ÔÓ¦µÄ³õʼ»¯·½·¨
±ÈÈçUIViewµÄ¶ÔÓ¦³õʼ»¯·½·¨Îª
- (instancetype)initWithFrame:(CGRect)frame |
UIViewController¶ÔÓ¦µÄΪ
- (instancetype)initWithNibName:(nullable
NSString *)
nibNameOrNil bundle:(nullable NSBundle *)n |
·ÀÖ¹³õʼ»¯ÓÃinit newµÈû¾¹ýϵͳ½øÐÐÉèÖÃһЩĬÈϵÄÊôÐÔ Ôì³Ébug
¶ÔÓÚÉùÃ÷NSString constÒª¶ÔÊÊÓ¦¶ÔÓ¦µÄÄ£¿é
±ÈÈçϵͳµÄ NSNotificationName
typedef NSString
*NSNotificationName NS_EXTENSIBLE_STRING_ENUM; |
½¨ÒéµÄд·¨
typedef NSString
*NSStringConfigProjectName;
FOUNDATION_EXPORT
NSStringConfigProjectName
const kConfigProjectPluginDebugBaseUrlString; |
²»½¨ÒéµÄд·¨
FOUNDATION_EXPORT
NSString
*const kConfigProjectPluginDebugBaseUrlString; |
¶ÔÓÚ#defineºêÃüÃû
µ¥´ÊÈ«²¿µÄ´óд µ¥´ÊÖ®¼äÓÃ_·Ö¸î
½¨ÒéµÄд·¨
#define NS_AVAILABLE_IOS(_ios)
CF_AVAILABLE_IOS(_ios) |
²»½¨ÒéµÄд·¨
#define NSAvailableIos(_ios)
CF_AVAILABLE_IOS(_ios) |
¶ÔÏóµ÷Ó÷½·¨ÒªÁô¿Õ¸ñ
½¨ÒéµÄд·¨
[[UIWindow alloc]
initWithFrame:[UIScreen mainScreen].bounds] |
²»½¨ÒéµÄд·¨
[[UIWindow alloc]initWithFrame:[UIScreen
mainScreen].bounds] |
¶ÔÓÚÖ»ÔÚmÄÚ²¿ÉùÃ÷µÄconst ÐèÒªÌí¼Óstatic
Õâ¸öÎÒ¾õµÃ¿ÉÒÔ²»¼Ó µ«ÊÇÎÞ·¨¿´µ½Æ»¹ûµÄʵÏÖ ËùÒÔ²»ÖªµÀÆ»¹ûµÄ¹æ·¶ÔõôдµÄ
½¨Òéд·¨
static NSStringInitCheckManger
const KGoogleServerTestKey = @"" |
²»½¨ÒéµÄд·¨
NSStringInitCheckManger
const KGoogleServerTestKey = @"" |
¶ÔÓÚ¾Ö²¿µÄ±äÁ¿¾¡Á¿µÄ³õʼ»¯
¾Ö²¿µÄ±äÁ¿Òª³õʼ»¯ ÊôÐÔÓÐĬÈϵÄÖµ ËùÒÔÎÒÃDz»±ØÐë¶ÔÓÚÊôÐÔ½øÐгõʼ»¯
ÎÒ֮ǰÓöµ½µÄÒ»¸öBUG¾ÍÊÇintÀàÐÍûÓгõʼ»¯¸øÎÒĬÈÏNanÔì³É±ÀÀ£
½¨ÒéµÄд·¨
²»½¨ÒéµÄд·¨
¶ÔÓÚһЩ¶ÔÏóÅжÏÊÇ·ñ¸³Öµ¿ÉÒÔ²»½øÐгõʼ»¯ µ«ÊǶÔÓÚÒ»¶¨²»»áΪnilÒª½øÐгõʼ»¯
±äÁ¿ÃûµÄ¹æ·¶
Ò»¶¨ÒªÊ¹ÓÃÍÕ·åµÄÃüÃû
½¨ÒéµÄд·¨
UNUserNotificationCenter
*unCenter =
[UNUserNotificationCenter currentNotificationCenter]; |
²»½¨ÒéµÄд·¨
UNUserNotificationCenter *uncenter =
[UNUserNotificationCenter currentNotificationCenter]; |
¶ÔÓÚÊôÐԵĸ³Öµ
²»ÒªÖ±½Óµ÷ÓÃset·½·¨
½¨ÒéµÄд·¨
unCenter.delegate
= self; |
²»½¨ÒéµÄд·¨
[unCenter setDelegate:self]; |
¶ÔÓÚNS_OPTIONSÀàÐͶà¸öÖµÓÃ|Á¬½Ó²»ÄÜÓÃ+
½¨ÒéµÄд·¨
UNAuthorizationOptionAlert
| UNAuthorizationOptionBadge
| UNAuthorizationOptionSound |
²»½¨ÒéµÄд·¨
UNAuthorizationOptionAlert+UNAuthorizationOptionBadge
+UNAuthorizationOptionSound |
blockµÄÃüÃû¹æ·¶
֮ǰÑо¿¹ýºÜ¶àµÄµÚÈý·½µÄÃüÃû ¶ÔÓÚÆ»¹û¹Ù·½µÄûÕÒµ½
ÓÐCallBack½áβ Complete½áβ Block½áβ »¹ÓÐCompletionHandle½áβµÄ
ÎÒ¿´µ½Æ»¹ûºÜ¶àµÄ½áβ¶¼ÊÇÓÃCompletionHandle½áβ
´ó²¿·ÖÃüÃûÊÇBlockÎÒÃǰ´ÕÕBlockÃüÃû
½¨ÒéµÄд·¨
typedef void(DidUpdateViewCompletionHandle)(void) |
´íÎóд·¨
typedef void(DidUpdateViewCallBack) |
ʹÓÃNSUserDefaultsÒªÏÈ´´½¨
ÒòΪÎÒÃÇÓõ½NSUserDefaultsÎÞ·ÇÊDZ£´æºÍ¶ÁÈ¡ ÊÂÏȵĴ´½¨Ò»¸ö¶ÔÏó
¿ÉÒÔ¾«¼ò´úÂë
µ±Ö´Ðз½·¨ºÜ¶à ÓñäÁ¿Ìæ»»
½¨ÒéµÄд·¨
NSUserDefaults
*userDefault = [NSUserDefaults standardUserDefaults];
[userDefault setDouble:CFAbsoluteTimeGetCurrent()
forKey:@"AppStartTime"]; |
²»½¨ÒéµÄд·¨
[[NSUserDefaults
standardUserDefaults]
setDouble:CFAbsoluteTimeGetCurrent() forKey:@"AppStartTime |
¾¡Á¿ÉÙÔÚinitialize load·½·¨×öһЩ³õʼ»¯µÄÊÂÇé
Ó°Ïì³ÌÐòµÄÆô¶¯
½¨ÒéµÄ×ö·¨
- (void)viewDidLoad
{
[super viewDidLoad];
[[UITabBarItem appearance]
setTitleTextAttributes:@
{NSForegroundColorAttributeName :
GBCOLOR(153, 153, 153, 1.0)} forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:
@{NSForegroundColorAttributeName :
GBCOLOR(255, 129, 55, 1.0)} forState:UIControlStateSelected];
} |
²»½¨ÒéµÄ×ö·¨
+ (void)initialize
{
[[UITabBarItem appearance]
setTitleTextAttributes:@{NSForegroundColorAttributeName
:
GBCOLOR(153, 153, 153, 1.0)} forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:
@{NSForegroundColorAttributeName :
GBCOLOR(255, 129, 55, 1.0)} forState:UIControlStateSelected];
} |
֪ͨµÄÒÆ³ý
֪ͨÔÚdeallocҪʹÓÃÒÆ³ý¶ÔÏó¼àÌýµÄ·½·¨
½¨ÒéµÄд·¨
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
} |
²»½¨ÒéµÄд·¨
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:name1 object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:name2 object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:name3 object:nil];
} |
Åжϲ»Òª·ÅÔÚÒ»ÐÐ
ÅжϷÅÔÚÒ»ÐÐÒ²ÊÇ¿ÉÒ﵀ µ«ÊÇÎÒÃÇ»¹ÊÇÒªÇóÕý¹æÒ»Ð© ±Ï¾¹×¢Ã÷AppleµÄgoto
BUG
½¨ÒéµÄд·¨
if (!self.startPagesListInfo)
{
return ;
} |
²»½¨ÒéµÄд·¨
if (!self.startPagesListInfo)
return ; |
¶ÔÓÚÎÒÃÇȡֵºÍ´æÖµµÄkeyÒª¶¨ÒåÒ»ÏÂ
¶¨ÒåÒ»ÏÂkey ·½±ãÎÒÃÇʹÓà ²¢ÇÒ·½±ãÖ®ºó¸ÄÃû×Ö
½¨ÒéµÄд·¨
NSString startLoadString
= @"startLoad";
NSUserDefaults *userDefault = [NSUserDefaults
standardUserDefaults];
[userDefault objectForKey:startLoadString]
[userDefault setObject:@() forKey:startLoadString] |
²»½¨ÒéµÄд·¨
NSUserDefaults
*userDefault = [NSUserDefaults standardUserDefaults];
[userDefault objectForKey:@"startLoad"]
[userDefault setObject:@() forKey:@"startLoad"] |
·½·¨µÄ²ÎÊýÁ¬½Ó²»ÄÜÓпոñ
½¨ÒéµÄд·¨
- (BOOL)judgeStartLoadPageInTimeCurrentWithModel:(StartPageModel
*)obj |
²»½¨ÒéµÄд·¨
- (BOOL)judgeStartLoadPageInTimeCurrentWithModel
: (StartPageModel *)obj; |
¶ÔÓÚblockµÄÑ»·ÒýÓÃʹÓÃweakify ºÍstrongify
½¨ÒéµÄд·¨
@weakify(self);
[@[] enumerateObjectsUsingBlock:
^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull
stop) {
@strongify(self);
}]; |
²»½¨ÒéµÄд·¨
__weak typeof(self)
weakSelf = self;
[@[] enumerateObjectsUsingBlock:
^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull
stop) {
__strong typeof(weakSelf) strongSelf = weakSelf;
}]; |
²¼¾ÖºÍÉèÖÃÔ¼ÊøµÄ·½·¨Ñ¡Ôñ
¿ÉÒÔʵÏÖGBInitViewProtocolÐÒé Ö´ÐжÔÓ¦µÄ·½·¨
½¨ÒéµÄд·¨
#pragma mark
- <GBInitViewProtocol>
- (void)gbInitView {
self.backgroundColor = GBCOLOR_WHITE;
[self addSubview:self.loadImageView];
}
- (void)gbAutoLayoutView {
[self.loadImageView mas_makeConstraints:^(MASConstraintMaker
*make) {
make.edges.mas_equalTo(self).insets(UIEdgeInsetsZero);
}];
} |
ÓÐÀûÓÚÆäËûÈ˺ܷ½±ã²éÕÒµ±Ç°½çÃæ²¼¾ÖºÍÌí¼ÓÊÔͼµÄλÖÃ
ÊôÐÔÒª¾¡Á¿Ê¹ÓÃÀÁ¼ÓÔØ
ÎÒÃÇÒ»¸ö½çÃæÓÐºÜ¶à¿Ø¼þ ÀûÓÃÀÁ¼ÓÔØ¿ÉÒÔÃÀ»¯´úÂë
ËùÓеÄÀÁ¼ÓÔØ·ÅÔÚGetterµÄmarkµÄÏÂÃæ
½¨ÒéµÄд·¨
#pragma mark
- getter
- (UIImageView *)loadImageView {
if (!_loadImageView) {
_loadImageView = [[UIImageView alloc] init];
_loadImageView.image = [self imageWithScreen];
_loadImageView.contentMode = UIViewContentModeScaleAspectFill;
_loadImageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:
@selector(loadImageTouchAction)];
[_loadImageView addGestureRecognizer:tap];
}
return _loadImageView;
} |
ÍÆ¼öµÄ½çÃæ¿ò¼Ü
ËùÓнçÃæµÄ¿Ø¼þÔªËØ¶ÀÁ¢µ½ÁíÍâµÄUIView
UIViewControllerÖ»¸ºÔðÌø×ª½çÃæ
н¨UIView¸ºÔð½çÃæµÄÏÔʾ
VIewModel¸ºÔðÊý¾ÝµÄÇëÇóºÍ½âÎö
APi¸ºÔðÇëÇó
model¸ºÔðºǫ́Êý¾Ý½âÎö
other ¸ºÔðÑùʽºÍÆäËû´¦Àí
¶àʹÓÃ×ÖÃæÁ¿
×Ö·û´® @¡±¡±
NSString *string
= @"string"; |
NSNumber @()
×Öµä @{}
NSDictionary
*dictionary = @{
@"name":@"123"
}; |
Êý×é @[]
NSArray *array
= @[
@"321231",
@"123"
]; |
×ÖµäºÍÊý×éµÄȡֵºÍ´æÖµ
¶àÓÃÀàÐͳ£Á¿ ÉÙÓÃ#define
½¨ÒéµÄд·¨
static const
NSTimeInterval kAnimationDuration = 0.3; |
²»½¨ÒéµÄд·¨
#define ANIMATION_DURATION
0.3 |
¶ÔÓÚһЩ״̬ Ñ¡ÏîµÄʹÓÃö¾Ù
¾¡Á¿ÉÙÓøù¾ÝÊý×ÖÅжÏ״̬ÉÙÓÃ×Ö·û´® Êý×ÖÅжÏ״̬
½¨ÒéµÄд·¨
typedef NS_ENUM(NSUInteger,
HomeViewState) {
HomeViewStateNoData,
HomeViewStateFailure,
HomeViewStateItemList,
HomeViewStateBannerList
};
if(state == HomeViewStateNoData){
// ÏÔʾûÊý¾Ý
}else if(state == HomeViewStateFailure) {
// ÏÔʾÇëÇó´íÎó
}else if(state == HomeViewStateItemList) {
// ÏÔʾÉÌÆ·µÄÁбí
}else if(state == HomeViewStateBannerList) {
// ÏÔʾbannerÁбí
} |
²»½¨ÒéµÄд·¨
if(state == 0){
// ÏÔʾûÊý¾Ý
}else if(state == 1) {
// ÏÔʾÇëÇó´íÎó
}else if(state == 2) {
// ÏÔʾÉÌÆ·µÄÁбí
}else if(state == 3) {
// ÏÔʾbannerÁбí
} |
¶àʹÓÃÀà×å
±ÈÈçÎÒÃÇÐèÒª´´½¨Ò»¸öÀà Óжà¸öÑùʽ
typedef NS_ENUM(NSUInteger,
ZHCustomViewStyle) {
ZHCustomViewStyleRed,
ZHCustomViewStyleWhite
};
@interface ZHCustomView : UIView
+ (instancetype)customWithStyle:(ZHCustomViewStyle)style;
@end
#import "ZHCustomView.h"
#import "ZHCustomRedView.h"
#import "ZHCustomWhiteView.h"
@implementation ZHCustomView
+ (instancetype)customWithStyle:(ZHCustomViewStyle)style
{
switch (style) {
case ZHCustomViewStyleRed: {
return [[ZHCustomRedView alloc] initWithFrame:CGRectZero];
}
break;
case ZHCustomViewStyleWhite:{
return [[ZHCustomWhiteView alloc] initWithFrame:CGRectZero];
}
break;
default:
break;
}
}
@end |
ZHCustomRedView
#import "ZHCustomView.h"
@interface ZHCustomRedView : ZHCustomView
@end
#import "ZHCustomRedView.h"
@implementation ZHCustomRedView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor redColor];
}
return self;
}
@end |
ZHCustomWhiteView
#import "ZHCustomView.h"
@interface ZHCustomWhiteView : ZHCustomView
@end
#import "ZHCustomWhiteView.h"
@implementation ZHCustomWhiteView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor whiteColor];
}
return self;
}
@end |
ÀàÃû¼ÓÉÏǰ׺±ÜÃâ³åÍ»
ÒòΪÍŶӵĺÏ×÷ ¿ÉÄÜ»á³öÏÖ´ó¼ÒÏëµ½Ò»ÑùµÄÃû×Ö»òÕßÌí¼ÓµÚÈý·½¿âÒýÈëºÍµÚÈý·½¿âÃû×ÖÒ»Ñù
¾¡Á¿¼ÓÉÏǰ׺¡£
Èç¹ûÖ»Õë¶Ô¹¤³Ì¾ÍʹÓù¤³ÌµÄËõд
±ÈÈç×Ô¼º¸öÈ˵ĵÚÈý·½¿â¾Í¼ÓÉÏ×Ô¼ºÃû×Ö»òÕßêdzƵÄËõд
½¨ÒéµÄд·¨
@interface GBHomeViewController
: NSObject |
²»½¨ÒéµÄд·¨
@interface HomeViewController
: NSObject |
ÌṩȫÄܵijõʼ»¯·½·¨
¶ÔÓÚ³õʼ»¯²ÎÊýÓÐºÜ¶à µ«ÊDz»ÊÇÒ»¶¨È«²¿Ê¹ÓõĿÉÒÔÌṩ¶à¸ö³õʼ»¯·½·¨
½¨ÒéµÄд·¨
- (instancetype)initWithFrame:(CGRect)frame;
- (instancetype)initWithPerson:(GBPersonModel
*)person;
- (instancetype)initWithFrame:(CGRect)frame person:(GBPersonModel
*)person; |
²»½¨ÒéµÄд·¨
- (instancetype)initWithFrame:(CGRect)frame
person:(GBPersonModel *)person; |
ʵÏÖDescription·½±ãµ÷ÊÔ
Õâ¸ö²»ÍƼö×Ô¼ºÊÖд ¿ÉÒÔʹÓÃXcode²å¼þ×Ô¶¯Éú³É ÊôÐÔÔ½¶à»á¼ÓÖØÊÖд´úÂëµÄ³¤¶È
¾¡¿ÉÄÜʹÓò»¿É±äµÄ¶ÔÏó
¶ÔÓÚOC´æÔںܶà¿É±äµÄ¶ÔÏó ±ÈÈçNSMutableString NSMutableArray
NSMutableDictionaryµÈµÈ
¶ÔÓÚһЩ²»ÔÊÐí¸Ä±äµÄÖ±½ÓʹÓò»¿É±ä¶ÔÏó
¿ÉÒÔ½ÚÊ¡¶ÔÏó¿ªÖ§ »¹¿ÉÒÔ·ÀÖ¹±ðÈËÐÞ¸ÄÊý¾ÝÔì³Ébug
½¨ÒéµÄд·¨
NSArray *sexList = @[@"ÄÐ",@"Å®"]; |
²»½¨ÒéµÄд·¨
¡¢
NSMutableArray *sexList
= [NSMutableArray arrayWithArray:@[@"ÄÐ",@"Å®"]] |
Èç¹û½¨ÒéµÄʹÓÃBlockºÍ´úÀí
ÎÒ¾õµÃ´úÀí¿ÉÒÔÓÃÔÚд¿Ø¼þÐèÒªÊý¾ÝÔ´¸³Öµ ºÍһЩʼþ»Øµ÷µÄʱºòʹÓÃ
ÎÒ²éÔÄÁËÆ»¹ûµÄblock»ù±¾É϶¼ÊÇÖ´ÐÐÒ»¸öʱ¼ä ÐèÒªÒì²½»Øµ÷¾ÍʹÓÃblock
Èç¹ûûÓÐÖ÷¶¯Ö´Ðж¯×÷ ¶øÊǼàÌýÒì²½µÄ»Øµ÷ ½¨ÒéÓôúÀí
½¨ÒéµÄд·¨
TestName *name = [[TestName
alloc] init];
name.delegate = self;
[name searchText:text completionHandle:^(BOOL
isExit) {
};
- (void)name:(TestName)name resultTextHaveChanged:(NSString
*)text {
} |
²»½¨ÒéµÄд·¨
TestName *name = [[TestName
alloc] init];
[name searchText:text completionHandle:^(BOOL
isExit) {
};
name.resultTextHaveChanged = ^(NSString *text)
{
}; |
¼ÇµÃDealloc¼ÇµÃÊÍ·Å
¼ÇµÃÔÚDeallocÊÍ·Å×¢²áµÄ֪ͨºÍKVOµÄ¼àÌý
²»ÊÍ·ÅÈÝÒ×Ôì³ÉÄÚ´æÊͷűÀÀ£
Ñø³Éϰ¹ß°Ñ°´ÕÕ·½·¨¹¦Äܵ½·ÖÀàÀïÃæ
¶ÔÓÚһЩÓа´ÕÕ¹¦ÄÜÀàÐ͵ķ½·¨»®·ÖÔÚÒ»¸ö·ÖÀàÀïÃæ ·ÖÀàºÍ֮ǰÀàдÔÚͬһ¸öÎļþ
½¨ÒéµÄд·¨
@interface GBPerson : NSObject
@end
@interface GBPerson (Friend)
// ÅóÓÑ
- (void)addFriend:(GBPenson *)friend;
- (void)deleteFriend:(GBPenson *)friend;
@end
@interface GBPerson (Play)
// ÓéÀÖ
- (void)playSound;
- (void)playGame;
@end |
²»½¨ÒéµÄд·¨
@interface GBPerson : NSObject
// ÅóÓÑ
- (void)addFriend:(GBPenson *)friend;
- (void)deleteFriend:(GBPenson *)friend;
// ÓéÀÖ
- (void)playSound;
- (void)playGame; |
ΪµÚÈý·½ÀàÌí¼Ó·ÖÀàÌí¼Óǰ׺
±ÈÈçΪϵͳUIViewÌí¼Ó·ÖÀàAddµÄÌí¼Óǰ׺
½¨ÒéµÄд·¨
@interface UIView (GB_Add)
- (void)gb_addCustomView:(CustomView *)customView;
@end |
²»½¨ÒéµÄд·¨
@interface UIView (Add)
- (void)addCustomView:(CustomView *)customView;
@end |
¾¡Á¿ÉÙÔÚ·ÖÀàÀïÃæÊ¹ÓÃÊôÐÔ
¼ÙÉèÎÒÃÇ·ÖÀàÓÐÒ»¸öÖ»¶ÁµÄ×Ö¶Î ÎÒÃÇ¿ÉÒÔ²»Ê¹ÓÃÊôÐÔ ¿ÉÒÔʹÓ÷½·¨
½¨ÒéµÄд·¨
@interface UIView (Add)
- (NSArray *)customViews;
@end
@implementation UIView (Add)
- (NSArray *)customViews {
return @[customView1,customView2];
}
@end |
²»½¨ÒéµÄд·¨
@interface UIView (Add)
@property(nonatomic, strong, readonly) NSArray
*customViews;
@end
@implementation UIView (Add)
- (NSArray *)customViews {
return @[customView1,customView2];
}
@end |
·ÇÒªÔÚ×Ô¼ºÀàµÄ·ÖÀàÌí¼Ó¶ÁдµÄÊôÐÔ ¿ÉÒÔÓÃÓï·¨ÌÇ
¿ÉÒÔÀûÓÃÖ÷ÀàµÄ˽ÓбäÁ¿
½¨ÒéµÄд·¨
@interface ZHCustomView
: UIView
@end
@interface ZHCustomView (Add)
@property(nonatomic, copy) NSString *name;
@end |
import "ZHCustomView.h"
@implementation ZHCustomView {
NSString *_name;
}
@end
@implementation ZHCustomView (Add)
- (void)setName:(NSString *)name {
_name = name;
}
- (NSString *)name {
return _name;
}
@end |
²»½¨ÒéµÄд·¨
- (void)setName:(NSString
*)name {
objc_setAssociatedObject(self, "name",
name,
OBJC_ASSOCIATION_COPY_NONATOMIC);
}
- (NSString *)name {
return objc_getAssociatedObject(self, "name");
} |
¶ÔÓÚ¸øµÚÈý·½ºÍϵͳµÄÀà·ÇÒªÌí¼ÓÊôÐÔ ¿ÉÒÔʹÓÃruntime¡£
¶ÔÓÚһЩ×Ô¼º²»È·¶¨µÄ¿ÉÒÔʹÓÃtry catch
¶ÔÓÚ²»ÖªµÀºǫ́·µ»ØÊ²Ã´ÀàÐ굀 ¿ÉÒÔʹÓÃtry catch
½¨ÒéµÄд·¨
int index = 0;
@try {
NSArray *array = obj[@"list"];
index = [array.firstObject intValue];
}
@catch {} |
ÒòΪOCÊÇÔËÐÐʱÓï·¨ ¿ÉÄÜarray²»Ò»¶¨ÊÇNSArrayÀàÐ͵Ä
²»½¨ÒéµÄд·¨
int index = 0;
NSArray *array = obj[@"list"];
if(array.count > 0) {
index = [array.firstObject intValue];
} |
Èç¹ûºǫ́·µ»ØlistΪ×Ö¶Î Õâ¶Î´úÂë¾Í±ÀÀ£ÁË ¿ÉÒÔʹÓÃtry catchÒ²¿ÉÒÔÓÃModel¿â
»òÕß×Ô¼ºÌí¼ÓÅжÏ
ʹÓÃdispatch_onceÀ´´´½¨µ¥Àý
½¨ÒéµÄд·¨
+ (instancetype)sharedInstance
{
static ZHCustomView* instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [ZHCustomView new];
});
return instance;
} |
²»½¨ÒéµÄд·¨
+ (instancetype)sharedInstance
{
static ZHCustomView* instance = nil;
if(!instance) {
instance = [[ZHCustomView alloc] initWithFrame:CGRectZero];
}
return instance;
} |
±ãÀûµÄд·¨
Èç¹ûÖ»ÐèÒª±ãÀûÊý×éºÍ×ÖµäµÄд·¨ÓÃfor in
½¨ÒéµÄд·¨
for(NSString *name in names)
{
//
} |
²»½¨ÒéµÄд·¨
for(int i = 0; i < names.lenght
; i ++) {
NSString *name = names[i];
} |
ÐèÒª±ãÀû×ÖµäºÍÊý×éµÄÄÚÈÝ ²¢ÇÒÐèÒªË÷ÒýÓÃenumerator
½¨ÒéµÄд·¨
[names enumerateObjectsUsingBlock:^
(NSString * _Nonnull name, NSUInteger idx, BOOL
* _Nonnull stop) {
}]; |
²»½¨ÒéµÄд·¨
for(int i = 0; i < names.lenght
; i ++) {
NSString *name = names[i];
} |
Èç¹ûÏë½øÐлº´æÊ¹ÓÃNSCache²»ÒªÊ¹ÓÃNSDictionary½øÐлº´æ
½¨ÒéµÄд·¨
NSCache *cache = [[NSCache
alloc] init];
[cache setObject:object forKey:key]; |
²»½¨ÒéµÄд·¨
NSMutableDictionary *dictionary
= [NSMutableDictionary dictionary];
[dictionary setObject:object forKey:key]; |
ÓÈ´ï±í´ïʽ
ÍÆ¼ö:
if ([myValue isEqual:@42])
{ ... |
²»ÍƼö:
if ([@42 isEqual:myValue])
{ ... |
nil ºÍ BOOL ¼ì²é
ÍÆ¼ö
if(name) {
}
if (isMyFriend) {
} |
²»½¨ÒéµÄд·¨
if(name != nil) {
}
if(isMyFriend == YES) {
} |
»Æ½ð´óµÀ
½¨ÒéµÄд·¨
if(name.lenght <= 0)
{
return;
}
if(![name isEqualToString:@"zhanghang"])
{
return;
}
..... |
²»½¨ÒéµÄд·¨
if(name.lenght > 0)
{
if([name isEqualToString:@"zhanghang"])
{
....
}
} |
¸´Ôӵıí´ïʽ
½¨ÒéµÄд·¨
BOOL nameContainsSwift
= [sessionName containsString:@"Swift"];
BOOL isCurrentYear = [sessionDateCompontents year]
== 2014;
BOOL isSwiftSession = nameContainsSwift &&
isCurrentYear;
if (isSwiftSession) {
// Do something very cool
} |
²»½¨ÒéµÄд·¨
if ([sessionName containsString:@"Swift"]
&&
[sessionDateCompontents year] == 2014) {
// Do something very cool
} |
ÈýÔªÔËËã·û
ÍÆ¼ö:
²»ÍƼö:
result = a > b ? x =
c > d ? c : d : y; |
µ±ÈýÔªÔËËã·ûµÄµÚ¶þ¸ö²ÎÊý£¨if ·ÖÖ§£©·µ»ØºÍÌõ¼þÓï¾äÖÐÒѾ¼ì²éµÄ¶ÔÏóÒ»ÑùµÄ¶ÔÏóµÄʱºò£¬ÏÂÃæµÄ±í´ï·½Ê½¸üÁéÇÉ£º
ÍÆ¼ö:
result = object ? : [self
createObject]; |
²»ÍƼö:
result = object ? object
: [self createObject]; |
´íÎó´¦Àí
ÓÐЩ·½·¨Í¨Í¨¹ý²ÎÊý·µ»Ø error µÄÒýÓã¬Ê¹ÓÃÕâÑùµÄ·½·¨Ê±Ó¦µ±¼ì²é·½·¨µÄ·µ»ØÖµ£¬¶ø·Ç
error µÄÒýÓá£
ÍÆ¼ö:
NSError *error = nil;
if (![self trySomethingWithError:&error])
{
// Handle Error
} |
´ËÍ⣬һЩƻ¹ûµÄ API Ôڳɹ¦µÄÇé¿öÏ»á¶Ô error ²ÎÊý£¨Èç¹ûËü·Ç
NULL£©Ð´ÈëÀ¬»øÖµ£¨garbage values£©£¬ËùÒÔÈç¹û¼ì²é error µÄÖµ¿ÉÄܵ¼Ö´íÎó £¨ÉõÖÁ±ÀÀ££©¡£
Êý×éºÍ×Öµä×îºÃÖ¸¶¨ÔªËصÄÀàÐÍ
½¨ÒéµÄд·¨
NSArray<NSString *>
*names = [NSArray array]; |
²»½¨ÒéµÄд·¨
NSArray *names = [NSArray
array]; |
Êý×éºÍ×ÖµäµÄÔªËØ´¹Ö±Ð´
½¨ÒéµÄд·¨
NSArray *array = @[
@"a",
@"b",
@"b"
];
NSDictionary *dictionary = @{
@"a":@"",
@"b":@"",
@"c":@""
}; |
²»½¨Òéд·¨
NSArray *array = @[@"a",@"b",@"b"];
NSDictionary *dictionary = @{@"a":@"",@"b":@"",@"c":@""} |
|