文章

顯示包含「Objective-C」標籤的文章

[iOS]取得當月有多少天

  - ( NSInteger )getNumberOfDaysInMonth {      NSCalendar  * calendar = [[ NSCalendar   alloc ]  initWithCalendarIdentifier : NSCalendarIdentifierGregorian ];      NSDate  * currentDate = [ NSDate   date ];      NSRange  range = [calendar  rangeOfUnit : NSCalendarUnitDay                                     inUnit :  NSCalendarUnitMonth                                      forDate :currentDate];      return  range. length ; }

下pod instal遇到的錯誤

  下指令 pod install 遇到錯誤 /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems.rb:241:in `bin_path': can't find gem cocoapods (>= 0.a) (Gem::GemNotFoundException) from /usr/local/bin/pod:22:in `<main>' 這邊的解決方式:重裝cocoapods 移除 sudo gem uninstall cocoapods 安裝 gem install cocoapods

iOS的UIIMAGE圖片合成

  - ( UIImage   *)addImage:( UIImage   *)image1 toImage:( UIImage   *)image2 {      UIGraphicsBeginImageContext (image1. size );     [image1 drawInRect: CGRectMake ( 0 ,  0 , image1. size . width , image1. size . height )];     [image2 drawInRect: CGRectMake ( 0 ,  0 , image2. size . width , image2. size . height )];      UIImage  *resultingImage =  UIGraphicsGetImageFromCurrentImageContext ();      UIGraphicsEndImageContext ();      return  resultingImage; }

判斷NSString是否為空

 之前用NSString去取JSON回傳解析值的時後,因為有空藍為使得我在抓取網路圖檔時程式錯誤.後來解決辦法是判斷抓回來所存在的字串是否為空   1 2 3 4 5 6 7 8 9 10 if ([ object isEqual : [ NSNull null ]]) { } else if ([ object isKindOfClass : [ NSNull class ]]) { } else if ( object == nil ){ }

NSString轉NSDictionary

  先轉 NSData再轉 NSDictionary NSString * KBStr =....;     NSData  *data = [KBStr  dataUsingEncoding : NSUTF8StringEncoding ];          NSDictionary  *tmpResposeJson = [ NSJSONSerialization   JSONObjectWithData :data  options : NSJSONReadingAllowFragments   error : nil ];

iOS字串取代replace a character in NSString

 Swift var  deviceTokenString =  NSString (format:  "%@" , deviceToken)         deviceTokenString = deviceTokenString. stringByReplacingOccurrencesOfString ( "<" , withString:  "" ) Object-C [[[deviceToken  description ]                                        stringByReplacingOccurrencesOfString :  @"<"   withString :  @"" ]