├── CorePlotDemo ├── Note01.png ├── Note02.png └── CorePlotDemo │ ├── en.lproj │ ├── InfoPlist.strings │ └── KSViewController.xib │ ├── CorePlotLib │ ├── CorePlotHeaders │ │ ├── CPTTextStylePlatformSpecific.h │ │ ├── CPTDerivedXYGraph.h │ │ ├── CPTTestCase.h │ │ ├── CPTAxisLabelGroup.h │ │ ├── CPTAxisTitle.h │ │ ├── CPTPlatformSpecificDefines.h │ │ ├── CPTExceptions.h │ │ ├── NSDecimalNumberExtensions.h │ │ ├── CPTXYAxisSet.h │ │ ├── CPTPlotGroup.h │ │ ├── CPTGridLineGroup.h │ │ ├── CPTGridLines.h │ │ ├── CPTPathExtensions.h │ │ ├── CPTMutableNumericData.h │ │ ├── CPTMutableShadow.h │ │ ├── CPTXYGraph.h │ │ ├── NSNumberExtensions.h │ │ ├── CPTMutableTextStyle.h │ │ ├── CPTPlotAreaFrame.h │ │ ├── CPTXYAxis.h │ │ ├── CPTAnnotationHostLayer.h │ │ ├── CPTPlatformSpecificFunctions.h │ │ ├── CPTPlotSpaceAnnotation.h │ │ ├── CPTTimeFormatter.h │ │ ├── CPTColorSpace.h │ │ ├── CPTGraphHostingView.h │ │ ├── CPTLayerAnnotation.h │ │ ├── CPTLimitBand.h │ │ ├── CPTAxisSet.h │ │ ├── CPTMutableLineStyle.h │ │ ├── CPTShadow.h │ │ ├── CPTCalendarFormatter.h │ │ ├── CPTTextLayer.h │ │ ├── CPTBorderedLayer.h │ │ ├── CPTMutablePlotRange.h │ │ ├── CPTDataSourceTestCase.h │ │ ├── CPTMutableNumericData+TypeConversion.h │ │ ├── CPTXYPlotSpace.h │ │ ├── CPTNumericData+TypeConversion.h │ │ ├── CPTFill.h │ │ ├── CPTLegendEntry.h │ │ ├── CPTConstraints.h │ │ ├── CPTPlatformSpecificCategories.h │ │ ├── CPTImage.h │ │ ├── CPTAnnotation.h │ │ ├── CPTAxisLabel.h │ │ ├── CPTColor.h │ │ ├── NSCoderExtensions.h │ │ ├── CPTLineStyle.h │ │ ├── CPTTextStyle.h │ │ ├── CPTTheme.h │ │ ├── CPTPlotArea.h │ │ ├── CorePlot-CocoaTouch.h │ │ ├── CPTNumericDataType.h │ │ ├── CPTResponder.h │ │ ├── mainpage.h │ │ ├── CPTPlotRange.h │ │ ├── CPTLineCap.h │ │ ├── CPTPlotSymbol.h │ │ ├── CPTLayer.h │ │ ├── CPTNumericData.h │ │ ├── CPTGradient.h │ │ ├── CPTRangePlot.h │ │ ├── CPTGraph.h │ │ ├── CPTUtilities.h │ │ ├── CPTLegend.h │ │ ├── CPTScatterPlot.h │ │ ├── CPTPieChart.h │ │ ├── CPTDefinitions.h │ │ ├── CPTBarPlot.h │ │ └── CPTPlotSpace.h │ └── libCorePlot-CocoaTouch.a │ ├── Default.png │ ├── Default@2x.png │ ├── Default-568h@2x.png │ ├── KSViewController.h │ ├── CorePlotDemo-Prefix.pch │ ├── main.m │ ├── KSAppDelegate.h │ ├── CorePlotDemo-Info.plist │ └── KSAppDelegate.m ├── SQLiteDemo └── SQLiteDemo │ ├── en.lproj │ ├── InfoPlist.strings │ └── KSViewController_iPad.xib │ ├── Default.png │ ├── Default@2x.png │ ├── Default-568h@2x.png │ ├── SQLiteDemo-Prefix.pch │ ├── main.m │ ├── KSViewController.h │ ├── KSAppDelegate.h │ ├── KSCustomer.h │ ├── KSCustomer.m │ ├── KSDefines.h │ ├── SQLiteDemo-Info.plist │ └── KSAppDelegate.m ├── KSNetworkDemo ├── KSNetworkDemo │ ├── en.lproj │ │ ├── InfoPlist.strings │ │ └── MainStoryboard.storyboard │ ├── Default.png │ ├── Default@2x.png │ ├── Default-568h@2x.png │ ├── KSAppDelegate.h │ ├── KSNetworkDemo-Prefix.pch │ ├── KSViewController.h │ ├── main.m │ ├── NSStream+StreamsToHost.h │ ├── KSSocketViewController.h │ ├── KSCFNetworkViewController.h │ ├── KSNSStreamViewController.h │ ├── KSNetworkDemo-Info.plist │ ├── NSStream+StreamsToHost.m │ ├── KSAppDelegate.m │ ├── KSViewController.m │ ├── KSSocketViewController.m │ └── KSNSStreamViewController.m └── Screenshots_SocketDemo.png ├── KSUtilitiesDemo └── KSUtilitiesDemo │ ├── en.lproj │ ├── InfoPlist.strings │ └── MainStoryboard.storyboard │ ├── Default.png │ ├── Default@2x.png │ ├── Default-568h@2x.png │ ├── KSAppDelegate.h │ ├── KSUtilitiesDemo-Prefix.pch │ ├── Controllers │ ├── KSViewController.h │ └── KSViewController.m │ ├── main.m │ ├── KSUtilities │ ├── KSErrorHandler.h │ ├── KSImageCache.h │ ├── KSExceptionHandler.h │ ├── KSPathUtil.h │ ├── KSDefines.h │ ├── KSPathUtil.m │ ├── KSLog.h │ ├── KSErrorHandler.m │ ├── KSImageCache.m │ └── KSExceptionHandler.m │ ├── KSUtilitiesDemo-Info.plist │ └── KSAppDelegate.m ├── .gitignore └── README.md /CorePlotDemo/Note01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kesalin/iOSSnippet/HEAD/CorePlotDemo/Note01.png -------------------------------------------------------------------------------- /CorePlotDemo/Note02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kesalin/iOSSnippet/HEAD/CorePlotDemo/Note02.png -------------------------------------------------------------------------------- /SQLiteDemo/SQLiteDemo/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTTextStylePlatformSpecific.h: -------------------------------------------------------------------------------- 1 | #import 2 | -------------------------------------------------------------------------------- /SQLiteDemo/SQLiteDemo/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kesalin/iOSSnippet/HEAD/SQLiteDemo/SQLiteDemo/Default.png -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kesalin/iOSSnippet/HEAD/CorePlotDemo/CorePlotDemo/Default.png -------------------------------------------------------------------------------- /SQLiteDemo/SQLiteDemo/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kesalin/iOSSnippet/HEAD/SQLiteDemo/SQLiteDemo/Default@2x.png -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kesalin/iOSSnippet/HEAD/KSNetworkDemo/KSNetworkDemo/Default.png -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kesalin/iOSSnippet/HEAD/CorePlotDemo/CorePlotDemo/Default@2x.png -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kesalin/iOSSnippet/HEAD/KSNetworkDemo/KSNetworkDemo/Default@2x.png -------------------------------------------------------------------------------- /KSNetworkDemo/Screenshots_SocketDemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kesalin/iOSSnippet/HEAD/KSNetworkDemo/Screenshots_SocketDemo.png -------------------------------------------------------------------------------- /SQLiteDemo/SQLiteDemo/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kesalin/iOSSnippet/HEAD/SQLiteDemo/SQLiteDemo/Default-568h@2x.png -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kesalin/iOSSnippet/HEAD/KSUtilitiesDemo/KSUtilitiesDemo/Default.png -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kesalin/iOSSnippet/HEAD/CorePlotDemo/CorePlotDemo/Default-568h@2x.png -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kesalin/iOSSnippet/HEAD/KSNetworkDemo/KSNetworkDemo/Default-568h@2x.png -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kesalin/iOSSnippet/HEAD/KSUtilitiesDemo/KSUtilitiesDemo/Default@2x.png -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kesalin/iOSSnippet/HEAD/KSUtilitiesDemo/KSUtilitiesDemo/Default-568h@2x.png -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTDerivedXYGraph.h: -------------------------------------------------------------------------------- 1 | #import "CPTXYGraph.h" 2 | 3 | @interface CPTDerivedXYGraph : CPTXYGraph { 4 | } 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/libCorePlot-CocoaTouch.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kesalin/iOSSnippet/HEAD/CorePlotDemo/CorePlotDemo/CorePlotLib/libCorePlot-CocoaTouch.a -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTTestCase.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface CPTTestCase : SenTestCase { 4 | } 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTAxisLabelGroup.h: -------------------------------------------------------------------------------- 1 | #import "CPTLayer.h" 2 | #import 3 | 4 | @interface CPTAxisLabelGroup : CPTLayer { 5 | } 6 | 7 | @end 8 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTAxisTitle.h: -------------------------------------------------------------------------------- 1 | #import "CPTAxisLabel.h" 2 | #import 3 | 4 | @interface CPTAxisTitle : CPTAxisLabel { 5 | } 6 | 7 | @end 8 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTPlatformSpecificDefines.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | typedef UIImage CPTNativeImage; ///< Platform-native image format. 5 | typedef UIEvent CPTNativeEvent; ///< Platform-native OS event. 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | *.xcworkspace 13 | !default.xcworkspace 14 | xcuserdata 15 | profile 16 | *.moved-aside 17 | DerivedData 18 | .idea/ 19 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTExceptions.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | /// @file 4 | 5 | /// @name Custom Exception Identifiers 6 | /// @{ 7 | extern NSString *const CPTException; 8 | extern NSString *const CPTDataException; 9 | extern NSString *const CPTNumericDataException; 10 | /// @} 11 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/NSDecimalNumberExtensions.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | /** @category NSDecimalNumber(CPTExtensions) 5 | * @brief Core Plot extensions to NSDecimalNumber. 6 | **/ 7 | @interface NSDecimalNumber(CPTExtensions) 8 | 9 | @end 10 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTXYAxisSet.h: -------------------------------------------------------------------------------- 1 | #import "CPTAxisSet.h" 2 | #import 3 | 4 | @class CPTXYAxis; 5 | 6 | @interface CPTXYAxisSet : CPTAxisSet { 7 | } 8 | 9 | @property (nonatomic, readonly, retain) CPTXYAxis *xAxis; 10 | @property (nonatomic, readonly, retain) CPTXYAxis *yAxis; 11 | 12 | @end 13 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTPlotGroup.h: -------------------------------------------------------------------------------- 1 | #import "CPTLayer.h" 2 | 3 | @class CPTPlot; 4 | 5 | @interface CPTPlotGroup : CPTLayer { 6 | } 7 | 8 | /// @name Adding and Removing Plots 9 | /// @{ 10 | -(void)addPlot:(CPTPlot *)plot; 11 | -(void)removePlot:(CPTPlot *)plot; 12 | -(void)insertPlot:(CPTPlot *)plot atIndex:(NSUInteger)idx; 13 | /// @} 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/KSViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSViewController.h 3 | // CorePlotDemo 4 | // 5 | // Created by kesalin on 2/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CorePlot-CocoaTouch.h" 11 | 12 | @interface KSViewController : UIViewController 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/KSAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSAppDelegate.h 3 | // KSNetworkDemo 4 | // 5 | // Created by kesalin on 13/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface KSAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/KSAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSAppDelegate.h 3 | // KSUtilitiesDemo 4 | // 5 | // Created by kesalin on 6/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface KSAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTGridLineGroup.h: -------------------------------------------------------------------------------- 1 | #import "CPTLayer.h" 2 | 3 | @class CPTPlotArea; 4 | 5 | @interface CPTGridLineGroup : CPTLayer { 6 | @private 7 | __cpt_weak CPTPlotArea *plotArea; 8 | BOOL major; 9 | } 10 | 11 | @property (nonatomic, readwrite, assign) __cpt_weak CPTPlotArea *plotArea; 12 | @property (nonatomic, readwrite) BOOL major; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTGridLines.h: -------------------------------------------------------------------------------- 1 | #import "CPTLayer.h" 2 | #import 3 | 4 | @class CPTAxis; 5 | 6 | @interface CPTGridLines : CPTLayer { 7 | @private 8 | __cpt_weak CPTAxis *axis; 9 | BOOL major; 10 | } 11 | 12 | @property (nonatomic, readwrite, assign) __cpt_weak CPTAxis *axis; 13 | @property (nonatomic, readwrite) BOOL major; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /SQLiteDemo/SQLiteDemo/SQLiteDemo-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'SQLiteDemo' target in the 'SQLiteDemo' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_4_0 8 | #warning "This project uses features only available in iOS SDK 4.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTPathExtensions.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | /// @file 5 | 6 | #if __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | CGPathRef CreateRoundedRectPath(CGRect rect, CGFloat cornerRadius); 11 | void AddRoundedRectPath(CGContextRef context, CGRect rect, CGFloat cornerRadius); 12 | 13 | #if __cplusplus 14 | } 15 | #endif 16 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotDemo-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'CorePlotDemo' target in the 'CorePlotDemo' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_4_0 8 | #warning "This project uses features only available in iOS SDK 4.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/KSNetworkDemo-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'KSNetworkDemo' target in the 'KSNetworkDemo' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_5_0 8 | #warning "This project uses features only available in iOS SDK 5.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/KSViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSViewController.h 3 | // KSNetworkDemo 4 | // 5 | // Created by kesalin on 13/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface KSViewController : UIViewController 12 | 13 | @property (weak, nonatomic) IBOutlet UITableView *mainTableView; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/KSUtilitiesDemo-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'KSUtilitiesDemo' target in the 'KSUtilitiesDemo' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_5_0 8 | #warning "This project uses features only available in iOS SDK 5.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /SQLiteDemo/SQLiteDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SQLiteDemo 4 | // 5 | // Created by kesalin on 3/28/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "KSAppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([KSAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // CorePlotDemo 4 | // 5 | // Created by kesalin on 2/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "KSAppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([KSAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // KSNetworkDemo 4 | // 5 | // Created by kesalin on 13/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "KSAppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([KSAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/Controllers/KSViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSViewController.h 3 | // KSUtilitiesDemo 4 | // 5 | // Created by kesalin on 6/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface KSViewController : UIViewController 12 | 13 | @property (weak, nonatomic) IBOutlet UITableView *mainTableView; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // KSUtilitiesDemo 4 | // 5 | // Created by kesalin on 6/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "KSAppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([KSAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTMutableNumericData.h: -------------------------------------------------------------------------------- 1 | #import "CPTNumericData.h" 2 | #import "CPTNumericDataType.h" 3 | #import 4 | 5 | @interface CPTMutableNumericData : CPTNumericData { 6 | } 7 | 8 | /// @name Data Buffer 9 | /// @{ 10 | @property (readonly) void *mutableBytes; 11 | /// @} 12 | 13 | /// @name Dimensions 14 | /// @{ 15 | @property (copy, readwrite) NSArray *shape; 16 | /// @} 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTMutableShadow.h: -------------------------------------------------------------------------------- 1 | #import "CPTShadow.h" 2 | #import 3 | #import 4 | 5 | @class CPTColor; 6 | 7 | @interface CPTMutableShadow : CPTShadow { 8 | } 9 | 10 | @property (nonatomic, readwrite, assign) CGSize shadowOffset; 11 | @property (nonatomic, readwrite, assign) CGFloat shadowBlurRadius; 12 | @property (nonatomic, readwrite, retain) CPTColor *shadowColor; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /SQLiteDemo/SQLiteDemo/KSViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSViewController.h 3 | // SQLiteDemo 4 | // 5 | // Created by kesalin on 3/28/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface KSViewController : UIViewController 12 | { 13 | } 14 | 15 | - (IBAction)addButtonPressed:(id)sender; 16 | - (IBAction)deleteButtonPressed:(id)sender; 17 | - (IBAction)updateButtonPressed:(id)sender; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTXYGraph.h: -------------------------------------------------------------------------------- 1 | #import "CPTDefinitions.h" 2 | #import "CPTGraph.h" 3 | #import 4 | 5 | @interface CPTXYGraph : CPTGraph { 6 | @private 7 | CPTScaleType xScaleType; 8 | CPTScaleType yScaleType; 9 | } 10 | 11 | /// @name Initialization 12 | /// @{ 13 | -(id)initWithFrame:(CGRect)newFrame xScaleType:(CPTScaleType)newXScaleType yScaleType:(CPTScaleType)newYScaleType; 14 | /// @} 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/NSNumberExtensions.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | /** @category NSNumber(CPTExtensions) 5 | * @brief Core Plot extensions to NSNumber. 6 | **/ 7 | @interface NSNumber(CPTExtensions) 8 | 9 | +(NSNumber *)numberWithCGFloat:(CGFloat)number; 10 | 11 | -(CGFloat)cgFloatValue; 12 | -(id)initWithCGFloat:(CGFloat)number; 13 | 14 | -(NSDecimalNumber *)decimalNumber; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /SQLiteDemo/SQLiteDemo/KSAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSAppDelegate.h 3 | // SQLiteDemo 4 | // 5 | // Created by kesalin on 3/28/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class KSViewController; 12 | 13 | @interface KSAppDelegate : UIResponder 14 | 15 | @property (strong, nonatomic) UIWindow *window; 16 | 17 | @property (strong, nonatomic) KSViewController *viewController; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/KSAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSAppDelegate.h 3 | // CorePlotDemo 4 | // 5 | // Created by kesalin on 2/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class KSViewController; 12 | 13 | @interface KSAppDelegate : UIResponder 14 | 15 | @property (strong, nonatomic) UIWindow *window; 16 | 17 | @property (strong, nonatomic) KSViewController *viewController; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTMutableTextStyle.h: -------------------------------------------------------------------------------- 1 | #import "CPTTextStyle.h" 2 | #import 3 | 4 | @class CPTColor; 5 | 6 | @interface CPTMutableTextStyle : CPTTextStyle { 7 | } 8 | 9 | @property (readwrite, copy, nonatomic) NSString *fontName; 10 | @property (readwrite, assign, nonatomic) CGFloat fontSize; 11 | @property (readwrite, copy, nonatomic) CPTColor *color; 12 | @property (readwrite, assign, nonatomic) CPTTextAlignment textAlignment; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTPlotAreaFrame.h: -------------------------------------------------------------------------------- 1 | #import "CPTBorderedLayer.h" 2 | 3 | @class CPTAxisSet; 4 | @class CPTPlotGroup; 5 | @class CPTPlotArea; 6 | 7 | @interface CPTPlotAreaFrame : CPTBorderedLayer { 8 | @private 9 | CPTPlotArea *plotArea; 10 | } 11 | 12 | @property (nonatomic, readonly, retain) CPTPlotArea *plotArea; 13 | @property (nonatomic, readwrite, retain) CPTAxisSet *axisSet; 14 | @property (nonatomic, readwrite, retain) CPTPlotGroup *plotGroup; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTXYAxis.h: -------------------------------------------------------------------------------- 1 | #import "CPTAxis.h" 2 | #import 3 | 4 | @class CPTConstraints; 5 | 6 | @interface CPTXYAxis : CPTAxis { 7 | @private 8 | NSDecimal orthogonalCoordinateDecimal; 9 | CPTConstraints *axisConstraints; 10 | } 11 | 12 | /// @name Positioning 13 | /// @{ 14 | @property (nonatomic, readwrite) NSDecimal orthogonalCoordinateDecimal; 15 | @property (nonatomic, readwrite, retain) CPTConstraints *axisConstraints; 16 | /// @} 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTAnnotationHostLayer.h: -------------------------------------------------------------------------------- 1 | #import "CPTLayer.h" 2 | 3 | @class CPTAnnotation; 4 | 5 | @interface CPTAnnotationHostLayer : CPTLayer { 6 | @private 7 | NSMutableArray *mutableAnnotations; 8 | } 9 | 10 | @property (nonatomic, readonly, retain) NSArray *annotations; 11 | 12 | /// @name Annotations 13 | /// @{ 14 | -(void)addAnnotation:(CPTAnnotation *)annotation; 15 | -(void)removeAnnotation:(CPTAnnotation *)annotation; 16 | -(void)removeAllAnnotations; 17 | /// @} 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTPlatformSpecificFunctions.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | /// @file 5 | 6 | #if __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /// @name Graphics Context Save Stack 11 | /// @{ 12 | void CPTPushCGContext(CGContextRef context); 13 | void CPTPopCGContext(void); 14 | 15 | /// @} 16 | 17 | /// @name Graphics Context 18 | /// @{ 19 | CGContextRef CPTGetCurrentContext(void); 20 | 21 | /// @} 22 | 23 | #if __cplusplus 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTPlotSpaceAnnotation.h: -------------------------------------------------------------------------------- 1 | #import "CPTAnnotation.h" 2 | #import 3 | 4 | @class CPTPlotSpace; 5 | 6 | @interface CPTPlotSpaceAnnotation : CPTAnnotation { 7 | NSArray *anchorPlotPoint; 8 | CPTPlotSpace *plotSpace; 9 | } 10 | 11 | @property (nonatomic, readwrite, copy) NSArray *anchorPlotPoint; 12 | @property (nonatomic, readonly, retain) CPTPlotSpace *plotSpace; 13 | 14 | -(id)initWithPlotSpace:(CPTPlotSpace *)space anchorPlotPoint:(NSArray *)plotPoint; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTTimeFormatter.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | /// @file 4 | 5 | @interface CPTTimeFormatter : NSNumberFormatter { 6 | @private 7 | NSDateFormatter *dateFormatter; 8 | NSDate *referenceDate; 9 | } 10 | 11 | @property (nonatomic, readwrite, retain) NSDateFormatter *dateFormatter; 12 | @property (nonatomic, readwrite, copy) NSDate *referenceDate; 13 | 14 | /// @name Initialization 15 | /// @{ 16 | -(id)initWithDateFormatter:(NSDateFormatter *)aDateFormatter; 17 | /// @} 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTColorSpace.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface CPTColorSpace : NSObject { 5 | @private 6 | CGColorSpaceRef cgColorSpace; 7 | } 8 | 9 | @property (nonatomic, readonly, assign) CGColorSpaceRef cgColorSpace; 10 | 11 | /// @name Factory Methods 12 | /// @{ 13 | +(CPTColorSpace *)genericRGBSpace; 14 | /// @} 15 | 16 | /// @name Initialization 17 | /// @{ 18 | -(id)initWithCGColorSpace:(CGColorSpaceRef)colorSpace; 19 | /// @} 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/NSStream+StreamsToHost.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSStream+StreamsToHost.h 3 | // KSNetworkDemo 4 | // 5 | // Created by kesalin on 15/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSStream(StreamsToHost) 12 | 13 | + (void)getStreamsToHostNamed:(NSString *)hostName 14 | port:(NSInteger)port 15 | inputStream:(out NSInputStream **)inputStreamPtr 16 | outputStream:(out NSOutputStream **)outputStreamPtr; 17 | @end 18 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTGraphHostingView.h: -------------------------------------------------------------------------------- 1 | #import "CPTDefinitions.h" 2 | #import 3 | 4 | @class CPTGraph; 5 | 6 | @interface CPTGraphHostingView : UIView { 7 | @protected 8 | CPTGraph *hostedGraph; 9 | BOOL collapsesLayers; 10 | BOOL allowPinchScaling; 11 | __cpt_weak id pinchGestureRecognizer; 12 | } 13 | 14 | @property (nonatomic, readwrite, retain) CPTGraph *hostedGraph; 15 | @property (nonatomic, readwrite, assign) BOOL collapsesLayers; 16 | @property (nonatomic, readwrite, assign) BOOL allowPinchScaling; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | iOSSnippet 2 | ============================== 3 | 4 | Code snippet on iOS 5 | 6 | 1, SQLiteDemo 7 | Demonstate how to use sqlite on iOS, such as open/close database, create table, insert/update/delete record. 8 | 9 | 2, CorePlotDemo 10 | Demonstate how to use CorePlot on iOS, display xygraph and scatter space. 11 | Sreenshots: 12 | ![Screenshots](https://github.com/kesalin/iOSSnippet/blob/master/CorePlotDemo/Note01.png) 13 | 14 | 3, KSUtilitiesDemo 15 | iOS utilities. 16 | 17 | 4, KSNetworkDemo 18 | Demonstate network programming with socket, CFNetwork, Bonjour on iOS. 19 | 20 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/KSUtilities/KSErrorHandler.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSErrorHandler.h 3 | // KSUtilitiesDemo 4 | // 5 | // Created by kesalin on 6/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface KSErrorHandler : NSObject 12 | 13 | @property (nonatomic, strong) NSError * error; 14 | @property (nonatomic, assign) BOOL isFatal; 15 | 16 | - (id)initWithError:(NSError *)error isFatal:(BOOL)isFatal; 17 | 18 | + (void)handleError:(NSError *)error isFatal:(BOOL)isFatal; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/KSUtilities/KSImageCache.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSImageCache.h 3 | // AmericanEnglish 4 | // 5 | // Created by kesalin on 6/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface KSImageCache : NSObject 12 | 13 | + (id)imageNamed:(NSString *)name; 14 | + (BOOL)setImage:(UIImage *)image forName:(NSString *)name; 15 | + (BOOL)setImagePath:(NSString *)filepath forName:(NSString *)name; 16 | + (void)removeImage:(NSString *)name; 17 | + (void)removeImages:(NSArray *)names; 18 | + (void)clear; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/KSUtilities/KSExceptionHandler.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSExceptionHandler.h 3 | // KSUtilitiesDemo 4 | // 5 | // Created by kesalin on 6/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | 13 | @interface KSExceptionHandler : NSObject 14 | 15 | @property (nonatomic, weak) UIViewController * parentViewController; 16 | 17 | + (id)sharedInstance; 18 | - (void)setOrCheckExceptionHandler; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /SQLiteDemo/SQLiteDemo/KSCustomer.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSCustomer.h 3 | // SQLiteDemo 4 | // 5 | // Created by kesalin on 3/28/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface KSCustomer : NSObject 12 | { 13 | NSString * name; 14 | NSString * address; 15 | NSInteger age; 16 | } 17 | 18 | @property (nonatomic, strong) NSString * name; 19 | @property (nonatomic, strong) NSString * address; 20 | @property (nonatomic, assign) NSInteger age; 21 | 22 | - (id)initWith:(NSString *)aName address:(NSString *)aAddress age:(NSInteger)aAge; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTLayerAnnotation.h: -------------------------------------------------------------------------------- 1 | #import "CPTAnnotation.h" 2 | #import "CPTDefinitions.h" 3 | #import 4 | 5 | @class CPTConstraints; 6 | 7 | @interface CPTLayerAnnotation : CPTAnnotation { 8 | @private 9 | __cpt_weak CPTLayer *anchorLayer; 10 | CPTConstraints *xConstraints; 11 | CPTConstraints *yConstraints; 12 | CPTRectAnchor rectAnchor; 13 | } 14 | 15 | @property (nonatomic, readonly, cpt_weak_property) __cpt_weak CPTLayer *anchorLayer; 16 | @property (nonatomic, readwrite, assign) CPTRectAnchor rectAnchor; 17 | 18 | -(id)initWithAnchorLayer:(CPTLayer *)anchorLayer; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /SQLiteDemo/SQLiteDemo/KSCustomer.m: -------------------------------------------------------------------------------- 1 | // 2 | // KSCustomer.m 3 | // SQLiteDemo 4 | // 5 | // Created by kesalin on 3/28/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import "KSCustomer.h" 10 | 11 | @implementation KSCustomer 12 | 13 | @synthesize name, address, age; 14 | 15 | - (id)initWith:(NSString *)aName address:(NSString *)aAddress age:(NSInteger)aAge 16 | { 17 | self = [super init]; 18 | if (self) { 19 | name = aName; 20 | address = aAddress; 21 | age = aAge; 22 | } 23 | 24 | return self; 25 | } 26 | 27 | - (void)dealloc 28 | { 29 | self.name = nil; 30 | self.address = nil; 31 | } 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/KSUtilities/KSPathUtil.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSPathUtil.h 3 | // KSUtilitiesDemo 4 | // 5 | // Created by kesalin on 6/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface KSPathUtil : NSObject 12 | 13 | + (NSString *)homeDirectory; 14 | + (NSString *)temporaryDirectory; 15 | + (NSString *)documentDirectory; 16 | + (NSString *)cacheDirectory; 17 | 18 | + (NSString *)resourcePath; 19 | + (NSString *)resourcePathForResource:(NSString *)name ofType:(NSString *)type; 20 | + (NSString *)resourcePathForResource:(NSString *)name ofType:(NSString *)type inDirectory:(NSString *)dir; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTLimitBand.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @class CPTPlotRange; 4 | @class CPTFill; 5 | 6 | @interface CPTLimitBand : NSObject { 7 | @private 8 | CPTPlotRange *range; 9 | CPTFill *fill; 10 | } 11 | 12 | @property (nonatomic, readwrite, retain) CPTPlotRange *range; 13 | @property (nonatomic, readwrite, retain) CPTFill *fill; 14 | 15 | /// @name Factory Methods 16 | /// @{ 17 | +(CPTLimitBand *)limitBandWithRange:(CPTPlotRange *)newRange fill:(CPTFill *)newFill; 18 | /// @} 19 | 20 | /// @name Initialization 21 | /// @{ 22 | -(id)initWithRange:(CPTPlotRange *)newRange fill:(CPTFill *)newFill; 23 | /// @} 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /SQLiteDemo/SQLiteDemo/KSDefines.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSDefines.h 3 | // SQLiteDemo 4 | // 5 | // Created by kesalin on 3/27/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #ifndef SQLiteDemo_KSDefines_h 10 | #define SQLiteDemo_KSDefines_h 11 | 12 | #ifdef DEBUG 13 | #define DLOG(format, ...) NSLog(format", file:%s, line:%d, function:%s.", ##__VA_ARGS__, __FILE__, __LINE__, __FUNCTION__) 14 | #define TRACE(format, ...) NSLog(@"--- %s "format"---", __FUNCTION__, ##__VA_ARGS__) 15 | #else 16 | #define DLOG(format, ...) 17 | #define TRACE(format, ...) 18 | #endif 19 | 20 | #define KSDocumentPath() [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTAxisSet.h: -------------------------------------------------------------------------------- 1 | #import "CPTLayer.h" 2 | #import 3 | 4 | @class CPTAxis; 5 | @class CPTLineStyle; 6 | 7 | @interface CPTAxisSet : CPTLayer { 8 | @private 9 | NSArray *axes; 10 | CPTLineStyle *borderLineStyle; 11 | } 12 | 13 | /// @name Axes 14 | /// @{ 15 | @property (nonatomic, readwrite, retain) NSArray *axes; 16 | /// @} 17 | 18 | /// @name Drawing 19 | /// @{ 20 | @property (nonatomic, readwrite, copy) CPTLineStyle *borderLineStyle; 21 | /// @} 22 | 23 | /// @name Labels 24 | /// @{ 25 | -(void)relabelAxes; 26 | /// @} 27 | 28 | /// @name Axes 29 | /// @{ 30 | -(CPTAxis *)axisForCoordinate:(CPTCoordinate)coordinate atIndex:(NSUInteger)idx; 31 | /// @} 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTMutableLineStyle.h: -------------------------------------------------------------------------------- 1 | #import "CPTLineStyle.h" 2 | #import 3 | 4 | @class CPTColor; 5 | 6 | @interface CPTMutableLineStyle : CPTLineStyle { 7 | } 8 | 9 | @property (nonatomic, readwrite, assign) CGLineCap lineCap; 10 | @property (nonatomic, readwrite, assign) CGLineJoin lineJoin; 11 | @property (nonatomic, readwrite, assign) CGFloat miterLimit; 12 | @property (nonatomic, readwrite, assign) CGFloat lineWidth; 13 | @property (nonatomic, readwrite, retain) NSArray *dashPattern; 14 | @property (nonatomic, readwrite, assign) CGFloat patternPhase; 15 | @property (nonatomic, readwrite, retain) CPTColor *lineColor; 16 | @property (nonatomic, readwrite, retain) CPTFill *lineFill; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTShadow.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @class CPTColor; 5 | 6 | @interface CPTShadow : NSObject { 7 | @private 8 | CGSize shadowOffset; 9 | CGFloat shadowBlurRadius; 10 | CPTColor *shadowColor; 11 | } 12 | 13 | @property (nonatomic, readonly, assign) CGSize shadowOffset; 14 | @property (nonatomic, readonly, assign) CGFloat shadowBlurRadius; 15 | @property (nonatomic, readonly, retain) CPTColor *shadowColor; 16 | 17 | /// @name Factory Methods 18 | /// @{ 19 | +(id)shadow; 20 | /// @} 21 | 22 | /// @name Drawing 23 | /// @{ 24 | -(void)setShadowInContext:(CGContextRef)context; 25 | /// @} 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTCalendarFormatter.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface CPTCalendarFormatter : NSNumberFormatter { 4 | @private 5 | NSDateFormatter *dateFormatter; 6 | NSDate *referenceDate; 7 | NSCalendar *referenceCalendar; 8 | NSCalendarUnit referenceCalendarUnit; 9 | } 10 | 11 | @property (nonatomic, readwrite, retain) NSDateFormatter *dateFormatter; 12 | @property (nonatomic, readwrite, copy) NSDate *referenceDate; 13 | @property (nonatomic, readwrite, copy) NSCalendar *referenceCalendar; 14 | @property (nonatomic, readwrite, assign) NSCalendarUnit referenceCalendarUnit; 15 | 16 | /// @name Initialization 17 | /// @{ 18 | -(id)initWithDateFormatter:(NSDateFormatter *)aDateFormatter; 19 | /// @} 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTTextLayer.h: -------------------------------------------------------------------------------- 1 | #import "CPTBorderedLayer.h" 2 | #import "CPTTextStyle.h" 3 | 4 | /// @file 5 | 6 | extern const CGFloat kCPTTextLayerMarginWidth; ///< Margin width around the text. 7 | 8 | @interface CPTTextLayer : CPTBorderedLayer { 9 | @private 10 | NSString *text; 11 | CPTTextStyle *textStyle; 12 | } 13 | 14 | @property (readwrite, copy, nonatomic) NSString *text; 15 | @property (readwrite, retain, nonatomic) CPTTextStyle *textStyle; 16 | 17 | /// @name Initialization 18 | /// @{ 19 | -(id)initWithText:(NSString *)newText; 20 | -(id)initWithText:(NSString *)newText style:(CPTTextStyle *)newStyle; 21 | /// @} 22 | 23 | /// @name Layout 24 | /// @{ 25 | -(CGSize)sizeThatFits; 26 | -(void)sizeToFit; 27 | /// @} 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/KSSocketViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSSocketViewController.h 3 | // KSNetworkDemo 4 | // 5 | // Created by kesalin on 13/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface KSSocketViewController : UIViewController 12 | 13 | @property (weak, nonatomic) IBOutlet UITextField *serverAddressTextField; 14 | @property (weak, nonatomic) IBOutlet UITextField *serverPortTextField; 15 | @property (weak, nonatomic) IBOutlet UITextView *receiveTextView; 16 | @property (weak, nonatomic) IBOutlet UIButton *connectButton; 17 | @property (weak, nonatomic) IBOutlet UIActivityIndicatorView *networkActivityView; 18 | 19 | - (IBAction)connectButtonClick:(id)sender; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/KSCFNetworkViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSCFNetworkViewController.h 3 | // KSNetworkDemo 4 | // 5 | // Created by kesalin on 13/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface KSCFNetworkViewController : UIViewController 12 | 13 | @property (weak, nonatomic) IBOutlet UITextField *serverAddressTextField; 14 | @property (weak, nonatomic) IBOutlet UITextField *serverPortTextField; 15 | @property (weak, nonatomic) IBOutlet UITextView *receiveTextView; 16 | @property (weak, nonatomic) IBOutlet UIButton *connectButton; 17 | @property (weak, nonatomic) IBOutlet UIActivityIndicatorView *networkActivityView; 18 | 19 | - (IBAction)connectButtonClick:(id)sender; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/KSNSStreamViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSNSStreamViewController.h 3 | // KSNetworkDemo 4 | // 5 | // Created by kesalin on 15/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface KSNSStreamViewController : UIViewController 12 | 13 | @property (weak, nonatomic) IBOutlet UITextField *serverAddressTextField; 14 | @property (weak, nonatomic) IBOutlet UITextField *serverPortTextField; 15 | @property (weak, nonatomic) IBOutlet UITextView *receiveTextView; 16 | @property (weak, nonatomic) IBOutlet UIButton *connectButton; 17 | @property (weak, nonatomic) IBOutlet UIActivityIndicatorView *networkActivityView; 18 | 19 | - (IBAction)connectButtonClick:(id)sender; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTBorderedLayer.h: -------------------------------------------------------------------------------- 1 | #import "CPTAnnotationHostLayer.h" 2 | #import 3 | 4 | @class CPTLineStyle; 5 | @class CPTFill; 6 | 7 | @interface CPTBorderedLayer : CPTAnnotationHostLayer { 8 | @private 9 | CPTLineStyle *borderLineStyle; 10 | CPTFill *fill; 11 | BOOL inLayout; 12 | } 13 | 14 | /// @name Drawing 15 | /// @{ 16 | @property (nonatomic, readwrite, copy) CPTLineStyle *borderLineStyle; 17 | @property (nonatomic, readwrite, copy) CPTFill *fill; 18 | /// @} 19 | 20 | /// @name Layout 21 | /// @{ 22 | @property (nonatomic, readwrite) BOOL inLayout; 23 | /// @} 24 | 25 | /// @name Drawing 26 | /// @{ 27 | -(void)renderBorderedLayer:(CPTBorderedLayer *)layer asVectorInContext:(CGContextRef)context; 28 | /// @} 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTMutablePlotRange.h: -------------------------------------------------------------------------------- 1 | #import "CPTPlotRange.h" 2 | 3 | @interface CPTMutablePlotRange : CPTPlotRange { 4 | } 5 | 6 | /// @name Range Limits 7 | /// @{ 8 | @property (nonatomic, readwrite) NSDecimal location; 9 | @property (nonatomic, readwrite) NSDecimal length; 10 | /// @} 11 | 12 | /// @name Combining Ranges 13 | /// @{ 14 | -(void)unionPlotRange:(CPTPlotRange *)otherRange; 15 | -(void)intersectionPlotRange:(CPTPlotRange *)otherRange; 16 | /// @} 17 | 18 | /// @name Shifting Ranges 19 | /// @{ 20 | -(void)shiftLocationToFitInRange:(CPTPlotRange *)otherRange; 21 | -(void)shiftEndToFitInRange:(CPTPlotRange *)otherRange; 22 | /// @} 23 | 24 | /// @name Expanding/Contracting Ranges 25 | /// @{ 26 | -(void)expandRangeByFactor:(NSDecimal)factor; 27 | /// @} 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTDataSourceTestCase.h: -------------------------------------------------------------------------------- 1 | #import "CPTTestCase.h" 2 | 3 | #import "CPTPlot.h" 4 | 5 | @class CPTMutablePlotRange; 6 | 7 | @interface CPTDataSourceTestCase : CPTTestCase { 8 | @private 9 | NSArray *xData, *yData; 10 | CPTMutablePlotRange *xRange, *yRange; 11 | 12 | NSMutableArray *plots; 13 | 14 | NSUInteger nRecords; 15 | } 16 | 17 | @property (copy, readwrite) NSArray *xData; 18 | @property (copy, readwrite) NSArray *yData; 19 | @property (assign, readwrite) NSUInteger nRecords; 20 | @property (retain, readonly) CPTMutablePlotRange *xRange; 21 | @property (retain, readonly) CPTMutablePlotRange *yRange; 22 | @property (retain, readwrite) NSMutableArray *plots; 23 | 24 | -(void)buildData; 25 | 26 | -(void)addPlot:(CPTPlot *)newPlot; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTMutableNumericData+TypeConversion.h: -------------------------------------------------------------------------------- 1 | #import "CPTMutableNumericData.h" 2 | #import "CPTNumericDataType.h" 3 | #import 4 | 5 | /** @category CPTMutableNumericData(TypeConversion) 6 | * @brief Type conversion methods for CPTMutableNumericData. 7 | **/ 8 | @interface CPTMutableNumericData(TypeConversion) 9 | 10 | /// @name Data Format 11 | /// @{ 12 | @property (assign, readwrite) CPTNumericDataType dataType; 13 | @property (assign, readwrite) CPTDataTypeFormat dataTypeFormat; 14 | @property (assign, readwrite) size_t sampleBytes; 15 | @property (assign, readwrite) CFByteOrder byteOrder; 16 | /// @} 17 | 18 | /// @name Type Conversion 19 | /// @{ 20 | -(void)convertToType:(CPTDataTypeFormat)newDataType sampleBytes:(size_t)newSampleBytes byteOrder:(CFByteOrder)newByteOrder; 21 | /// @} 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTXYPlotSpace.h: -------------------------------------------------------------------------------- 1 | #import "CPTDefinitions.h" 2 | #import "CPTPlotSpace.h" 3 | 4 | @class CPTPlotRange; 5 | 6 | @interface CPTXYPlotSpace : CPTPlotSpace { 7 | @private 8 | CPTPlotRange *xRange; 9 | CPTPlotRange *yRange; 10 | CPTPlotRange *globalXRange; 11 | CPTPlotRange *globalYRange; 12 | CPTScaleType xScaleType; 13 | CPTScaleType yScaleType; 14 | CGPoint lastDragPoint; 15 | BOOL isDragging; 16 | } 17 | 18 | @property (nonatomic, readwrite, copy) CPTPlotRange *xRange; 19 | @property (nonatomic, readwrite, copy) CPTPlotRange *yRange; 20 | @property (nonatomic, readwrite, copy) CPTPlotRange *globalXRange; 21 | @property (nonatomic, readwrite, copy) CPTPlotRange *globalYRange; 22 | @property (nonatomic, readwrite, assign) CPTScaleType xScaleType; 23 | @property (nonatomic, readwrite, assign) CPTScaleType yScaleType; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTNumericData+TypeConversion.h: -------------------------------------------------------------------------------- 1 | #import "CPTNumericData.h" 2 | #import "CPTNumericDataType.h" 3 | #import 4 | 5 | /** @category CPTNumericData(TypeConversion) 6 | * @brief Type conversion methods for CPTNumericData. 7 | **/ 8 | @interface CPTNumericData(TypeConversion) 9 | 10 | /// @name Type Conversion 11 | /// @{ 12 | -(CPTNumericData *)dataByConvertingToDataType:(CPTNumericDataType)newDataType; 13 | 14 | -(CPTNumericData *)dataByConvertingToType:(CPTDataTypeFormat)newDataType sampleBytes:(size_t)newSampleBytes byteOrder:(CFByteOrder)newByteOrder; 15 | /// @} 16 | 17 | /// @name Data Conversion Utilities 18 | /// @{ 19 | -(void)convertData:(NSData *)sourceData dataType:(CPTNumericDataType *)sourceDataType toData:(NSMutableData *)destData dataType:(CPTNumericDataType *)destDataType; 20 | -(void)swapByteOrderForData:(NSMutableData *)sourceData sampleSize:(size_t)sampleSize; 21 | /// @} 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTFill.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @class CPTGradient; 5 | @class CPTImage; 6 | @class CPTColor; 7 | 8 | @interface CPTFill : NSObject { 9 | } 10 | 11 | /// @name Factory Methods 12 | /// @{ 13 | +(CPTFill *)fillWithColor:(CPTColor *)aColor; 14 | +(CPTFill *)fillWithGradient:(CPTGradient *)aGradient; 15 | +(CPTFill *)fillWithImage:(CPTImage *)anImage; 16 | /// @} 17 | 18 | /// @name Initialization 19 | /// @{ 20 | -(id)initWithColor:(CPTColor *)aColor; 21 | -(id)initWithGradient:(CPTGradient *)aGradient; 22 | -(id)initWithImage:(CPTImage *)anImage; 23 | /// @} 24 | 25 | @end 26 | 27 | /** @category CPTFill(AbstractMethods) 28 | * @brief CPTFill abstract methods—must be overridden by subclasses 29 | **/ 30 | @interface CPTFill(AbstractMethods) 31 | 32 | /// @name Drawing 33 | /// @{ 34 | -(void)fillRect:(CGRect)rect inContext:(CGContextRef)context; 35 | -(void)fillPathInContext:(CGContextRef)context; 36 | /// @} 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTLegendEntry.h: -------------------------------------------------------------------------------- 1 | #import "CPTDefinitions.h" 2 | #import 3 | #import 4 | 5 | @class CPTPlot; 6 | @class CPTTextStyle; 7 | 8 | @interface CPTLegendEntry : NSObject { 9 | @private 10 | __cpt_weak CPTPlot *plot; 11 | NSUInteger index; 12 | NSUInteger row; 13 | NSUInteger column; 14 | CPTTextStyle *textStyle; 15 | } 16 | 17 | /// @name Plot Info 18 | /// @{ 19 | @property (nonatomic, readwrite, cpt_weak_property) __cpt_weak CPTPlot *plot; 20 | @property (nonatomic, readwrite, assign) NSUInteger index; 21 | /// @} 22 | 23 | /// @name Formatting 24 | /// @{ 25 | @property (nonatomic, readwrite, retain) CPTTextStyle *textStyle; 26 | /// @} 27 | 28 | /// @name Layout 29 | /// @{ 30 | @property (nonatomic, readwrite, assign) NSUInteger row; 31 | @property (nonatomic, readwrite, assign) NSUInteger column; 32 | @property (nonatomic, readonly, assign) CGSize titleSize; 33 | /// @} 34 | 35 | /// @name Drawing 36 | /// @{ 37 | -(void)drawTitleInRect:(CGRect)rect inContext:(CGContextRef)context scale:(CGFloat)scale; 38 | /// @} 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTConstraints.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface CPTConstraints : NSObject { 5 | } 6 | 7 | /// @name Factory Methods 8 | /// @{ 9 | +(CPTConstraints *)constraintWithLowerOffset:(CGFloat)newOffset; 10 | +(CPTConstraints *)constraintWithUpperOffset:(CGFloat)newOffset; 11 | +(CPTConstraints *)constraintWithRelativeOffset:(CGFloat)newOffset; 12 | /// @} 13 | 14 | /// @name Initialization 15 | /// @{ 16 | -(id)initWithLowerOffset:(CGFloat)newOffset; 17 | -(id)initWithUpperOffset:(CGFloat)newOffset; 18 | -(id)initWithRelativeOffset:(CGFloat)newOffset; 19 | /// @} 20 | 21 | @end 22 | 23 | /** @category CPTConstraints(AbstractMethods) 24 | * @brief CPTConstraints abstract methods—must be overridden by subclasses 25 | **/ 26 | @interface CPTConstraints(AbstractMethods) 27 | 28 | /// @name Comparison 29 | /// @{ 30 | -(BOOL)isEqualToConstraint:(CPTConstraints *)otherConstraint; 31 | /// @} 32 | 33 | /// @name Position 34 | /// @{ 35 | -(CGFloat)positionForLowerBound:(CGFloat)lowerBound upperBound:(CGFloat)upperBound; 36 | /// @} 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTPlatformSpecificCategories.h: -------------------------------------------------------------------------------- 1 | #import "CPTColor.h" 2 | #import "CPTLayer.h" 3 | #import "CPTPlatformSpecificDefines.h" 4 | #import 5 | 6 | /** @category CPTColor(CPTPlatformSpecificColorExtensions) 7 | * @brief Platform-specific extensions to CPTColor. 8 | **/ 9 | @interface CPTColor(CPTPlatformSpecificColorExtensions) 10 | 11 | @property (nonatomic, readonly, retain) UIColor *uiColor; 12 | 13 | @end 14 | 15 | /** @category CPTLayer(CPTPlatformSpecificLayerExtensions) 16 | * @brief Platform-specific extensions to CPTLayer. 17 | **/ 18 | @interface CPTLayer(CPTPlatformSpecificLayerExtensions) 19 | 20 | /// @name Images 21 | /// @{ 22 | -(CPTNativeImage *)imageOfLayer; 23 | /// @} 24 | 25 | @end 26 | 27 | /** @category NSNumber(CPTPlatformSpecificNumberExtensions) 28 | * @brief Platform-specific extensions to NSNumber. 29 | **/ 30 | @interface NSNumber(CPTPlatformSpecificNumberExtensions) 31 | 32 | -(BOOL)isLessThan:(NSNumber *)other; 33 | -(BOOL)isLessThanOrEqualTo:(NSNumber *)other; 34 | -(BOOL)isGreaterThan:(NSNumber *)other; 35 | -(BOOL)isGreaterThanOrEqualTo:(NSNumber *)other; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTImage.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface CPTImage : NSObject { 5 | @private 6 | CGImageRef image; 7 | CGFloat scale; 8 | BOOL tiled; 9 | BOOL tileAnchoredToContext; 10 | } 11 | 12 | @property (nonatomic, readwrite, assign) CGImageRef image; 13 | @property (nonatomic, readwrite, assign) CGFloat scale; 14 | @property (nonatomic, readwrite, assign, getter = isTiled) BOOL tiled; 15 | @property (nonatomic, readwrite, assign) BOOL tileAnchoredToContext; 16 | 17 | /// @name Factory Methods 18 | /// @{ 19 | +(CPTImage *)imageWithCGImage:(CGImageRef)anImage scale:(CGFloat)newScale; 20 | +(CPTImage *)imageWithCGImage:(CGImageRef)anImage; 21 | +(CPTImage *)imageForPNGFile:(NSString *)path; 22 | /// @} 23 | 24 | /// @name Initialization 25 | /// @{ 26 | -(id)initWithCGImage:(CGImageRef)anImage scale:(CGFloat)newScale; 27 | -(id)initWithCGImage:(CGImageRef)anImage; 28 | -(id)initForPNGFile:(NSString *)path; 29 | /// @} 30 | 31 | /// @name Drawing 32 | /// @{ 33 | -(void)drawInRect:(CGRect)rect inContext:(CGContextRef)context; 34 | /// @} 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTAnnotation.h: -------------------------------------------------------------------------------- 1 | #import "CPTDefinitions.h" 2 | #import 3 | #import 4 | 5 | @class CPTAnnotationHostLayer; 6 | @class CPTLayer; 7 | 8 | @interface CPTAnnotation : NSObject { 9 | @private 10 | __cpt_weak CPTAnnotationHostLayer *annotationHostLayer; 11 | CPTLayer *contentLayer; 12 | CGPoint contentAnchorPoint; 13 | CGPoint displacement; 14 | CGFloat rotation; 15 | } 16 | 17 | @property (nonatomic, readwrite, retain) CPTLayer *contentLayer; 18 | @property (nonatomic, readwrite, cpt_weak_property) __cpt_weak CPTAnnotationHostLayer *annotationHostLayer; 19 | @property (nonatomic, readwrite, assign) CGPoint contentAnchorPoint; 20 | @property (nonatomic, readwrite, assign) CGPoint displacement; 21 | @property (nonatomic, readwrite, assign) CGFloat rotation; 22 | 23 | @end 24 | 25 | #pragma mark - 26 | 27 | /** @category CPTAnnotation(AbstractMethods) 28 | * @brief CPTAnnotation abstract methods—must be overridden by subclasses. 29 | **/ 30 | @interface CPTAnnotation(AbstractMethods) 31 | 32 | /// @name Layout 33 | /// @{ 34 | -(void)positionContentLayer; 35 | /// @} 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTAxisLabel.h: -------------------------------------------------------------------------------- 1 | #import "CPTDefinitions.h" 2 | #import 3 | 4 | @class CPTLayer; 5 | @class CPTTextStyle; 6 | 7 | @interface CPTAxisLabel : NSObject { 8 | @private 9 | CPTLayer *contentLayer; 10 | CGFloat offset; 11 | CGFloat rotation; 12 | CPTAlignment alignment; 13 | NSDecimal tickLocation; 14 | } 15 | 16 | @property (nonatomic, readwrite, retain) CPTLayer *contentLayer; 17 | @property (nonatomic, readwrite, assign) CGFloat offset; 18 | @property (nonatomic, readwrite, assign) CGFloat rotation; 19 | @property (nonatomic, readwrite, assign) CPTAlignment alignment; 20 | @property (nonatomic, readwrite) NSDecimal tickLocation; 21 | 22 | /// @name Initialization 23 | /// @{ 24 | -(id)initWithText:(NSString *)newText textStyle:(CPTTextStyle *)style; 25 | -(id)initWithContentLayer:(CPTLayer *)layer; 26 | /// @} 27 | 28 | /// @name Layout 29 | /// @{ 30 | -(void)positionRelativeToViewPoint:(CGPoint)point forCoordinate:(CPTCoordinate)coordinate inDirection:(CPTSign)direction; 31 | -(void)positionBetweenViewPoint:(CGPoint)firstPoint andViewPoint:(CGPoint)secondPoint forCoordinate:(CPTCoordinate)coordinate inDirection:(CPTSign)direction; 32 | /// @} 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTColor.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface CPTColor : NSObject { 5 | @private 6 | CGColorRef cgColor; 7 | } 8 | 9 | @property (nonatomic, readonly, assign) CGColorRef cgColor; 10 | 11 | /// @name Factory Methods 12 | /// @{ 13 | +(CPTColor *)clearColor; 14 | +(CPTColor *)whiteColor; 15 | +(CPTColor *)lightGrayColor; 16 | +(CPTColor *)grayColor; 17 | +(CPTColor *)darkGrayColor; 18 | +(CPTColor *)blackColor; 19 | +(CPTColor *)redColor; 20 | +(CPTColor *)greenColor; 21 | +(CPTColor *)blueColor; 22 | +(CPTColor *)cyanColor; 23 | +(CPTColor *)yellowColor; 24 | +(CPTColor *)magentaColor; 25 | +(CPTColor *)orangeColor; 26 | +(CPTColor *)purpleColor; 27 | +(CPTColor *)brownColor; 28 | 29 | +(CPTColor *)colorWithCGColor:(CGColorRef)newCGColor; 30 | +(CPTColor *)colorWithComponentRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha; 31 | +(CPTColor *)colorWithGenericGray:(CGFloat)gray; 32 | /// @} 33 | 34 | /// @name Initialization 35 | /// @{ 36 | -(id)initWithCGColor:(CGColorRef)cgColor; 37 | -(id)initWithComponentRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha; 38 | 39 | -(CPTColor *)colorWithAlphaComponent:(CGFloat)alpha; 40 | /// @} 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.kesalin.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/NSCoderExtensions.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | /** @category NSCoder(CPTExtensions) 5 | * @brief Core Plot extensions to NSCoder. 6 | **/ 7 | @interface NSCoder(CPTExtensions) 8 | 9 | /// @name Encoding Data 10 | /// @{ 11 | -(void)encodeCGFloat:(CGFloat)number forKey:(NSString *)key; 12 | -(void)encodeCPTPoint:(CGPoint)point forKey:(NSString *)key; 13 | -(void)encodeCPTSize:(CGSize)size forKey:(NSString *)key; 14 | -(void)encodeCPTRect:(CGRect)rect forKey:(NSString *)key; 15 | 16 | -(void)encodeCGColorSpace:(CGColorSpaceRef)colorSpace forKey:(NSString *)key; 17 | -(void)encodeCGPath:(CGPathRef)path forKey:(NSString *)key; 18 | -(void)encodeCGImage:(CGImageRef)image forKey:(NSString *)key; 19 | 20 | -(void)encodeDecimal:(NSDecimal)number forKey:(NSString *)key; 21 | /// @} 22 | 23 | /// @name Decoding Data 24 | /// @{ 25 | -(CGFloat)decodeCGFloatForKey:(NSString *)key; 26 | -(CGPoint)decodeCPTPointForKey:(NSString *)key; 27 | -(CGSize)decodeCPTSizeForKey:(NSString *)key; 28 | -(CGRect)decodeCPTRectForKey:(NSString *)key; 29 | 30 | -(CGColorSpaceRef)newCGColorSpaceDecodeForKey:(NSString *)key; 31 | -(CGPathRef)newCGPathDecodeForKey:(NSString *)key; 32 | -(CGImageRef)newCGImageDecodeForKey:(NSString *)key; 33 | 34 | -(NSDecimal)decodeDecimalForKey:(NSString *)key; 35 | /// @} 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/KSNetworkDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.kesalin.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | MainStoryboard 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/KSUtilities/KSDefines.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSDefines.h 3 | // KSUtilitiesDemo 4 | // 5 | // Created by kesalin on 6/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #ifndef KSUtilitiesDemo_KSDefines_h 10 | #define KSUtilitiesDemo_KSDefines_h 11 | 12 | #define sizeOfArray(_a) sizeof((_a))/sizeof((_a[0])) 13 | 14 | #define kIsIPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 15 | #define kIsSimulator (NSNotFound != [[[UIDevice currentDevice] model] rangeOfString:@"Simulator"].location) 16 | 17 | #define kDeviceUUID [[UIDevice currentDevice] uniqueIdentifier] 18 | #define kDeviceVersion [[[UIDevice currentDevice] systemVersion] floatValue] 19 | 20 | #define kScreenBounds [UIScreen mainScreen] bounds] 21 | #define kAppWidth [[UIScreen mainScreen] bounds].size.width 22 | #define kAppHeight [[UIScreen mainScreen] bounds].size.height 23 | 24 | #define kTabItemHeight 44.0 25 | #define kStatusHeight 20.0 26 | 27 | #define kUserNameRegex @"^[A-Za-z0-9_]{3,18}(@([a-zA-Z0-9_-])+(\\.[a-zA-Z0-9_-]+)){0,1}$" 28 | #define kPasswordRegex @".{6,12}" 29 | #define kPhoneNumberRegex @"^(0|\\+86|86){0,1}(13[0-9]|15[0-9]|18[6-9])[0-9]{8}$" 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/KSUtilities/KSPathUtil.m: -------------------------------------------------------------------------------- 1 | // 2 | // KSPath.m 3 | // KSUtilitiesDemo 4 | // 5 | // Created by kesalin on 6/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import "KSPathUtil.h" 10 | 11 | @implementation KSPathUtil 12 | 13 | 14 | + (NSString *)homeDirectory 15 | { 16 | return NSHomeDirectory(); 17 | } 18 | 19 | + (NSString *)temporaryDirectory 20 | { 21 | return NSTemporaryDirectory(); 22 | } 23 | 24 | + (NSString *)documentDirectory 25 | { 26 | NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 27 | NSString * dir = [paths objectAtIndex:0]; 28 | return dir; 29 | } 30 | 31 | + (NSString *)cacheDirectory 32 | { 33 | NSArray * paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 34 | NSString * dir = [paths objectAtIndex:0]; 35 | return dir; 36 | } 37 | 38 | + (NSString *)resourcePath 39 | { 40 | return [[NSBundle mainBundle] resourcePath]; 41 | } 42 | 43 | + (NSString *)resourcePathForResource:(NSString *)name ofType:(NSString *)type 44 | { 45 | return [[NSBundle mainBundle] pathForResource:name ofType:type]; 46 | } 47 | 48 | + (NSString *)resourcePathForResource:(NSString *)name ofType:(NSString *)type inDirectory:(NSString *)dir 49 | { 50 | return [[NSBundle mainBundle] pathForResource:name ofType:type inDirectory:dir]; 51 | } 52 | 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/KSUtilitiesDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.kesalin.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | MainStoryboard 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTLineStyle.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @class CPTColor; 5 | @class CPTFill; 6 | 7 | @interface CPTLineStyle : NSObject { 8 | @private 9 | CGLineCap lineCap; 10 | // CGLineDash lineDash; // We should make a struct to keep this information 11 | CGLineJoin lineJoin; 12 | CGFloat miterLimit; 13 | CGFloat lineWidth; 14 | NSArray *dashPattern; 15 | CGFloat patternPhase; 16 | // StrokePattern; // We should make a struct to keep this information 17 | CPTColor *lineColor; 18 | CPTFill *lineFill; 19 | } 20 | 21 | @property (nonatomic, readonly, assign) CGLineCap lineCap; 22 | @property (nonatomic, readonly, assign) CGLineJoin lineJoin; 23 | @property (nonatomic, readonly, assign) CGFloat miterLimit; 24 | @property (nonatomic, readonly, assign) CGFloat lineWidth; 25 | @property (nonatomic, readonly, retain) NSArray *dashPattern; 26 | @property (nonatomic, readonly, assign) CGFloat patternPhase; 27 | @property (nonatomic, readonly, retain) CPTColor *lineColor; 28 | @property (nonatomic, readonly, retain) CPTFill *lineFill; 29 | 30 | /// @name Factory Methods 31 | /// @{ 32 | +(id)lineStyle; 33 | /// @} 34 | 35 | /// @name Drawing 36 | /// @{ 37 | -(void)setLineStyleInContext:(CGContextRef)context; 38 | -(void)strokePathInContext:(CGContextRef)context; 39 | -(void)strokeRect:(CGRect)rect inContext:(CGContextRef)context; 40 | /// @} 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTTextStyle.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | /// @file 5 | 6 | @class CPTColor; 7 | 8 | /** 9 | * @brief Enumeration of paragraph alignments. 10 | **/ 11 | typedef enum _CPTTextAlignment { 12 | CPTTextAlignmentLeft, ///< Left alignment 13 | CPTTextAlignmentCenter, ///< Center alignment 14 | CPTTextAlignmentRight ///< Right alignment 15 | } 16 | CPTTextAlignment; 17 | 18 | @interface CPTTextStyle : NSObject { 19 | @protected 20 | NSString *fontName; 21 | CGFloat fontSize; 22 | CPTColor *color; 23 | CPTTextAlignment textAlignment; 24 | } 25 | 26 | @property (readonly, copy, nonatomic) NSString *fontName; 27 | @property (readonly, assign, nonatomic) CGFloat fontSize; 28 | @property (readonly, copy, nonatomic) CPTColor *color; 29 | @property (readonly, assign, nonatomic) CPTTextAlignment textAlignment; 30 | 31 | /// @name Factory Methods 32 | /// @{ 33 | +(id)textStyle; 34 | /// @} 35 | 36 | @end 37 | 38 | /** @category NSString(CPTTextStyleExtensions) 39 | * @brief NSString extensions for drawing styled text. 40 | **/ 41 | @interface NSString(CPTTextStyleExtensions) 42 | 43 | /// @name Measurement 44 | /// @{ 45 | -(CGSize)sizeWithTextStyle:(CPTTextStyle *)style; 46 | /// @} 47 | 48 | /// @name Drawing 49 | /// @{ 50 | -(void)drawInRect:(CGRect)rect withTextStyle:(CPTTextStyle *)style inContext:(CGContextRef)context; 51 | /// @} 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/KSUtilities/KSLog.h: -------------------------------------------------------------------------------- 1 | // 2 | // KSLog.h 3 | // KSUtilitiesDemo 4 | // 5 | // Created by kesalin on 6/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #ifndef KSUtilitiesDemo_KSLog_h 10 | #define KSUtilitiesDemo_KSLog_h 11 | 12 | 13 | #ifdef DEBUG 14 | #define KSLog(format, ...) NSLog(format", file:%s, line:%d, function:%s.", ##__VA_ARGS__, __FILE__, __LINE__, __FUNCTION__) 15 | #define KSTrace(format, ...) NSLog(@"--- %s "format"---", __FUNCTION__, ##__VA_ARGS__) 16 | #else 17 | #define KSLog(format, ...) 18 | #define KSTrace(format, ...) 19 | #endif 20 | 21 | /* 22 | #ifdef DEBUG_OBJC 23 | //开启下面的宏就把调试信息输出到文件,注释即输出到终端 24 | #define DEBUG_TO_FILE 25 | #define DEBUG_FILE "/tmp/debugmsg" 26 | #ifdef DEBUG_TO_FILE 27 | //调试信息的缓冲长度 28 | #define DEBUG_BUFFER_MAX 4096 29 | //将调试信息输出到文件中 30 | #define printDebugMsg(moduleName, format, ...) {\ 31 | char buffer[DEBUG_BUFFER_MAX+1]={0};\ 32 | snprintf( buffer, DEBUG_BUFFER_MAX \ 33 | , "[%s] "format" File:%s, Line:%d\n", moduleName, ##__VA_ARGS__, __FILE__, __LINE__ );\ 34 | FILE* fd = fopen(DEBUG_FILE, "a");\ 35 | if ( fd != NULL ) {\ 36 | fwrite( buffer, strlen(buffer), 1, fd );\ 37 | fflush( fd );\ 38 | fclose( fd );\ 39 | }\ 40 | } 41 | #else 42 | //将调试信息输出到终端 43 | #define printDebugMsg(moduleName, format, ...) \ 44 | printf( "[%s] "format" File:%s, Line:%d\n", moduleName, ##__VA_ARGS__, __FILE__, __LINE__ ); 45 | #endif //end for #ifdef DEBUG_TO_FILE 46 | #else 47 | //发行版本,什么也不做 48 | #define printDebugMsg(moduleName, format, ...) 49 | #endif 50 | */ 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /SQLiteDemo/SQLiteDemo/SQLiteDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.kesalin.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/NSStream+StreamsToHost.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSStream+StreamsToHost.m 3 | // KSNetworkDemo 4 | // 5 | // Created by kesalin on 15/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | // 10 | // Ref:http://developer.apple.com/library/ios/#qa/qa1652/_index.html 11 | // 12 | 13 | #import "NSStream+StreamsToHost.h" 14 | 15 | @implementation NSStream(StreamsToHost) 16 | 17 | + (void)getStreamsToHostNamed:(NSString *)hostName 18 | port:(NSInteger)port 19 | inputStream:(out NSInputStream **)inputStreamPtr 20 | outputStream:(out NSOutputStream **)outputStreamPtr 21 | { 22 | CFReadStreamRef readStream; 23 | CFWriteStreamRef writeStream; 24 | 25 | assert(hostName != nil); 26 | assert( (port > 0) && (port < 65536) ); 27 | assert( (inputStreamPtr != NULL) || (outputStreamPtr != NULL) ); 28 | 29 | readStream = NULL; 30 | writeStream = NULL; 31 | 32 | CFStreamCreatePairWithSocketToHost( 33 | NULL, 34 | (__bridge CFStringRef) hostName, 35 | port, 36 | ((inputStreamPtr != NULL) ? &readStream : NULL), 37 | ((outputStreamPtr != NULL) ? &writeStream : NULL) 38 | ); 39 | 40 | if (inputStreamPtr != NULL) { 41 | *inputStreamPtr = CFBridgingRelease(readStream); 42 | } 43 | 44 | if (outputStreamPtr != NULL) { 45 | *outputStreamPtr = CFBridgingRelease(writeStream); 46 | } 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTTheme.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | /// @ingroup themeNames 4 | /// @{ 5 | extern NSString *const kCPTDarkGradientTheme; ///< A graph theme with dark gray gradient backgrounds and light gray lines. 6 | extern NSString *const kCPTPlainBlackTheme; ///< A graph theme with black backgrounds and white lines. 7 | extern NSString *const kCPTPlainWhiteTheme; ///< A graph theme with white backgrounds and black lines. 8 | extern NSString *const kCPTSlateTheme; ///< A graph theme with colors that match the default iPhone navigation bar, toolbar buttons, and table views. 9 | extern NSString *const kCPTStocksTheme; ///< A graph theme with a gradient background and white lines. 10 | /// @} 11 | 12 | @class CPTGraph; 13 | @class CPTPlotAreaFrame; 14 | @class CPTAxisSet; 15 | @class CPTMutableTextStyle; 16 | 17 | @interface CPTTheme : NSObject { 18 | @private 19 | Class graphClass; 20 | } 21 | 22 | @property (nonatomic, readwrite, retain) Class graphClass; 23 | 24 | /// @name Theme Management 25 | /// @{ 26 | +(void)registerTheme:(Class)themeClass; 27 | +(NSArray *)themeClasses; 28 | +(CPTTheme *)themeNamed:(NSString *)theme; 29 | +(NSString *)name; 30 | /// @} 31 | 32 | /// @name Theme Usage 33 | /// @{ 34 | -(void)applyThemeToGraph:(CPTGraph *)graph; 35 | /// @} 36 | 37 | @end 38 | 39 | /** @category CPTTheme(AbstractMethods) 40 | * @brief CPTTheme abstract methods—must be overridden by subclasses 41 | **/ 42 | @interface CPTTheme(AbstractMethods) 43 | 44 | /// @name Theme Usage 45 | /// @{ 46 | -(id)newGraph; 47 | 48 | -(void)applyThemeToBackground:(CPTGraph *)graph; 49 | -(void)applyThemeToPlotArea:(CPTPlotAreaFrame *)plotAreaFrame; 50 | -(void)applyThemeToAxisSet:(CPTAxisSet *)axisSet; 51 | /// @} 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTPlotArea.h: -------------------------------------------------------------------------------- 1 | #import "CPTAnnotationHostLayer.h" 2 | #import "CPTGraph.h" 3 | #import "CPTLayer.h" 4 | #import 5 | 6 | @class CPTAxis; 7 | @class CPTAxisLabelGroup; 8 | @class CPTAxisSet; 9 | @class CPTGridLineGroup; 10 | @class CPTPlotGroup; 11 | @class CPTLineStyle; 12 | @class CPTFill; 13 | 14 | @interface CPTPlotArea : CPTAnnotationHostLayer { 15 | @private 16 | CPTGridLineGroup *minorGridLineGroup; 17 | CPTGridLineGroup *majorGridLineGroup; 18 | CPTAxisSet *axisSet; 19 | CPTPlotGroup *plotGroup; 20 | CPTAxisLabelGroup *axisLabelGroup; 21 | CPTAxisLabelGroup *axisTitleGroup; 22 | CPTFill *fill; 23 | NSArray *topDownLayerOrder; 24 | CPTGraphLayerType *bottomUpLayerOrder; 25 | BOOL updatingLayers; 26 | } 27 | 28 | /// @name Layers 29 | /// @{ 30 | @property (nonatomic, readwrite, retain) CPTGridLineGroup *minorGridLineGroup; 31 | @property (nonatomic, readwrite, retain) CPTGridLineGroup *majorGridLineGroup; 32 | @property (nonatomic, readwrite, retain) CPTAxisSet *axisSet; 33 | @property (nonatomic, readwrite, retain) CPTPlotGroup *plotGroup; 34 | @property (nonatomic, readwrite, retain) CPTAxisLabelGroup *axisLabelGroup; 35 | @property (nonatomic, readwrite, retain) CPTAxisLabelGroup *axisTitleGroup; 36 | /// @} 37 | 38 | /// @name Layer Ordering 39 | /// @{ 40 | @property (nonatomic, readwrite, retain) NSArray *topDownLayerOrder; 41 | /// @} 42 | 43 | /// @name Decorations 44 | /// @{ 45 | @property (nonatomic, readwrite, copy) CPTLineStyle *borderLineStyle; 46 | @property (nonatomic, readwrite, copy) CPTFill *fill; 47 | /// @} 48 | 49 | /// @name Axis Set Layer Management 50 | /// @{ 51 | -(void)updateAxisSetLayersForType:(CPTGraphLayerType)layerType; 52 | -(void)setAxisSetLayersForType:(CPTGraphLayerType)layerType; 53 | -(unsigned)sublayerIndexForAxis:(CPTAxis *)axis layerType:(CPTGraphLayerType)layerType; 54 | /// @} 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CorePlot-CocoaTouch.h: -------------------------------------------------------------------------------- 1 | #import "CPTAnnotation.h" 2 | #import "CPTAnnotationHostLayer.h" 3 | #import "CPTAxis.h" 4 | #import "CPTAxisLabel.h" 5 | #import "CPTAxisSet.h" 6 | #import "CPTAxisTitle.h" 7 | #import "CPTBarPlot.h" 8 | #import "CPTBorderedLayer.h" 9 | #import "CPTCalendarFormatter.h" 10 | #import "CPTColor.h" 11 | #import "CPTColorSpace.h" 12 | #import "CPTConstraints.h" 13 | #import "CPTDefinitions.h" 14 | #import "CPTExceptions.h" 15 | #import "CPTFill.h" 16 | #import "CPTGradient.h" 17 | #import "CPTGraph.h" 18 | #import "CPTGraphHostingView.h" 19 | #import "CPTImage.h" 20 | #import "CPTLayer.h" 21 | #import "CPTLayerAnnotation.h" 22 | #import "CPTLegend.h" 23 | #import "CPTLegendEntry.h" 24 | #import "CPTLimitBand.h" 25 | #import "CPTLineCap.h" 26 | #import "CPTLineStyle.h" 27 | #import "CPTMutableLineStyle.h" 28 | #import "CPTMutableNumericData.h" 29 | #import "CPTMutableNumericData+TypeConversion.h" 30 | #import "CPTMutablePlotRange.h" 31 | #import "CPTMutableShadow.h" 32 | #import "CPTMutableTextStyle.h" 33 | #import "CPTNumericData.h" 34 | #import "CPTNumericData+TypeConversion.h" 35 | #import "CPTNumericDataType.h" 36 | #import "CPTPieChart.h" 37 | #import "CPTPlatformSpecificDefines.h" 38 | #import "CPTPlatformSpecificFunctions.h" 39 | #import "CPTPlatformSpecificCategories.h" 40 | #import "CPTPathExtensions.h" 41 | #import "CPTPlot.h" 42 | #import "CPTPlotArea.h" 43 | #import "CPTPlotAreaFrame.h" 44 | #import "CPTPlotRange.h" 45 | #import "CPTPlotSpace.h" 46 | #import "CPTPlotSpaceAnnotation.h" 47 | #import "CPTPlotSymbol.h" 48 | #import "CPTRangePlot.h" 49 | #import "CPTResponder.h" 50 | #import "CPTScatterPlot.h" 51 | #import "CPTShadow.h" 52 | #import "CPTTextLayer.h" 53 | #import "CPTTextStyle.h" 54 | #import "CPTTheme.h" 55 | #import "CPTTimeFormatter.h" 56 | #import "CPTTradingRangePlot.h" 57 | #import "CPTUtilities.h" 58 | #import "CPTXYAxis.h" 59 | #import "CPTXYAxisSet.h" 60 | #import "CPTXYGraph.h" 61 | #import "CPTXYPlotSpace.h" 62 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTNumericDataType.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | /// @file 4 | 5 | /** 6 | * @brief Enumeration of data formats for numeric data. 7 | **/ 8 | typedef enum _CPTDataTypeFormat { 9 | CPTUndefinedDataType = 0, ///< Undefined 10 | CPTIntegerDataType, ///< Integer 11 | CPTUnsignedIntegerDataType, ///< Unsigned integer 12 | CPTFloatingPointDataType, ///< Floating point 13 | CPTComplexFloatingPointDataType, ///< Complex floating point 14 | CPTDecimalDataType ///< NSDecimal 15 | } 16 | CPTDataTypeFormat; 17 | 18 | /** 19 | * @brief Enumeration of memory arrangements for multi-dimensional data arrays. 20 | * @see See Wikipedia for more information. 21 | **/ 22 | typedef enum _CPTDataOrder { 23 | CPTDataOrderRowsFirst, ///< Numeric data is arranged in row-major order. 24 | CPTDataOrderColumnsFirst ///< Numeric data is arranged in column-major order. 25 | } 26 | CPTDataOrder; 27 | 28 | /** 29 | * @brief Struct that describes the encoding of numeric data samples. 30 | **/ 31 | typedef struct _CPTNumericDataType { 32 | CPTDataTypeFormat dataTypeFormat; ///< Data type format 33 | size_t sampleBytes; ///< Number of bytes in each sample 34 | CFByteOrder byteOrder; ///< Byte order 35 | } 36 | CPTNumericDataType; 37 | 38 | #if __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /// @name Data Type Utilities 43 | /// @{ 44 | CPTNumericDataType CPTDataType(CPTDataTypeFormat format, size_t sampleBytes, CFByteOrder byteOrder); 45 | CPTNumericDataType CPTDataTypeWithDataTypeString(NSString *dataTypeString); 46 | NSString *CPTDataTypeStringFromDataType(CPTNumericDataType dataType); 47 | BOOL CPTDataTypeIsSupported(CPTNumericDataType format); 48 | BOOL CPTDataTypeEqualToDataType(CPTNumericDataType dataType1, CPTNumericDataType dataType2); 49 | 50 | /// @} 51 | 52 | #if __cplusplus 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTResponder.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | #import "CPTPlatformSpecificDefines.h" 5 | 6 | /** 7 | * @brief The basis of all event processing in Core Plot. 8 | **/ 9 | @protocol CPTResponder 10 | 11 | /// @name User Interaction 12 | /// @{ 13 | 14 | /** 15 | * @brief @required Informs the receiver that the user has 16 | * @if MacOnly pressed the mouse button. @endif 17 | * @if iOSOnly touched the screen. @endif 18 | * @param event The OS event. 19 | * @param interactionPoint The coordinates of the interaction. 20 | * @return Whether the event was handled or not. 21 | **/ 22 | -(BOOL)pointingDeviceDownEvent:(CPTNativeEvent *)event atPoint:(CGPoint)interactionPoint; 23 | 24 | /** 25 | * @brief @required Informs the receiver that the user has 26 | * @if MacOnly released the mouse button. @endif 27 | * @if iOSOnly lifted their finger off the screen. @endif 28 | * @param event The OS event. 29 | * @param interactionPoint The coordinates of the interaction. 30 | * @return Whether the event was handled or not. 31 | **/ 32 | -(BOOL)pointingDeviceUpEvent:(CPTNativeEvent *)event atPoint:(CGPoint)interactionPoint; 33 | 34 | /** 35 | * @brief @required Informs the receiver that the user has moved 36 | * @if MacOnly the mouse with the button pressed. @endif 37 | * @if iOSOnly their finger while touching the screen. @endif 38 | * @param event The OS event. 39 | * @param interactionPoint The coordinates of the interaction. 40 | * @return Whether the event was handled or not. 41 | **/ 42 | -(BOOL)pointingDeviceDraggedEvent:(CPTNativeEvent *)event atPoint:(CGPoint)interactionPoint; 43 | 44 | /** 45 | * @brief @required Informs the receiver that tracking of 46 | * @if MacOnly mouse moves @endif 47 | * @if iOSOnly touches @endif 48 | * has been cancelled for any reason. 49 | * @param event The OS event. 50 | * @return Whether the event was handled or not. 51 | **/ 52 | -(BOOL)pointingDeviceCancelledEvent:(CPTNativeEvent *)event; 53 | /// @} 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/KSAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // KSAppDelegate.m 3 | // KSNetworkDemo 4 | // 5 | // Created by kesalin on 13/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import "KSAppDelegate.h" 10 | 11 | @implementation KSAppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | // Override point for customization after application launch. 16 | return YES; 17 | } 18 | 19 | - (void)applicationWillResignActive:(UIApplication *)application 20 | { 21 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 22 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 23 | } 24 | 25 | - (void)applicationDidEnterBackground:(UIApplication *)application 26 | { 27 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | - (void)applicationWillEnterForeground:(UIApplication *)application 32 | { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | - (void)applicationDidBecomeActive:(UIApplication *)application 37 | { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application 42 | { 43 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/mainpage.h: -------------------------------------------------------------------------------- 1 | /*! @mainpage Core Plot 2 | * 3 | * @section intro Introduction 4 | * 5 | * Core Plot is a plotting framework for Mac OS X and iOS. It provides 2D visualization of data, 6 | * and is tightly integrated with Apple technologies like Core Animation, Core Data, and Cocoa Bindings. 7 | * 8 | * @section start Getting Started 9 | * 10 | * See the project wiki at 11 | * http://code.google.com/p/core-plot/wiki/UsingCorePlotInApplications for information on how to use Core Plot 12 | * in your own application. 13 | * 14 | * @section contribute Contributing to Core Plot 15 | * 16 | * Core Plot is an open source project. The project home page is http://code.google.com/p/core-plot/ on Google Code. 17 | * See http://code.google.com/p/core-plot/source/checkout for instructions on how to download the source code. 18 | * 19 | * @subsection coding Coding Standards 20 | * Everyone has a their own preferred coding style, and no one way can be considered right. Nonetheless, in a 21 | * project like Core Plot, with many developers contributing, it is worthwhile defining a set of basic coding 22 | * standards to prevent a mishmash of different styles which can become frustrating when 23 | * navigating the code base. See the file "Coding Style.mdown" found in the documentation directory 24 | * of the project source for specific guidelines. 25 | * 26 | * @subsection documentation Documentation Policy 27 | * See http://code.google.com/p/core-plot/wiki/DocumentationPolicy for instructions on how to 28 | * document your code so that your comments will appear in these documentation pages. 29 | * 30 | * @subsection testing Testing Policy 31 | * Because Core Plot is intended to be used in scientific, financial, and other domains where correctness is paramount, 32 | * unit testing is integrated into the framework. Good test coverage protects developers from introducing accidental 33 | * regressions and frees them to experiment and refactor without fear of breaking things. See 34 | * http://code.google.com/p/core-plot/wiki/CorePlotTesting for instructions on how to build unit tests 35 | * for any new code you add to the project. 36 | */ 37 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTPlotRange.h: -------------------------------------------------------------------------------- 1 | #import "CPTDefinitions.h" 2 | #import 3 | 4 | /// @file 5 | 6 | /** 7 | * @brief Enumeration of possible results of a plot range comparison. 8 | **/ 9 | typedef enum _CPTPlotRangeComparisonResult { 10 | CPTPlotRangeComparisonResultNumberBelowRange, ///< Number is below the range. 11 | CPTPlotRangeComparisonResultNumberInRange, ///< Number is in the range. 12 | CPTPlotRangeComparisonResultNumberAboveRange ///< Number is above the range. 13 | } 14 | CPTPlotRangeComparisonResult; 15 | 16 | @interface CPTPlotRange : NSObject { 17 | @private 18 | NSDecimal location; 19 | NSDecimal length; 20 | double locationDouble; 21 | double lengthDouble; 22 | } 23 | 24 | /// @name Range Limits 25 | /// @{ 26 | @property (nonatomic, readonly) NSDecimal location; 27 | @property (nonatomic, readonly) NSDecimal length; 28 | @property (nonatomic, readonly) NSDecimal end; 29 | @property (nonatomic, readonly) double locationDouble; 30 | @property (nonatomic, readonly) double lengthDouble; 31 | @property (nonatomic, readonly) double endDouble; 32 | 33 | @property (nonatomic, readonly) NSDecimal minLimit; 34 | @property (nonatomic, readonly) NSDecimal midPoint; 35 | @property (nonatomic, readonly) NSDecimal maxLimit; 36 | @property (nonatomic, readonly) double minLimitDouble; 37 | @property (nonatomic, readonly) double midPointDouble; 38 | @property (nonatomic, readonly) double maxLimitDouble; 39 | /// @} 40 | 41 | /// @name Factory Methods 42 | /// @{ 43 | +(id)plotRangeWithLocation:(NSDecimal)loc length:(NSDecimal)len; 44 | /// @} 45 | 46 | /// @name Initialization 47 | /// @{ 48 | -(id)initWithLocation:(NSDecimal)loc length:(NSDecimal)len; 49 | /// @} 50 | 51 | /// @name Checking Ranges 52 | /// @{ 53 | -(BOOL)contains:(NSDecimal)number; 54 | -(BOOL)containsDouble:(double)number; 55 | -(BOOL)isEqualToRange:(CPTPlotRange *)otherRange; 56 | -(BOOL)containsRange:(CPTPlotRange *)otherRange; 57 | -(BOOL)intersectsRange:(CPTPlotRange *)otherRange; 58 | /// @} 59 | 60 | /// @name Range Comparison 61 | /// @{ 62 | -(CPTPlotRangeComparisonResult)compareToNumber:(NSNumber *)number; 63 | -(CPTPlotRangeComparisonResult)compareToDecimal:(NSDecimal)number; 64 | -(CPTPlotRangeComparisonResult)compareToDouble:(double)number; 65 | /// @} 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTLineCap.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | /// @file 5 | 6 | @class CPTLineStyle; 7 | @class CPTFill; 8 | 9 | /** 10 | * @brief Line cap types. 11 | **/ 12 | typedef enum _CPTLineCapType { 13 | CPTLineCapTypeNone, ///< No line cap. 14 | CPTLineCapTypeOpenArrow, ///< Open arrow line cap. 15 | CPTLineCapTypeSolidArrow, ///< Solid arrow line cap. 16 | CPTLineCapTypeSweptArrow, ///< Swept arrow line cap. 17 | CPTLineCapTypeRectangle, ///< Rectangle line cap. 18 | CPTLineCapTypeEllipse, ///< Elliptical line cap. 19 | CPTLineCapTypeDiamond, ///< Diamond line cap. 20 | CPTLineCapTypePentagon, ///< Pentagon line cap. 21 | CPTLineCapTypeHexagon, ///< Hexagon line cap. 22 | CPTLineCapTypeBar, ///< Bar line cap. 23 | CPTLineCapTypeCross, ///< X line cap. 24 | CPTLineCapTypeSnow, ///< Snowflake line cap. 25 | CPTLineCapTypeCustom ///< Custom line cap. 26 | } 27 | CPTLineCapType; 28 | 29 | @interface CPTLineCap : NSObject { 30 | @private 31 | CGSize size; 32 | CPTLineCapType lineCapType; 33 | CPTLineStyle *lineStyle; 34 | CPTFill *fill; 35 | CGPathRef cachedLineCapPath; 36 | CGPathRef customLineCapPath; 37 | BOOL usesEvenOddClipRule; 38 | } 39 | 40 | @property (nonatomic, readwrite, assign) CGSize size; 41 | @property (nonatomic, readwrite, assign) CPTLineCapType lineCapType; 42 | @property (nonatomic, readwrite, retain) CPTLineStyle *lineStyle; 43 | @property (nonatomic, readwrite, retain) CPTFill *fill; 44 | @property (nonatomic, readwrite, assign) CGPathRef customLineCapPath; 45 | @property (nonatomic, readwrite, assign) BOOL usesEvenOddClipRule; 46 | 47 | /// @name Factory Methods 48 | /// @{ 49 | +(CPTLineCap *)lineCap; 50 | +(CPTLineCap *)openArrowPlotLineCap; 51 | +(CPTLineCap *)solidArrowPlotLineCap; 52 | +(CPTLineCap *)sweptArrowPlotLineCap; 53 | +(CPTLineCap *)rectanglePlotLineCap; 54 | +(CPTLineCap *)ellipsePlotLineCap; 55 | +(CPTLineCap *)diamondPlotLineCap; 56 | +(CPTLineCap *)pentagonPlotLineCap; 57 | +(CPTLineCap *)hexagonPlotLineCap; 58 | +(CPTLineCap *)barPlotLineCap; 59 | +(CPTLineCap *)crossPlotLineCap; 60 | +(CPTLineCap *)snowPlotLineCap; 61 | +(CPTLineCap *)customLineCapWithPath:(CGPathRef)aPath; 62 | /// @} 63 | 64 | /// @name Drawing 65 | /// @{ 66 | -(void)renderAsVectorInContext:(CGContextRef)context atPoint:(CGPoint)center inDirection:(CGPoint)direction; 67 | /// @} 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/KSAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // KSAppDelegate.m 3 | // KSUtilitiesDemo 4 | // 5 | // Created by kesalin on 6/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import "KSAppDelegate.h" 10 | #import "KSExceptionHandler.h" 11 | 12 | @implementation KSAppDelegate 13 | 14 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 15 | { 16 | // Override point for customization after application launch. 17 | 18 | #if !TARGET_IPHONE_SIMULATOR 19 | 20 | KSExceptionHandler * exceptionHandler = [KSExceptionHandler sharedInstance]; 21 | exceptionHandler.parentViewController = self.window.rootViewController; 22 | [exceptionHandler setOrCheckExceptionHandler]; 23 | 24 | #endif 25 | 26 | return YES; 27 | } 28 | 29 | - (void)applicationWillResignActive:(UIApplication *)application 30 | { 31 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 32 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 33 | } 34 | 35 | - (void)applicationDidEnterBackground:(UIApplication *)application 36 | { 37 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 38 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 39 | } 40 | 41 | - (void)applicationWillEnterForeground:(UIApplication *)application 42 | { 43 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 44 | } 45 | 46 | - (void)applicationDidBecomeActive:(UIApplication *)application 47 | { 48 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 49 | } 50 | 51 | - (void)applicationWillTerminate:(UIApplication *)application 52 | { 53 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 54 | } 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/KSAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // KSAppDelegate.m 3 | // CorePlotDemo 4 | // 5 | // Created by kesalin on 2/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import "KSAppDelegate.h" 10 | 11 | #import "KSViewController.h" 12 | 13 | @implementation KSAppDelegate 14 | 15 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 16 | { 17 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 18 | self.viewController = [[KSViewController alloc] initWithNibName:@"KSViewController" bundle:nil]; 19 | 20 | if ([self.window respondsToSelector:@selector(setRootViewController:)]) { 21 | self.window.rootViewController = self.viewController; 22 | } 23 | 24 | else { 25 | [self.window addSubview:self.viewController.view]; 26 | } 27 | 28 | [self.window makeKeyAndVisible]; 29 | return YES; 30 | } 31 | 32 | - (void)applicationWillResignActive:(UIApplication *)application 33 | { 34 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 35 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 36 | } 37 | 38 | - (void)applicationDidEnterBackground:(UIApplication *)application 39 | { 40 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 41 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 42 | } 43 | 44 | - (void)applicationWillEnterForeground:(UIApplication *)application 45 | { 46 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 47 | } 48 | 49 | - (void)applicationDidBecomeActive:(UIApplication *)application 50 | { 51 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 52 | } 53 | 54 | - (void)applicationWillTerminate:(UIApplication *)application 55 | { 56 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 57 | } 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /SQLiteDemo/SQLiteDemo/KSAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // KSAppDelegate.m 3 | // SQLiteDemo 4 | // 5 | // Created by kesalin on 3/28/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import "KSAppDelegate.h" 10 | 11 | #import "KSViewController.h" 12 | 13 | @implementation KSAppDelegate 14 | 15 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 16 | { 17 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 18 | // Override point for customization after application launch. 19 | if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 20 | self.viewController = [[KSViewController alloc] initWithNibName:@"KSViewController_iPhone" bundle:nil]; 21 | } else { 22 | self.viewController = [[KSViewController alloc] initWithNibName:@"KSViewController_iPad" bundle:nil]; 23 | } 24 | self.window.rootViewController = self.viewController; 25 | [self.window makeKeyAndVisible]; 26 | return YES; 27 | } 28 | 29 | - (void)applicationWillResignActive:(UIApplication *)application 30 | { 31 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 32 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 33 | } 34 | 35 | - (void)applicationDidEnterBackground:(UIApplication *)application 36 | { 37 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 38 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 39 | } 40 | 41 | - (void)applicationWillEnterForeground:(UIApplication *)application 42 | { 43 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 44 | } 45 | 46 | - (void)applicationDidBecomeActive:(UIApplication *)application 47 | { 48 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 49 | } 50 | 51 | - (void)applicationWillTerminate:(UIApplication *)application 52 | { 53 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 54 | } 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/KSViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // KSViewController.m 3 | // KSNetworkDemo 4 | // 5 | // Created by kesalin on 13/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import "KSViewController.h" 10 | #import "KSSocketViewController.h" 11 | 12 | @interface KSViewController () 13 | { 14 | NSDictionary * _items; 15 | } 16 | @end 17 | 18 | @implementation KSViewController 19 | 20 | - (void)viewDidLoad 21 | { 22 | [super viewDidLoad]; 23 | 24 | _items = @{ 25 | @"BSD Socket Demo": @"KSSocketViewController", 26 | @"CFNetwork Demo": @"KSCFNetworkViewController", 27 | @"NSStream Demo" : @"KSNSStreamViewController" 28 | }; 29 | 30 | self.mainTableView.dataSource = self; 31 | self.mainTableView.delegate = self; 32 | } 33 | 34 | - (void)didReceiveMemoryWarning 35 | { 36 | [super didReceiveMemoryWarning]; 37 | // Dispose of any resources that can be recreated. 38 | } 39 | 40 | - (id) keyInDictionary:(NSDictionary *)dict atIndex:(NSInteger)index 41 | { 42 | NSArray * keys = [dict allKeys]; 43 | if (index >= [keys count]) { 44 | NSLog(@" >> Error: index out of bounds. %s", __FUNCTION__); 45 | return nil; 46 | } 47 | 48 | return keys[index]; 49 | } 50 | 51 | #pragma mark - 52 | #pragma mark UITableViewDataSource 53 | 54 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 55 | { 56 | return [_items count]; 57 | } 58 | 59 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 60 | { 61 | static NSString * CellIdentifier = @"NetworkCellIdentifier"; 62 | UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 63 | if (cell == nil) { 64 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 65 | cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 66 | } 67 | 68 | NSString * key = [self keyInDictionary:_items atIndex:indexPath.row]; 69 | cell.textLabel.text = key; 70 | 71 | return cell; 72 | } 73 | 74 | #pragma mark - 75 | #pragma mark UITableViewDelegate 76 | 77 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 78 | { 79 | NSString * key = [self keyInDictionary:_items atIndex:indexPath.row]; 80 | NSString * controllerName = [_items objectForKey:key]; 81 | 82 | Class controllerClass = NSClassFromString(controllerName); 83 | if (controllerClass != nil) { 84 | id controller = [[controllerClass alloc] init]; 85 | [self.navigationController pushViewController:controller animated:YES]; 86 | } 87 | } 88 | 89 | @end 90 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTPlotSymbol.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | /// @file 5 | 6 | @class CPTLineStyle; 7 | @class CPTFill; 8 | @class CPTShadow; 9 | 10 | /** 11 | * @brief Plot symbol types. 12 | **/ 13 | typedef enum _CPTPlotSymbolType { 14 | CPTPlotSymbolTypeNone, ///< No symbol. 15 | CPTPlotSymbolTypeRectangle, ///< Rectangle symbol. 16 | CPTPlotSymbolTypeEllipse, ///< Elliptical symbol. 17 | CPTPlotSymbolTypeDiamond, ///< Diamond symbol. 18 | CPTPlotSymbolTypeTriangle, ///< Triangle symbol. 19 | CPTPlotSymbolTypeStar, ///< 5-point star symbol. 20 | CPTPlotSymbolTypePentagon, ///< Pentagon symbol. 21 | CPTPlotSymbolTypeHexagon, ///< Hexagon symbol. 22 | CPTPlotSymbolTypeCross, ///< X symbol. 23 | CPTPlotSymbolTypePlus, ///< Plus symbol. 24 | CPTPlotSymbolTypeDash, ///< Dash symbol. 25 | CPTPlotSymbolTypeSnow, ///< Snowflake symbol. 26 | CPTPlotSymbolTypeCustom ///< Custom symbol. 27 | } 28 | CPTPlotSymbolType; 29 | 30 | @interface CPTPlotSymbol : NSObject { 31 | @private 32 | CGPoint anchorPoint; 33 | CGSize size; 34 | CPTPlotSymbolType symbolType; 35 | CPTLineStyle *lineStyle; 36 | CPTFill *fill; 37 | CGPathRef cachedSymbolPath; 38 | CGPathRef customSymbolPath; 39 | BOOL usesEvenOddClipRule; 40 | CGLayerRef cachedLayer; 41 | CPTShadow *shadow; 42 | } 43 | 44 | @property (nonatomic, readwrite, assign) CGPoint anchorPoint; 45 | @property (nonatomic, readwrite, assign) CGSize size; 46 | @property (nonatomic, readwrite, assign) CPTPlotSymbolType symbolType; 47 | @property (nonatomic, readwrite, retain) CPTLineStyle *lineStyle; 48 | @property (nonatomic, readwrite, retain) CPTFill *fill; 49 | @property (nonatomic, readwrite, copy) CPTShadow *shadow; 50 | @property (nonatomic, readwrite, assign) CGPathRef customSymbolPath; 51 | @property (nonatomic, readwrite, assign) BOOL usesEvenOddClipRule; 52 | 53 | /// @name Factory Methods 54 | /// @{ 55 | +(CPTPlotSymbol *)plotSymbol; 56 | +(CPTPlotSymbol *)crossPlotSymbol; 57 | +(CPTPlotSymbol *)ellipsePlotSymbol; 58 | +(CPTPlotSymbol *)rectanglePlotSymbol; 59 | +(CPTPlotSymbol *)plusPlotSymbol; 60 | +(CPTPlotSymbol *)starPlotSymbol; 61 | +(CPTPlotSymbol *)diamondPlotSymbol; 62 | +(CPTPlotSymbol *)trianglePlotSymbol; 63 | +(CPTPlotSymbol *)pentagonPlotSymbol; 64 | +(CPTPlotSymbol *)hexagonPlotSymbol; 65 | +(CPTPlotSymbol *)dashPlotSymbol; 66 | +(CPTPlotSymbol *)snowPlotSymbol; 67 | +(CPTPlotSymbol *)customPlotSymbolWithPath:(CGPathRef)aPath; 68 | /// @} 69 | 70 | /// @name Drawing 71 | /// @{ 72 | -(void)renderInContext:(CGContextRef)context atPoint:(CGPoint)center scale:(CGFloat)scale alignToPixels:(BOOL)alignToPixels; 73 | -(void)renderAsVectorInContext:(CGContextRef)context atPoint:(CGPoint)center scale:(CGFloat)scale; 74 | /// @} 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/KSUtilities/KSErrorHandler.m: -------------------------------------------------------------------------------- 1 | // 2 | // KSErrorHandler.m 3 | // KSUtilitiesDemo 4 | // 5 | // Created by kesalin on 6/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import "KSErrorHandler.h" 10 | #import "KSLog.h" 11 | 12 | @implementation KSErrorHandler 13 | 14 | static NSMutableArray * retainedDelegates = nil; 15 | 16 | - (id)initWithError:(NSError *)error isFatal:(BOOL)isFatalError 17 | { 18 | self = [super init]; 19 | if (self) { 20 | self.error = error; 21 | self.isFatal = isFatalError; 22 | } 23 | 24 | return self; 25 | } 26 | 27 | #pragma mark - 28 | #pragma mark UIAlertViewDelegate 29 | 30 | -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 31 | { 32 | if (buttonIndex != [alertView cancelButtonIndex]) 33 | { 34 | NSString * buttonTitle = [alertView buttonTitleAtIndex:buttonIndex]; 35 | NSInteger recoveryIndex = [[self.error localizedRecoveryOptions] indexOfObject:buttonTitle]; 36 | if (recoveryIndex != NSNotFound) 37 | { 38 | if ([[self.error recoveryAttempter] attemptRecoveryFromError:self.error 39 | optionIndex:recoveryIndex] == NO) 40 | { 41 | // Redisplay alert since recovery attempt failed 42 | [KSErrorHandler handleError:self.error isFatal:self.isFatal]; 43 | } 44 | } 45 | } 46 | else 47 | { 48 | // Cancel button clicked 49 | // 50 | if (self.isFatal) 51 | { 52 | // In case of a fatal error, abort execution 53 | abort(); 54 | // exit(0); 55 | } 56 | } 57 | 58 | // Job is finished, release this delegate 59 | [retainedDelegates removeObject:self]; 60 | } 61 | 62 | + (void)handleError:(NSError *)error isFatal:(BOOL)isFatal 63 | { 64 | NSString *localizedCancelTitle = NSLocalizedString(@"Dismiss", nil); 65 | if (isFatal) 66 | localizedCancelTitle = NSLocalizedString(@"Shut Down", nil); 67 | 68 | // Notify the user 69 | KSErrorHandler *delegate = [[KSErrorHandler alloc] initWithError:error isFatal:isFatal]; 70 | if (!retainedDelegates) { 71 | retainedDelegates = [[NSMutableArray alloc] init]; 72 | } 73 | [retainedDelegates addObject:delegate]; 74 | 75 | UIAlertView * alert = [[UIAlertView alloc] initWithTitle:[error localizedDescription] 76 | message:[error localizedFailureReason] 77 | delegate:delegate 78 | cancelButtonTitle:localizedCancelTitle 79 | otherButtonTitles:nil]; 80 | 81 | if ([error recoveryAttempter]) 82 | { 83 | // Append the recovery suggestion to the error message 84 | alert.message = [NSString stringWithFormat:@"%@\n%@", alert.message, error.localizedRecoverySuggestion]; 85 | // Add buttons for the recovery options 86 | for (NSString * option in error.localizedRecoveryOptions) 87 | { 88 | [alert addButtonWithTitle:option]; 89 | } 90 | } 91 | 92 | 93 | [alert show]; 94 | 95 | // Log to standard out 96 | KSLog(@"Unhandled error:\n%@, %@", error, [error userInfo]); 97 | } 98 | 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTLayer.h: -------------------------------------------------------------------------------- 1 | #import "CPTDefinitions.h" 2 | #import "CPTResponder.h" 3 | #import 4 | #import 5 | 6 | @class CPTGraph; 7 | @class CPTShadow; 8 | 9 | /// @name Layout 10 | /// @{ 11 | 12 | /** @brief Notification sent by all layers when the layer @link CALayer::bounds bounds @endlink change. 13 | * @ingroup notification 14 | **/ 15 | extern NSString *const CPTLayerBoundsDidChangeNotification; 16 | 17 | /// @} 18 | 19 | @interface CPTLayer : CALayer { 20 | @private 21 | CGFloat paddingLeft; 22 | CGFloat paddingTop; 23 | CGFloat paddingRight; 24 | CGFloat paddingBottom; 25 | BOOL masksToBorder; 26 | CPTShadow *shadow; 27 | BOOL renderingRecursively; 28 | BOOL useFastRendering; 29 | __cpt_weak CPTGraph *graph; 30 | CGPathRef outerBorderPath; 31 | CGPathRef innerBorderPath; 32 | id identifier; 33 | } 34 | 35 | /// @name Graph 36 | /// @{ 37 | @property (nonatomic, readwrite, cpt_weak_property) __cpt_weak CPTGraph *graph; 38 | /// @} 39 | 40 | /// @name Padding 41 | /// @{ 42 | @property (nonatomic, readwrite) CGFloat paddingLeft; 43 | @property (nonatomic, readwrite) CGFloat paddingTop; 44 | @property (nonatomic, readwrite) CGFloat paddingRight; 45 | @property (nonatomic, readwrite) CGFloat paddingBottom; 46 | /// @} 47 | 48 | /// @name Drawing 49 | /// @{ 50 | @property (readwrite, assign) CGFloat contentsScale; 51 | @property (nonatomic, readonly, assign) BOOL useFastRendering; 52 | @property (nonatomic, readwrite, copy) CPTShadow *shadow; 53 | /// @} 54 | 55 | /// @name Masking 56 | /// @{ 57 | @property (nonatomic, readwrite, assign) BOOL masksToBorder; 58 | @property (nonatomic, readwrite, assign) CGPathRef outerBorderPath; 59 | @property (nonatomic, readwrite, assign) CGPathRef innerBorderPath; 60 | @property (nonatomic, readonly, assign) CGPathRef maskingPath; 61 | @property (nonatomic, readonly, assign) CGPathRef sublayerMaskingPath; 62 | /// @} 63 | 64 | /// @name Identification 65 | /// @{ 66 | @property (nonatomic, readwrite, copy) id identifier; 67 | /// @} 68 | 69 | /// @name Layout 70 | /// @{ 71 | @property (readonly) NSSet *sublayersExcludedFromAutomaticLayout; 72 | /// @} 73 | 74 | /// @name Initialization 75 | /// @{ 76 | -(id)initWithFrame:(CGRect)newFrame; 77 | /// @} 78 | 79 | /// @name Drawing 80 | /// @{ 81 | -(void)renderAsVectorInContext:(CGContextRef)context; 82 | -(void)recursivelyRenderInContext:(CGContextRef)context; 83 | -(void)layoutAndRenderInContext:(CGContextRef)context; 84 | -(NSData *)dataForPDFRepresentationOfLayer; 85 | /// @} 86 | 87 | /// @name Masking 88 | /// @{ 89 | -(void)applySublayerMaskToContext:(CGContextRef)context forSublayer:(CPTLayer *)sublayer withOffset:(CGPoint)offset; 90 | -(void)applyMaskToContext:(CGContextRef)context; 91 | /// @} 92 | 93 | /// @name Layout 94 | /// @{ 95 | -(void)pixelAlign; 96 | -(void)sublayerMarginLeft:(CGFloat *)left top:(CGFloat *)top right:(CGFloat *)right bottom:(CGFloat *)bottom; 97 | /// @} 98 | 99 | /// @name Information 100 | /// @{ 101 | -(void)logLayers; 102 | /// @} 103 | 104 | @end 105 | 106 | /// @cond 107 | // for MacOS 10.6 SDK compatibility 108 | #if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE 109 | #else 110 | #if MAC_OS_X_VERSION_MAX_ALLOWED < 1070 111 | @interface CALayer(CPTExtensions) 112 | 113 | @property (readwrite) CGFloat contentsScale; 114 | 115 | @end 116 | #endif 117 | #endif 118 | 119 | /// @endcond 120 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTNumericData.h: -------------------------------------------------------------------------------- 1 | #import "CPTNumericDataType.h" 2 | #import 3 | 4 | @interface CPTNumericData : NSObject { 5 | @protected 6 | NSData *data; 7 | CPTNumericDataType dataType; 8 | NSArray *shape; // array of dimension shapes (NSNumber) 9 | CPTDataOrder dataOrder; 10 | } 11 | 12 | /// @name Data Buffer 13 | /// @{ 14 | @property (copy, readonly) NSData *data; 15 | @property (readonly) const void *bytes; 16 | @property (readonly) NSUInteger length; 17 | /// @} 18 | 19 | /// @name Data Format 20 | /// @{ 21 | @property (assign, readonly) CPTNumericDataType dataType; 22 | @property (readonly) CPTDataTypeFormat dataTypeFormat; 23 | @property (readonly) size_t sampleBytes; 24 | @property (readonly) CFByteOrder byteOrder; 25 | /// @} 26 | 27 | /// @name Dimensions 28 | /// @{ 29 | @property (copy, readonly) NSArray *shape; 30 | @property (readonly) NSUInteger numberOfDimensions; 31 | @property (readonly) NSUInteger numberOfSamples; 32 | @property (readonly) CPTDataOrder dataOrder; 33 | /// @} 34 | 35 | /// @name Factory Methods 36 | /// @{ 37 | +(id)numericDataWithData:(NSData *)newData dataType:(CPTNumericDataType)newDataType shape:(NSArray *)shapeArray; 38 | +(id)numericDataWithData:(NSData *)newData dataTypeString:(NSString *)newDataTypeString shape:(NSArray *)shapeArray; 39 | +(id)numericDataWithArray:(NSArray *)newData dataType:(CPTNumericDataType)newDataType shape:(NSArray *)shapeArray; 40 | +(id)numericDataWithArray:(NSArray *)newData dataTypeString:(NSString *)newDataTypeString shape:(NSArray *)shapeArray; 41 | 42 | +(id)numericDataWithData:(NSData *)newData dataType:(CPTNumericDataType)newDataType shape:(NSArray *)shapeArray dataOrder:(CPTDataOrder)order; 43 | +(id)numericDataWithData:(NSData *)newData dataTypeString:(NSString *)newDataTypeString shape:(NSArray *)shapeArray dataOrder:(CPTDataOrder)order; 44 | +(id)numericDataWithArray:(NSArray *)newData dataType:(CPTNumericDataType)newDataType shape:(NSArray *)shapeArray dataOrder:(CPTDataOrder)order; 45 | +(id)numericDataWithArray:(NSArray *)newData dataTypeString:(NSString *)newDataTypeString shape:(NSArray *)shapeArray dataOrder:(CPTDataOrder)order; 46 | /// @} 47 | 48 | /// @name Initialization 49 | /// @{ 50 | -(id)initWithData:(NSData *)newData dataType:(CPTNumericDataType)newDataType shape:(NSArray *)shapeArray; 51 | -(id)initWithData:(NSData *)newData dataTypeString:(NSString *)newDataTypeString shape:(NSArray *)shapeArray; 52 | -(id)initWithArray:(NSArray *)newData dataType:(CPTNumericDataType)newDataType shape:(NSArray *)shapeArray; 53 | -(id)initWithArray:(NSArray *)newData dataTypeString:(NSString *)newDataTypeString shape:(NSArray *)shapeArray; 54 | 55 | -(id)initWithData:(NSData *)newData dataType:(CPTNumericDataType)newDataType shape:(NSArray *)shapeArray dataOrder:(CPTDataOrder)order; 56 | -(id)initWithData:(NSData *)newData dataTypeString:(NSString *)newDataTypeString shape:(NSArray *)shapeArray dataOrder:(CPTDataOrder)order; 57 | -(id)initWithArray:(NSArray *)newData dataType:(CPTNumericDataType)newDataType shape:(NSArray *)shapeArray dataOrder:(CPTDataOrder)order; 58 | -(id)initWithArray:(NSArray *)newData dataTypeString:(NSString *)newDataTypeString shape:(NSArray *)shapeArray dataOrder:(CPTDataOrder)order; 59 | /// @} 60 | 61 | /// @name Samples 62 | /// @{ 63 | -(NSUInteger)sampleIndex:(NSUInteger)idx, ...; 64 | -(void *)samplePointer:(NSUInteger)sample; 65 | -(void *)samplePointerAtIndex:(NSUInteger)idx, ...; 66 | -(NSNumber *)sampleValue:(NSUInteger)sample; 67 | -(NSNumber *)sampleValueAtIndex:(NSUInteger)idx, ...; 68 | -(NSArray *)sampleArray; 69 | /// @} 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTGradient.h: -------------------------------------------------------------------------------- 1 | // Based on CTGradient (http://blog.oofn.net/2006/01/15/gradients-in-cocoa/) 2 | // CTGradient is in public domain (Thanks Chad Weider!) 3 | 4 | /// @file 5 | 6 | #import "CPTDefinitions.h" 7 | #import 8 | 9 | /** 10 | * @brief A structure representing one node in a linked list of RGBA colors. 11 | **/ 12 | typedef struct _CPTGradientElement { 13 | CPTRGBAColor color; ///< Color 14 | CGFloat position; ///< Gradient position (0 ≤ @par{position} ≤ 1) 15 | 16 | struct _CPTGradientElement *nextElement; ///< Pointer to the next CPTGradientElement in the list (last element == @NULL) 17 | } 18 | CPTGradientElement; 19 | 20 | /** 21 | * @brief Enumeration of blending modes 22 | **/ 23 | typedef enum _CPTBlendingMode { 24 | CPTLinearBlendingMode, ///< Linear blending mode 25 | CPTChromaticBlendingMode, ///< Chromatic blending mode 26 | CPTInverseChromaticBlendingMode ///< Inverse chromatic blending mode 27 | } 28 | CPTGradientBlendingMode; 29 | 30 | /** 31 | * @brief Enumeration of gradient types 32 | **/ 33 | typedef enum _CPTGradientType { 34 | CPTGradientTypeAxial, ///< Axial gradient 35 | CPTGradientTypeRadial ///< Radial gradient 36 | } 37 | CPTGradientType; 38 | 39 | @class CPTColorSpace; 40 | @class CPTColor; 41 | 42 | @interface CPTGradient : NSObject { 43 | @private 44 | CPTColorSpace *colorspace; 45 | CPTGradientElement *elementList; 46 | CPTGradientBlendingMode blendingMode; 47 | CGFunctionRef gradientFunction; 48 | CGFloat angle; // angle in degrees 49 | CPTGradientType gradientType; 50 | } 51 | 52 | @property (nonatomic, readonly, assign) CPTGradientBlendingMode blendingMode; 53 | @property (nonatomic, readwrite, assign) CGFloat angle; 54 | @property (nonatomic, readwrite, assign) CPTGradientType gradientType; 55 | 56 | /// @name Factory Methods 57 | /// @{ 58 | +(CPTGradient *)gradientWithBeginningColor:(CPTColor *)begin endingColor:(CPTColor *)end; 59 | +(CPTGradient *)gradientWithBeginningColor:(CPTColor *)begin endingColor:(CPTColor *)end beginningPosition:(CGFloat)beginningPosition endingPosition:(CGFloat)endingPosition; 60 | 61 | +(CPTGradient *)aquaSelectedGradient; 62 | +(CPTGradient *)aquaNormalGradient; 63 | +(CPTGradient *)aquaPressedGradient; 64 | 65 | +(CPTGradient *)unifiedSelectedGradient; 66 | +(CPTGradient *)unifiedNormalGradient; 67 | +(CPTGradient *)unifiedPressedGradient; 68 | +(CPTGradient *)unifiedDarkGradient; 69 | 70 | +(CPTGradient *)sourceListSelectedGradient; 71 | +(CPTGradient *)sourceListUnselectedGradient; 72 | 73 | +(CPTGradient *)rainbowGradient; 74 | +(CPTGradient *)hydrogenSpectrumGradient; 75 | /// @} 76 | 77 | /// @name Modification 78 | /// @{ 79 | -(CPTGradient *)gradientWithAlphaComponent:(CGFloat)alpha; 80 | -(CPTGradient *)gradientWithBlendingMode:(CPTGradientBlendingMode)mode; 81 | 82 | -(CPTGradient *)addColorStop:(CPTColor *)color atPosition:(CGFloat)position; // positions given relative to [0,1] 83 | -(CPTGradient *)removeColorStopAtIndex:(NSUInteger)idx; 84 | -(CPTGradient *)removeColorStopAtPosition:(CGFloat)position; 85 | /// @} 86 | 87 | /// @name Information 88 | /// @{ 89 | -(CGColorRef)newColorStopAtIndex:(NSUInteger)idx; 90 | -(CGColorRef)newColorAtPosition:(CGFloat)position; 91 | /// @} 92 | 93 | /// @name Drawing 94 | /// @{ 95 | -(void)drawSwatchInRect:(CGRect)rect inContext:(CGContextRef)context; 96 | -(void)fillRect:(CGRect)rect inContext:(CGContextRef)context; 97 | -(void)fillPathInContext:(CGContextRef)context; 98 | /// @} 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTRangePlot.h: -------------------------------------------------------------------------------- 1 | #import "CPTDefinitions.h" 2 | #import "CPTPlot.h" 3 | #import 4 | 5 | @class CPTLineStyle; 6 | @class CPTFill; 7 | @class CPTRangePlot; 8 | 9 | /// @ingroup plotBindingsRangePlot 10 | /// @{ 11 | extern NSString *const CPTRangePlotBindingXValues; 12 | extern NSString *const CPTRangePlotBindingYValues; 13 | extern NSString *const CPTRangePlotBindingHighValues; 14 | extern NSString *const CPTRangePlotBindingLowValues; 15 | extern NSString *const CPTRangePlotBindingLeftValues; 16 | extern NSString *const CPTRangePlotBindingRightValues; 17 | extern NSString *const CPTRangePlotBindingBarLineStyles; 18 | /// @} 19 | 20 | /** 21 | * @brief Enumeration of range plot data source field types 22 | **/ 23 | typedef enum _CPTRangePlotField { 24 | CPTRangePlotFieldX, ///< X values. 25 | CPTRangePlotFieldY, ///< Y values. 26 | CPTRangePlotFieldHigh, ///< relative High values. 27 | CPTRangePlotFieldLow, ///< relative Low values. 28 | CPTRangePlotFieldLeft, ///< relative Left values. 29 | CPTRangePlotFieldRight, ///< relative Right values. 30 | } 31 | CPTRangePlotField; 32 | 33 | #pragma mark - 34 | 35 | /** 36 | * @brief A range plot data source. 37 | **/ 38 | @protocol CPTRangePlotDataSource 39 | @optional 40 | 41 | /// @name Bar Style 42 | /// @{ 43 | 44 | /** @brief @optional Gets a range of bar line styles for the given range plot. 45 | * @param plot The range plot. 46 | * @param indexRange The range of the data indexes of interest. 47 | * @return An array of line styles. 48 | **/ 49 | -(NSArray *)barLineStylesForRangePlot:(CPTRangePlot *)plot recordIndexRange:(NSRange)indexRange; 50 | 51 | /** @brief @optional Gets a bar line style for the given range plot. 52 | * This method will not be called if 53 | * @link CPTRangePlotDataSource::barLineStylesForRangePlot:recordIndexRange: -barLineStylesForRangePlot:recordIndexRange: @endlink 54 | * is also implemented in the datasource. 55 | * @param plot The range plot. 56 | * @param idx The data index of interest. 57 | * @return The bar line style for the bar with the given index. If the data source returns @nil, the default line style is used. 58 | * If the data source returns an NSNull object, no line is drawn. 59 | **/ 60 | -(CPTLineStyle *)barLineStyleForRangePlot:(CPTRangePlot *)plot recordIndex:(NSUInteger)idx; 61 | 62 | /// @} 63 | 64 | @end 65 | 66 | #pragma mark - 67 | 68 | /** 69 | * @brief Range plot delegate. 70 | **/ 71 | @protocol CPTRangePlotDelegate 72 | 73 | @optional 74 | 75 | /// @name Point Selection 76 | /// @{ 77 | 78 | /** @brief @optional Informs the delegate that a bar was 79 | * @if MacOnly clicked. @endif 80 | * @if iOSOnly touched. @endif 81 | * @param plot The range plot. 82 | * @param idx The index of the 83 | * @if MacOnly clicked bar. @endif 84 | * @if iOSOnly touched bar. @endif 85 | **/ 86 | -(void)rangePlot:(CPTRangePlot *)plot rangeWasSelectedAtRecordIndex:(NSUInteger)idx; 87 | 88 | /** @brief @optional Informs the delegate that a bar was 89 | * @if MacOnly clicked. @endif 90 | * @if iOSOnly touched. @endif 91 | * @param plot The range plot. 92 | * @param idx The index of the 93 | * @if MacOnly clicked bar. @endif 94 | * @if iOSOnly touched bar. @endif 95 | * @param event The event that triggered the selection. 96 | **/ 97 | -(void)rangePlot:(CPTRangePlot *)plot rangeWasSelectedAtRecordIndex:(NSUInteger)idx withEvent:(CPTNativeEvent *)event; 98 | 99 | /// @} 100 | 101 | @end 102 | 103 | #pragma mark - 104 | 105 | @interface CPTRangePlot : CPTPlot { 106 | CPTLineStyle *barLineStyle; 107 | CGFloat barWidth; 108 | CGFloat gapHeight; 109 | CGFloat gapWidth; 110 | CPTFill *areaFill; 111 | } 112 | 113 | /// @name Appearance 114 | /// @{ 115 | @property (nonatomic, readwrite, copy) CPTLineStyle *barLineStyle; 116 | @property (nonatomic, readwrite) CGFloat barWidth; 117 | @property (nonatomic, readwrite) CGFloat gapHeight; 118 | @property (nonatomic, readwrite) CGFloat gapWidth; 119 | /// @} 120 | 121 | /// @name Drawing 122 | /// @{ 123 | @property (nonatomic, copy) CPTFill *areaFill; 124 | /// @} 125 | 126 | @end 127 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTGraph.h: -------------------------------------------------------------------------------- 1 | // Abstract class 2 | #import "CPTBorderedLayer.h" 3 | #import "CPTDefinitions.h" 4 | 5 | /// @file 6 | 7 | @class CPTAxisSet; 8 | @class CPTGraphHostingView; 9 | @class CPTLegend; 10 | @class CPTPlot; 11 | @class CPTPlotAreaFrame; 12 | @class CPTPlotSpace; 13 | @class CPTTheme; 14 | @class CPTTextStyle; 15 | @class CPTLayerAnnotation; 16 | 17 | /// @name Graph 18 | /// @{ 19 | 20 | /** @brief Notification sent by various objects to tell the graph it should redraw itself. 21 | * @ingroup notification 22 | **/ 23 | extern NSString *const CPTGraphNeedsRedrawNotification; 24 | 25 | /// @} 26 | 27 | /** 28 | * @brief Enumeration of graph layers. 29 | **/ 30 | typedef enum _CPTGraphLayerType { 31 | CPTGraphLayerTypeMinorGridLines, ///< Minor grid lines. 32 | CPTGraphLayerTypeMajorGridLines, ///< Major grid lines. 33 | CPTGraphLayerTypeAxisLines, ///< Axis lines. 34 | CPTGraphLayerTypePlots, ///< Plots. 35 | CPTGraphLayerTypeAxisLabels, ///< Axis labels. 36 | CPTGraphLayerTypeAxisTitles ///< Axis titles. 37 | } 38 | CPTGraphLayerType; 39 | 40 | #pragma mark - 41 | 42 | @interface CPTGraph : CPTBorderedLayer { 43 | @private 44 | __cpt_weak CPTGraphHostingView *hostingView; 45 | CPTPlotAreaFrame *plotAreaFrame; 46 | NSMutableArray *plots; 47 | NSMutableArray *plotSpaces; 48 | NSString *title; 49 | CPTTextStyle *titleTextStyle; 50 | CPTRectAnchor titlePlotAreaFrameAnchor; 51 | CGPoint titleDisplacement; 52 | CPTLayerAnnotation *titleAnnotation; 53 | CPTLegend *legend; 54 | CPTLayerAnnotation *legendAnnotation; 55 | CPTRectAnchor legendAnchor; 56 | CGPoint legendDisplacement; 57 | } 58 | 59 | /// @name Hosting View 60 | /// @{ 61 | @property (nonatomic, readwrite, cpt_weak_property) __cpt_weak CPTGraphHostingView *hostingView; 62 | /// @} 63 | 64 | /// @name Title 65 | /// @{ 66 | @property (nonatomic, readwrite, copy) NSString *title; 67 | @property (nonatomic, readwrite, copy) CPTTextStyle *titleTextStyle; 68 | @property (nonatomic, readwrite, assign) CGPoint titleDisplacement; 69 | @property (nonatomic, readwrite, assign) CPTRectAnchor titlePlotAreaFrameAnchor; 70 | /// @} 71 | 72 | /// @name Layers 73 | /// @{ 74 | @property (nonatomic, readwrite, retain) CPTAxisSet *axisSet; 75 | @property (nonatomic, readwrite, retain) CPTPlotAreaFrame *plotAreaFrame; 76 | @property (nonatomic, readonly, retain) CPTPlotSpace *defaultPlotSpace; 77 | @property (nonatomic, readwrite, retain) NSArray *topDownLayerOrder; 78 | /// @} 79 | 80 | /// @name Legend 81 | /// @{ 82 | @property (nonatomic, readwrite, retain) CPTLegend *legend; 83 | @property (nonatomic, readwrite, assign) CPTRectAnchor legendAnchor; 84 | @property (nonatomic, readwrite, assign) CGPoint legendDisplacement; 85 | /// @} 86 | 87 | /// @name Data Source 88 | /// @{ 89 | -(void)reloadData; 90 | -(void)reloadDataIfNeeded; 91 | /// @} 92 | 93 | /// @name Retrieving Plots 94 | /// @{ 95 | -(NSArray *)allPlots; 96 | -(CPTPlot *)plotAtIndex:(NSUInteger)idx; 97 | -(CPTPlot *)plotWithIdentifier:(id)identifier; 98 | /// @} 99 | 100 | /// @name Adding and Removing Plots 101 | /// @{ 102 | -(void)addPlot:(CPTPlot *)plot; 103 | -(void)addPlot:(CPTPlot *)plot toPlotSpace:(CPTPlotSpace *)space; 104 | -(void)removePlot:(CPTPlot *)plot; 105 | -(void)removePlotWithIdentifier:(id)identifier; 106 | -(void)insertPlot:(CPTPlot *)plot atIndex:(NSUInteger)idx; 107 | -(void)insertPlot:(CPTPlot *)plot atIndex:(NSUInteger)idx intoPlotSpace:(CPTPlotSpace *)space; 108 | /// @} 109 | 110 | /// @name Retrieving Plot Spaces 111 | /// @{ 112 | -(NSArray *)allPlotSpaces; 113 | -(CPTPlotSpace *)plotSpaceAtIndex:(NSUInteger)idx; 114 | -(CPTPlotSpace *)plotSpaceWithIdentifier:(id)identifier; 115 | /// @} 116 | 117 | /// @name Adding and Removing Plot Spaces 118 | /// @{ 119 | -(void)addPlotSpace:(CPTPlotSpace *)space; 120 | -(void)removePlotSpace:(CPTPlotSpace *)plotSpace; 121 | /// @} 122 | 123 | /// @name Themes 124 | /// @{ 125 | -(void)applyTheme:(CPTTheme *)theme; 126 | /// @} 127 | 128 | @end 129 | 130 | #pragma mark - 131 | 132 | /** @category CPTGraph(AbstractFactoryMethods) 133 | * @brief CPTGraph abstract methods—must be overridden by subclasses 134 | **/ 135 | @interface CPTGraph(AbstractFactoryMethods) 136 | 137 | /// @name Factory Methods 138 | /// @{ 139 | -(CPTPlotSpace *)newPlotSpace; 140 | -(CPTAxisSet *)newAxisSet; 141 | /// @} 142 | 143 | @end 144 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTUtilities.h: -------------------------------------------------------------------------------- 1 | #import "CPTDefinitions.h" 2 | #import 3 | 4 | /// @file 5 | 6 | #if __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /// @name Convert NSDecimal to Primitive Types 11 | /// @{ 12 | int8_t CPTDecimalCharValue(NSDecimal decimalNumber); 13 | int16_t CPTDecimalShortValue(NSDecimal decimalNumber); 14 | int32_t CPTDecimalLongValue(NSDecimal decimalNumber); 15 | int64_t CPTDecimalLongLongValue(NSDecimal decimalNumber); 16 | int CPTDecimalIntValue(NSDecimal decimalNumber); 17 | NSInteger CPTDecimalIntegerValue(NSDecimal decimalNumber); 18 | 19 | uint8_t CPTDecimalUnsignedCharValue(NSDecimal decimalNumber); 20 | uint16_t CPTDecimalUnsignedShortValue(NSDecimal decimalNumber); 21 | uint32_t CPTDecimalUnsignedLongValue(NSDecimal decimalNumber); 22 | uint64_t CPTDecimalUnsignedLongLongValue(NSDecimal decimalNumber); 23 | unsigned int CPTDecimalUnsignedIntValue(NSDecimal decimalNumber); 24 | NSUInteger CPTDecimalUnsignedIntegerValue(NSDecimal decimalNumber); 25 | 26 | float CPTDecimalFloatValue(NSDecimal decimalNumber); 27 | double CPTDecimalDoubleValue(NSDecimal decimalNumber); 28 | CGFloat CPTDecimalCGFloatValue(NSDecimal decimalNumber); 29 | 30 | NSString *CPTDecimalStringValue(NSDecimal decimalNumber); 31 | 32 | /// @} 33 | 34 | /// @name Convert Primitive Types to NSDecimal 35 | /// @{ 36 | NSDecimal CPTDecimalFromChar(int8_t anInt); 37 | NSDecimal CPTDecimalFromShort(int16_t anInt); 38 | NSDecimal CPTDecimalFromLong(int32_t anInt); 39 | NSDecimal CPTDecimalFromLongLong(int64_t anInt); 40 | NSDecimal CPTDecimalFromInt(int i); 41 | NSDecimal CPTDecimalFromInteger(NSInteger i); 42 | 43 | NSDecimal CPTDecimalFromUnsignedChar(uint8_t i); 44 | NSDecimal CPTDecimalFromUnsignedShort(uint16_t i); 45 | NSDecimal CPTDecimalFromUnsignedLong(uint32_t i); 46 | NSDecimal CPTDecimalFromUnsignedLongLong(uint64_t i); 47 | NSDecimal CPTDecimalFromUnsignedInt(unsigned int i); 48 | NSDecimal CPTDecimalFromUnsignedInteger(NSUInteger i); 49 | 50 | NSDecimal CPTDecimalFromFloat(float aFloat); 51 | NSDecimal CPTDecimalFromDouble(double aDouble); 52 | NSDecimal CPTDecimalFromCGFloat(CGFloat aCGFloat); 53 | 54 | NSDecimal CPTDecimalFromString(NSString *stringRepresentation); 55 | 56 | /// @} 57 | 58 | /// @name NSDecimal Arithmetic 59 | /// @{ 60 | NSDecimal CPTDecimalAdd(NSDecimal leftOperand, NSDecimal rightOperand); 61 | NSDecimal CPTDecimalSubtract(NSDecimal leftOperand, NSDecimal rightOperand); 62 | NSDecimal CPTDecimalMultiply(NSDecimal leftOperand, NSDecimal rightOperand); 63 | NSDecimal CPTDecimalDivide(NSDecimal numerator, NSDecimal denominator); 64 | 65 | /// @} 66 | 67 | /// @name NSDecimal Comparison 68 | /// @{ 69 | BOOL CPTDecimalGreaterThan(NSDecimal leftOperand, NSDecimal rightOperand); 70 | BOOL CPTDecimalGreaterThanOrEqualTo(NSDecimal leftOperand, NSDecimal rightOperand); 71 | BOOL CPTDecimalLessThan(NSDecimal leftOperand, NSDecimal rightOperand); 72 | BOOL CPTDecimalLessThanOrEqualTo(NSDecimal leftOperand, NSDecimal rightOperand); 73 | BOOL CPTDecimalEquals(NSDecimal leftOperand, NSDecimal rightOperand); 74 | 75 | /// @} 76 | 77 | /// @name NSDecimal Utilities 78 | /// @{ 79 | NSDecimal CPTDecimalNaN(void); 80 | 81 | /// @} 82 | 83 | /// @name Ranges 84 | /// @{ 85 | NSRange CPTExpandedRange(NSRange range, NSInteger expandBy); 86 | 87 | /// @} 88 | 89 | /// @name Coordinates 90 | /// @{ 91 | CPTCoordinate CPTOrthogonalCoordinate(CPTCoordinate coord); 92 | 93 | /// @} 94 | 95 | /// @name Gradient Colors 96 | /// @{ 97 | CPTRGBAColor CPTRGBAColorFromCGColor(CGColorRef color); 98 | 99 | /// @} 100 | 101 | /// @name Quartz Pixel-Alignment Functions 102 | /// @{ 103 | CGPoint CPTAlignPointToUserSpace(CGContextRef context, CGPoint point); 104 | CGSize CPTAlignSizeToUserSpace(CGContextRef context, CGSize size); 105 | CGRect CPTAlignRectToUserSpace(CGContextRef context, CGRect rect); 106 | 107 | CGPoint CPTAlignIntegralPointToUserSpace(CGContextRef context, CGPoint point); 108 | CGRect CPTAlignIntegralRectToUserSpace(CGContextRef context, CGRect rect); 109 | 110 | /// @} 111 | 112 | /// @name String Formatting for Core Graphics Structs 113 | /// @{ 114 | NSString *CPTStringFromPoint(CGPoint point); 115 | NSString *CPTStringFromSize(CGSize size); 116 | NSString *CPTStringFromRect(CGRect rect); 117 | 118 | /// @} 119 | 120 | /// @name CGPoint Utilities 121 | /// @{ 122 | CGFloat squareOfDistanceBetweenPoints(CGPoint point1, CGPoint point2); 123 | 124 | /// @} 125 | 126 | #if __cplusplus 127 | } 128 | #endif 129 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/KSUtilities/KSImageCache.m: -------------------------------------------------------------------------------- 1 | // 2 | // KSImageCache.m 3 | // AmericanEnglish 4 | // 5 | // Created by kesalin on 6/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import "KSImageCache.h" 10 | #import "KSLog.h" 11 | 12 | @interface KSImageCache() 13 | { 14 | NSMutableDictionary * _imageDict; 15 | NSObject * _lockObject; 16 | } 17 | 18 | - (id)imageForKey:(NSString *)name; 19 | - (BOOL)setImage:(UIImage *)image forKey:(NSString *)name; 20 | - (BOOL)setImagePath:(NSString *)filepath forKey:(NSString *)name; 21 | - (void)removeImageForKey:(NSString *)name; 22 | - (void)removeImageForKeys:(NSArray *)names; 23 | - (void)removeAll; 24 | 25 | @end 26 | 27 | @implementation KSImageCache 28 | 29 | + (id)sharedInstance 30 | { 31 | static KSImageCache * imageCache = nil; 32 | 33 | static dispatch_once_t runOnceToken; 34 | dispatch_once(&runOnceToken, ^{ 35 | imageCache = [[self alloc] init]; 36 | }); 37 | 38 | return imageCache; 39 | } 40 | 41 | - (id)copyWithZone:(NSZone *)paramZone{ 42 | return self; 43 | } 44 | 45 | #pragma mark - 46 | #pragma mark Static methods wrapper 47 | 48 | + (id)imageNamed:(NSString *)name 49 | { 50 | return [[KSImageCache sharedInstance] imageForKey:name]; 51 | } 52 | 53 | + (BOOL)setImage:(UIImage *)image forName:(NSString *)name 54 | { 55 | return [[KSImageCache sharedInstance] setImage:image forKey:name]; 56 | } 57 | 58 | + (BOOL)setImagePath:(NSString *)filepath forName:(NSString *)name 59 | { 60 | return [[KSImageCache sharedInstance] setImagePath:filepath forKey:name]; 61 | } 62 | 63 | + (void)removeImage:(NSString *)name 64 | { 65 | return [[KSImageCache sharedInstance] removeImageForKey:name]; 66 | } 67 | 68 | + (void)removeImages:(NSArray *)names 69 | { 70 | return [[KSImageCache sharedInstance] removeImageForKeys:names]; 71 | } 72 | 73 | + (void)clear 74 | { 75 | return [[KSImageCache sharedInstance] removeAll]; 76 | } 77 | 78 | #pragma mark - 79 | #pragma mark Image cache methods 80 | 81 | - (id)init 82 | { 83 | self = [super init]; 84 | if (self) { 85 | _imageDict = [[NSMutableDictionary alloc] init]; 86 | _lockObject = [[NSObject alloc] init]; 87 | } 88 | 89 | return self; 90 | } 91 | 92 | - (id)imageForKey:(NSString *)name 93 | { 94 | if (name == nil || [name isEqualToString:@""]) { 95 | KSLog(@" >> Error: Name is nil or empty."); 96 | return nil; 97 | } 98 | 99 | return [_imageDict objectForKey:name]; 100 | } 101 | 102 | - (BOOL)setImage:(UIImage *)image forKey:(NSString *)name 103 | { 104 | if (image == nil) { 105 | KSLog(@" >> Error: Image is nil"); 106 | return NO; 107 | } 108 | 109 | if (name == nil || [name isEqualToString:@""]) { 110 | KSLog(@" >> Error: Name is nil or empty."); 111 | return NO; 112 | } 113 | 114 | @synchronized(_lockObject){ 115 | [_imageDict setObject:image forKey:name]; 116 | } 117 | 118 | return YES; 119 | } 120 | 121 | - (BOOL)setImagePath:(NSString *)filepath forKey:(NSString *)name 122 | { 123 | if (name == nil || [name isEqualToString:@""]) { 124 | KSLog(@" >> Error: Name is nil or empty."); 125 | return NO; 126 | } 127 | 128 | if (filepath == nil || [filepath isEqualToString:@""]) { 129 | KSLog(@" >> Error: Filepath is nil or empty."); 130 | return NO; 131 | } 132 | 133 | if (![[NSFileManager defaultManager] fileExistsAtPath:filepath]) { 134 | KSLog(@" >> Error: File does not exist at %@", filepath); 135 | } 136 | 137 | UIImage * image = [UIImage imageWithContentsOfFile:filepath]; 138 | @synchronized(_lockObject){ 139 | [_imageDict setObject:image forKey:name]; 140 | } 141 | 142 | return YES; 143 | } 144 | 145 | - (void)removeImageForKey:(NSString *)name 146 | { 147 | if (name == nil || [name isEqualToString:@""]) { 148 | KSLog(@" >> Error: Name is nil or empty."); 149 | return; 150 | } 151 | 152 | @synchronized(_lockObject){ 153 | [_imageDict removeObjectForKey:name]; 154 | } 155 | } 156 | 157 | - (void)removeImageForKeys:(NSArray *)names 158 | { 159 | if (names == nil) { 160 | KSLog(@" >> Error: Names is nil."); 161 | return; 162 | } 163 | 164 | @synchronized(_lockObject){ 165 | [_imageDict removeObjectsForKeys:names]; 166 | } 167 | } 168 | 169 | - (void)removeAll 170 | { 171 | @synchronized(_lockObject){ 172 | [_imageDict removeAllObjects]; 173 | } 174 | } 175 | 176 | @end 177 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/KSUtilities/KSExceptionHandler.m: -------------------------------------------------------------------------------- 1 | // 2 | // KSExceptionHandler.m 3 | // KSUtilitiesDemo 4 | // 5 | // Created by kesalin on 6/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import "KSExceptionHandler.h" 10 | #import "KSLog.h" 11 | #import "KSPathUtil.h" 12 | 13 | @interface KSExceptionHandler() 14 | 15 | @end 16 | 17 | @implementation KSExceptionHandler 18 | 19 | + (id)sharedInstance 20 | { 21 | static KSExceptionHandler * handler = nil; 22 | 23 | static dispatch_once_t runOnceToken; 24 | dispatch_once(&runOnceToken, ^{ 25 | handler = [[self alloc] init]; 26 | }); 27 | 28 | return handler; 29 | } 30 | 31 | + (void)setExceptionOccurredOnLastRunFlag:(BOOL)value 32 | { 33 | NSUserDefaults * settings = [NSUserDefaults standardUserDefaults]; 34 | [settings setBool:value forKey:@"ExceptionOccurredOnLastRun"]; 35 | [settings synchronize]; 36 | } 37 | 38 | void exceptionHandler(NSException *exception) 39 | { 40 | KSLog(@"Uncaught exception: %@\nReason: %@\nUser Info: %@\nCall Stack: %@", 41 | exception.name, exception.reason, exception.userInfo, exception.callStackSymbols); 42 | 43 | //Set flag 44 | [KSExceptionHandler setExceptionOccurredOnLastRunFlag:YES]; 45 | } 46 | 47 | - (void)setExceptionHandler 48 | { 49 | NSSetUncaughtExceptionHandler(&exceptionHandler); 50 | 51 | // Redirect stderr output stream to file 52 | // 53 | NSString * stderrPath = [[KSPathUtil documentDirectory] stringByAppendingPathComponent:@"stderr.log"]; 54 | freopen([stderrPath cStringUsingEncoding:NSASCIIStringEncoding], "w", stderr); 55 | } 56 | 57 | - (void)setOrCheckExceptionHandler 58 | { 59 | #if TARGET_IPHONE_SIMULATOR 60 | return; 61 | #endif 62 | 63 | NSUserDefaults * settings = [NSUserDefaults standardUserDefaults]; 64 | if ([settings boolForKey:@"ExceptionOccurredOnLastRun"]) { 65 | // Reset exception occurred flag 66 | [KSExceptionHandler setExceptionOccurredOnLastRunFlag:NO]; 67 | 68 | // Notify the user 69 | UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"We're sorry" 70 | message:@"An error occurred on the previous run." 71 | delegate:self 72 | cancelButtonTitle:@"Dismiss" 73 | otherButtonTitles:nil]; 74 | if (self.parentViewController != nil) { 75 | [alert addButtonWithTitle:@"Email a Report"]; 76 | } 77 | 78 | [alert show]; 79 | } 80 | 81 | else { 82 | [self setExceptionHandler]; 83 | } 84 | } 85 | 86 | #pragma mark - 87 | #pragma mark UIAlertViewDelegate 88 | 89 | -(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 90 | { 91 | if (buttonIndex == 1 && self.parentViewController != nil) 92 | { 93 | // Attach log file 94 | NSString * stderrPath = [[KSPathUtil documentDirectory] stringByAppendingPathComponent:@"stderr.log"]; 95 | NSData * data = [NSData dataWithContentsOfFile:stderrPath]; 96 | 97 | // Set device information 98 | UIDevice * device = [UIDevice currentDevice]; 99 | NSString * emailBody = [NSString stringWithFormat:@"My Model: %@\nMy OS: %@\nMy Version: %@", 100 | [device model], [device systemName], [device systemVersion]]; 101 | 102 | // Email a Report 103 | MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc] init]; 104 | mailComposer.mailComposeDelegate = self; 105 | [mailComposer setSubject:@"Error Report"]; 106 | [mailComposer setToRecipients:[NSArray arrayWithObject:@"kesalin@gmail.com"]]; 107 | [mailComposer addAttachmentData:data mimeType:@"Text/XML" fileName:@"stderr.log"]; 108 | [mailComposer setMessageBody:emailBody isHTML:NO]; 109 | 110 | [self.parentViewController presentViewController:mailComposer animated:YES 111 | completion:nil]; 112 | } 113 | 114 | [self setExceptionHandler]; 115 | } 116 | 117 | #pragma mark - 118 | #pragma mark MFMailComposeViewControllerDelegate 119 | 120 | -(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error 121 | { 122 | [self.parentViewController dismissViewControllerAnimated:YES completion:nil]; 123 | } 124 | 125 | @end 126 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTLegend.h: -------------------------------------------------------------------------------- 1 | #import "CPTBorderedLayer.h" 2 | #import 3 | 4 | /// @file 5 | 6 | @class CPTLegend; 7 | @class CPTPlot; 8 | @class CPTTextStyle; 9 | 10 | /// @name Legend 11 | /// @{ 12 | 13 | /** @brief Notification sent by plots to tell the legend it should redraw itself. 14 | * @ingroup notification 15 | **/ 16 | extern NSString *const CPTLegendNeedsRedrawForPlotNotification; 17 | 18 | /** @brief Notification sent by plots to tell the legend it should update its layout and redraw itself. 19 | * @ingroup notification 20 | **/ 21 | extern NSString *const CPTLegendNeedsLayoutForPlotNotification; 22 | 23 | /** @brief Notification sent by plots to tell the legend it should reload all legend entries. 24 | * @ingroup notification 25 | **/ 26 | extern NSString *const CPTLegendNeedsReloadEntriesForPlotNotification; 27 | 28 | /// @} 29 | 30 | /** 31 | * @brief Axis labeling delegate. 32 | **/ 33 | @protocol CPTLegendDelegate 34 | 35 | /// @name Drawing 36 | /// @{ 37 | 38 | /** @brief @required This method gives the delegate a chance to draw custom swatches for each legend entry. 39 | * 40 | * The "swatch" is the graphical part of the legend entry, usually accompanied by a text title 41 | * that will be drawn by the legend. Returning @NO will cause the legend to not draw the default 42 | * legend graphics. It is then the delegate’s responsiblity to do this. 43 | * @param legend The legend. 44 | * @param idx The zero-based index of the legend entry for the given plot. 45 | * @param plot The plot. 46 | * @param rect The bounding rectangle to use when drawing the swatch. 47 | * @param context The graphics context to draw into. 48 | * @return @YES if the legend should draw the default swatch or @NO if the delegate handled the drawing. 49 | **/ 50 | -(BOOL)legend:(CPTLegend *)legend shouldDrawSwatchAtIndex:(NSUInteger)idx forPlot:(CPTPlot *)plot inRect:(CGRect)rect inContext:(CGContextRef)context; 51 | 52 | /// @} 53 | 54 | @end 55 | 56 | #pragma mark - 57 | 58 | @interface CPTLegend : CPTBorderedLayer { 59 | @private 60 | NSMutableArray *plots; 61 | NSMutableArray *legendEntries; 62 | BOOL layoutChanged; 63 | CPTTextStyle *textStyle; 64 | CGSize swatchSize; 65 | CPTLineStyle *swatchBorderLineStyle; 66 | CGFloat swatchCornerRadius; 67 | CPTFill *swatchFill; 68 | NSUInteger numberOfRows; 69 | NSUInteger numberOfColumns; 70 | BOOL equalRows; 71 | BOOL equalColumns; 72 | NSArray *rowHeights; 73 | NSArray *rowHeightsThatFit; 74 | NSArray *columnWidths; 75 | NSArray *columnWidthsThatFit; 76 | CGFloat columnMargin; 77 | CGFloat rowMargin; 78 | CGFloat titleOffset; 79 | } 80 | 81 | /// @name Formatting 82 | /// @{ 83 | @property (nonatomic, readwrite, copy) CPTTextStyle *textStyle; 84 | @property (nonatomic, readwrite, assign) CGSize swatchSize; 85 | @property (nonatomic, readwrite, copy) CPTLineStyle *swatchBorderLineStyle; 86 | @property (nonatomic, readwrite, assign) CGFloat swatchCornerRadius; 87 | @property (nonatomic, readwrite, copy) CPTFill *swatchFill; 88 | /// @} 89 | 90 | /// @name Layout 91 | /// @{ 92 | @property (nonatomic, readonly, assign) BOOL layoutChanged; 93 | @property (nonatomic, readwrite, assign) NSUInteger numberOfRows; 94 | @property (nonatomic, readwrite, assign) NSUInteger numberOfColumns; 95 | @property (nonatomic, readwrite, assign) BOOL equalRows; 96 | @property (nonatomic, readwrite, assign) BOOL equalColumns; 97 | @property (nonatomic, readwrite, copy) NSArray *rowHeights; 98 | @property (nonatomic, readonly, retain) NSArray *rowHeightsThatFit; 99 | @property (nonatomic, readwrite, copy) NSArray *columnWidths; 100 | @property (nonatomic, readonly, retain) NSArray *columnWidthsThatFit; 101 | @property (nonatomic, readwrite, assign) CGFloat columnMargin; 102 | @property (nonatomic, readwrite, assign) CGFloat rowMargin; 103 | @property (nonatomic, readwrite, assign) CGFloat titleOffset; 104 | /// @} 105 | 106 | /// @name Factory Methods 107 | /// @{ 108 | +(id)legendWithPlots:(NSArray *)newPlots; 109 | +(id)legendWithGraph:(CPTGraph *)graph; 110 | /// @} 111 | 112 | /// @name Initialization 113 | /// @{ 114 | -(id)initWithPlots:(NSArray *)newPlots; 115 | -(id)initWithGraph:(CPTGraph *)graph; 116 | /// @} 117 | 118 | /// @name Plots 119 | /// @{ 120 | -(NSArray *)allPlots; 121 | -(CPTPlot *)plotAtIndex:(NSUInteger)idx; 122 | -(CPTPlot *)plotWithIdentifier:(id)identifier; 123 | 124 | -(void)addPlot:(CPTPlot *)plot; 125 | -(void)insertPlot:(CPTPlot *)plot atIndex:(NSUInteger)idx; 126 | -(void)removePlot:(CPTPlot *)plot; 127 | -(void)removePlotWithIdentifier:(id)identifier; 128 | /// @} 129 | 130 | /// @name Layout 131 | /// @{ 132 | -(void)setLayoutChanged; 133 | /// @} 134 | 135 | @end 136 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/en.lproj/MainStoryboard.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/en.lproj/MainStoryboard.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /KSUtilitiesDemo/KSUtilitiesDemo/Controllers/KSViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // KSViewController.m 3 | // KSUtilitiesDemo 4 | // 5 | // Created by kesalin on 6/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import "KSViewController.h" 10 | #import "KSLog.h" 11 | #import "KSErrorHandler.h" 12 | 13 | @interface KSViewController () 14 | { 15 | NSDictionary * _testItems; 16 | } 17 | 18 | - (id)testKeyAtIndex:(NSInteger) index; 19 | 20 | - (void)testError; 21 | - (void)testFatalError; 22 | @end 23 | 24 | @implementation KSViewController 25 | 26 | - (void)viewDidLoad 27 | { 28 | [super viewDidLoad]; 29 | // Do any additional setup after loading the view, typically from a nib. 30 | 31 | KSLog(@" >> Root view did load."); 32 | KSTrace(@" >> Root view did load."); 33 | 34 | _testItems = @{ 35 | @"Common error":@"testError", 36 | @"Fatal error":@"testFatalError", 37 | @"Exception":@"testException" 38 | }; 39 | self.mainTableView.dataSource = self; 40 | self.mainTableView.delegate = self; 41 | } 42 | 43 | - (void)didReceiveMemoryWarning 44 | { 45 | [super didReceiveMemoryWarning]; 46 | // Dispose of any resources that can be recreated. 47 | } 48 | 49 | - (id)testKeyAtIndex:(NSInteger) index 50 | { 51 | NSEnumerator * enumerator = [_testItems keyEnumerator]; 52 | id key = nil; 53 | NSInteger i = 0; 54 | while (i <= index) { 55 | key = [enumerator nextObject]; 56 | i++; 57 | 58 | if (key == nil) 59 | break; 60 | } 61 | return key; 62 | } 63 | 64 | #pragma mark - 65 | #pragma mark UITableViewDataSource 66 | 67 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 68 | { 69 | return [_testItems count]; 70 | } 71 | 72 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 73 | { 74 | static NSString * cellIdentifier = @"KSUtilitiesDemoCell"; 75 | UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 76 | if (cell == nil) { 77 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; 78 | } 79 | 80 | NSInteger row = indexPath.row; 81 | cell.textLabel.text = [self testKeyAtIndex:row]; 82 | return cell; 83 | } 84 | 85 | #pragma mark - 86 | #pragma mark UITableViewDelegate 87 | 88 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 89 | { 90 | NSInteger row = indexPath.row; 91 | NSString * key = [self testKeyAtIndex:row]; 92 | 93 | NSString * selectorName = [_testItems valueForKey:key]; 94 | SEL sel = NSSelectorFromString(selectorName); 95 | if (sel != nil) { 96 | [self performSelector:sel]; 97 | } 98 | } 99 | 100 | - (void)testError 101 | { 102 | NSString * description = @"Common Error"; 103 | NSString * failureReason = @"Can't seem to connect to network."; 104 | NSArray * recoveryOptions = @[@"Retry"]; 105 | NSString * recoverySuggestion = @"Check your wifi or 3G settings and retry."; 106 | 107 | NSDictionary * userInfo = 108 | [NSDictionary dictionaryWithObjects:@[description, failureReason, recoveryOptions, recoverySuggestion, self] 109 | forKeys: @[NSLocalizedDescriptionKey,NSLocalizedFailureReasonErrorKey, NSLocalizedRecoveryOptionsErrorKey, NSLocalizedRecoverySuggestionErrorKey, NSRecoveryAttempterErrorKey]]; 110 | 111 | NSError *error = [[NSError alloc] initWithDomain:@"com.kesalin.KSUtilitiesDemo" 112 | code:10 userInfo:userInfo]; 113 | 114 | [KSErrorHandler handleError:error isFatal:NO]; 115 | } 116 | 117 | - (void)testFatalError 118 | { 119 | NSString *description = @"Fatal Error"; 120 | NSString *failureReason = @"Data is corrupt. The app must shut down."; 121 | NSString *recoverySuggestion = @"Contact support!"; 122 | 123 | NSDictionary *userInfo = @{ 124 | description: NSLocalizedDescriptionKey, 125 | failureReason: NSLocalizedFailureReasonErrorKey, 126 | recoverySuggestion: NSLocalizedRecoverySuggestionErrorKey 127 | }; 128 | 129 | NSError *error = [[NSError alloc] initWithDomain:@"com.kesalin.KSUtilitiesDemo" 130 | code:11 userInfo:userInfo]; 131 | 132 | [KSErrorHandler handleError:error isFatal:YES]; 133 | } 134 | 135 | - (void)testException 136 | { 137 | NSException * e = [[NSException alloc] initWithName:@"FakeException" 138 | reason:@"The developer sucks!" 139 | userInfo:[NSDictionary dictionaryWithObject:@"Extra info" forKey:@"Key"]]; 140 | [e raise]; 141 | } 142 | 143 | @end 144 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTScatterPlot.h: -------------------------------------------------------------------------------- 1 | #import "CPTDefinitions.h" 2 | #import "CPTPlot.h" 3 | #import 4 | 5 | /// @file 6 | 7 | @class CPTLineStyle; 8 | @class CPTMutableNumericData; 9 | @class CPTNumericData; 10 | @class CPTPlotSymbol; 11 | @class CPTScatterPlot; 12 | @class CPTFill; 13 | 14 | /// @ingroup plotBindingsScatterPlot 15 | /// @{ 16 | extern NSString *const CPTScatterPlotBindingXValues; 17 | extern NSString *const CPTScatterPlotBindingYValues; 18 | extern NSString *const CPTScatterPlotBindingPlotSymbols; 19 | /// @} 20 | 21 | /** 22 | * @brief Enumeration of scatter plot data source field types 23 | **/ 24 | typedef enum _CPTScatterPlotField { 25 | CPTScatterPlotFieldX, ///< X values. 26 | CPTScatterPlotFieldY ///< Y values. 27 | } 28 | CPTScatterPlotField; 29 | 30 | /** 31 | * @brief Enumeration of scatter plot interpolation algorithms 32 | **/ 33 | typedef enum _CPTScatterPlotInterpolation { 34 | CPTScatterPlotInterpolationLinear, ///< Linear interpolation. 35 | CPTScatterPlotInterpolationStepped, ///< Steps beginnning at data point. 36 | CPTScatterPlotInterpolationHistogram, ///< Steps centered at data point. 37 | CPTScatterPlotInterpolationCurved ///< Bezier curve interpolation. 38 | } 39 | CPTScatterPlotInterpolation; 40 | 41 | #pragma mark - 42 | 43 | /** 44 | * @brief A scatter plot data source. 45 | **/ 46 | @protocol CPTScatterPlotDataSource 47 | 48 | @optional 49 | 50 | /// @name Plot Symbols 51 | /// @{ 52 | 53 | /** @brief @optional Gets a range of plot symbols for the given scatter plot. 54 | * @param plot The scatter plot. 55 | * @param indexRange The range of the data indexes of interest. 56 | * @return An array of plot symbols. 57 | **/ 58 | -(NSArray *)symbolsForScatterPlot:(CPTScatterPlot *)plot recordIndexRange:(NSRange)indexRange; 59 | 60 | /** @brief @optional Gets a single plot symbol for the given scatter plot. 61 | * This method will not be called if 62 | * @link CPTScatterPlotDataSource::symbolsForScatterPlot:recordIndexRange: -symbolsForScatterPlot:recordIndexRange: @endlink 63 | * is also implemented in the datasource. 64 | * @param plot The scatter plot. 65 | * @param idx The data index of interest. 66 | * @return The plot symbol to show for the point with the given index. 67 | **/ 68 | -(CPTPlotSymbol *)symbolForScatterPlot:(CPTScatterPlot *)plot recordIndex:(NSUInteger)idx; 69 | 70 | /// @} 71 | 72 | @end 73 | 74 | #pragma mark - 75 | 76 | /** 77 | * @brief Scatter plot delegate. 78 | **/ 79 | @protocol CPTScatterPlotDelegate 80 | 81 | @optional 82 | 83 | /// @name Point Selection 84 | /// @{ 85 | 86 | /** @brief @optional Informs the delegate that a data point was 87 | * @if MacOnly clicked. @endif 88 | * @if iOSOnly touched. @endif 89 | * @param plot The scatter plot. 90 | * @param idx The index of the 91 | * @if MacOnly clicked data point. @endif 92 | * @if iOSOnly touched data point. @endif 93 | **/ 94 | -(void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)idx; 95 | 96 | /** @brief @optional Informs the delegate that a data point was 97 | * @if MacOnly clicked. @endif 98 | * @if iOSOnly touched. @endif 99 | * @param plot The scatter plot. 100 | * @param idx The index of the 101 | * @if MacOnly clicked data point. @endif 102 | * @if iOSOnly touched data point. @endif 103 | * @param event The event that triggered the selection. 104 | **/ 105 | -(void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)idx withEvent:(CPTNativeEvent *)event; 106 | 107 | /// @} 108 | 109 | @end 110 | 111 | #pragma mark - 112 | 113 | @interface CPTScatterPlot : CPTPlot { 114 | @private 115 | CPTScatterPlotInterpolation interpolation; 116 | CPTLineStyle *dataLineStyle; 117 | CPTPlotSymbol *plotSymbol; 118 | CPTFill *areaFill; 119 | CPTFill *areaFill2; 120 | NSDecimal areaBaseValue; 121 | NSDecimal areaBaseValue2; 122 | CGFloat plotSymbolMarginForHitDetection; 123 | } 124 | 125 | /// @name Appearance 126 | /// @{ 127 | @property (nonatomic, readwrite) NSDecimal areaBaseValue; 128 | @property (nonatomic, readwrite) NSDecimal areaBaseValue2; 129 | @property (nonatomic, readwrite, assign) CPTScatterPlotInterpolation interpolation; 130 | /// @} 131 | 132 | /// @name Drawing 133 | /// @{ 134 | @property (nonatomic, readwrite, copy) CPTLineStyle *dataLineStyle; 135 | @property (nonatomic, readwrite, copy) CPTPlotSymbol *plotSymbol; 136 | @property (nonatomic, readwrite, copy) CPTFill *areaFill; 137 | @property (nonatomic, readwrite, copy) CPTFill *areaFill2; 138 | /// @} 139 | 140 | /// @name User Interaction 141 | /// @{ 142 | @property (nonatomic, readwrite, assign) CGFloat plotSymbolMarginForHitDetection; 143 | /// @} 144 | 145 | /// @name Visible Points 146 | /// @{ 147 | -(NSUInteger)indexOfVisiblePointClosestToPlotAreaPoint:(CGPoint)viewPoint; 148 | -(CGPoint)plotAreaPointOfVisiblePointAtIndex:(NSUInteger)idx; 149 | /// @} 150 | 151 | /// @name Plot Symbols 152 | /// @{ 153 | -(CPTPlotSymbol *)plotSymbolForRecordIndex:(NSUInteger)idx; 154 | /// @} 155 | 156 | @end 157 | -------------------------------------------------------------------------------- /SQLiteDemo/SQLiteDemo/en.lproj/KSViewController_iPad.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1536 5 | 12A206j 6 | 2519 7 | 1172.1 8 | 613.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 1856 12 | 13 | 14 | IBProxyObject 15 | IBUIView 16 | 17 | 18 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 19 | 20 | 21 | PluginDependencyRecalculationVersion 22 | 23 | 24 | 25 | 26 | IBFilesOwner 27 | IBIPadFramework 28 | 29 | 30 | IBFirstResponder 31 | IBIPadFramework 32 | 33 | 34 | 35 | 274 36 | {{0, 20}, {768, 1004}} 37 | 38 | 39 | 40 | 3 41 | MQA 42 | 43 | 2 44 | 45 | 46 | 47 | 2 48 | 49 | IBIPadFramework 50 | 51 | 52 | 53 | 54 | 55 | 56 | view 57 | 58 | 59 | 60 | 3 61 | 62 | 63 | 64 | 65 | 66 | 0 67 | 68 | 69 | 70 | 71 | 72 | -1 73 | 74 | 75 | File's Owner 76 | 77 | 78 | -2 79 | 80 | 81 | 82 | 83 | 2 84 | 85 | 86 | 87 | 88 | 89 | 90 | KSViewController 91 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 92 | UIResponder 93 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 94 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 95 | 96 | 97 | 98 | 99 | 100 | 3 101 | 102 | 103 | 104 | 105 | KSViewController 106 | UIViewController 107 | 108 | IBProjectSource 109 | ./Classes/KSViewController.h 110 | 111 | 112 | 113 | 114 | 0 115 | IBIPadFramework 116 | YES 117 | 3 118 | YES 119 | 1856 120 | 121 | 122 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTPieChart.h: -------------------------------------------------------------------------------- 1 | #import "CPTDefinitions.h" 2 | #import "CPTPlot.h" 3 | #import 4 | 5 | /// @file 6 | 7 | @class CPTColor; 8 | @class CPTFill; 9 | @class CPTMutableNumericData; 10 | @class CPTNumericData; 11 | @class CPTPieChart; 12 | @class CPTTextLayer; 13 | @class CPTLineStyle; 14 | 15 | /// @ingroup plotBindingsPieChart 16 | /// @{ 17 | extern NSString *const CPTPieChartBindingPieSliceWidthValues; 18 | extern NSString *const CPTPieChartBindingPieSliceFills; 19 | extern NSString *const CPTPieChartBindingPieSliceRadialOffsets; 20 | /// @} 21 | 22 | /** 23 | * @brief Enumeration of pie chart data source field types. 24 | **/ 25 | typedef enum _CPTPieChartField { 26 | CPTPieChartFieldSliceWidth, ///< Pie slice width. 27 | CPTPieChartFieldSliceWidthNormalized, ///< Pie slice width normalized [0, 1]. 28 | CPTPieChartFieldSliceWidthSum ///< Cumulative sum of pie slice widths. 29 | } 30 | CPTPieChartField; 31 | 32 | /** 33 | * @brief Enumeration of pie slice drawing directions. 34 | **/ 35 | typedef enum _CPTPieDirection { 36 | CPTPieDirectionClockwise, ///< Pie slices are drawn in a clockwise direction. 37 | CPTPieDirectionCounterClockwise ///< Pie slices are drawn in a counter-clockwise direction. 38 | } 39 | CPTPieDirection; 40 | 41 | #pragma mark - 42 | 43 | /** 44 | * @brief A pie chart data source. 45 | **/ 46 | @protocol CPTPieChartDataSource 47 | @optional 48 | 49 | /// @name Slice Style 50 | /// @{ 51 | 52 | /** @brief @optional Gets a range of slice fills for the given pie chart. 53 | * @param pieChart The pie chart. 54 | * @param indexRange The range of the data indexes of interest. 55 | * @return The pie slice fill for the slice with the given index. 56 | **/ 57 | -(NSArray *)sliceFillsForPieChart:(CPTPieChart *)pieChart recordIndexRange:(NSRange)indexRange; 58 | 59 | /** @brief @optional Gets a fill for the given pie chart slice. 60 | * This method will not be called if 61 | * @link CPTPieChartDataSource::sliceFillsForPieChart:recordIndexRange: -sliceFillsForPieChart:recordIndexRange: @endlink 62 | * is also implemented in the datasource. 63 | * @param pieChart The pie chart. 64 | * @param idx The data index of interest. 65 | * @return The pie slice fill for the slice with the given index. 66 | **/ 67 | -(CPTFill *)sliceFillForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)idx; 68 | 69 | /// @} 70 | 71 | /// @name Slice Layout 72 | /// @{ 73 | 74 | /** @brief @optional Gets a range of slice offsets for the given pie chart. 75 | * @param pieChart The pie chart. 76 | * @param indexRange The range of the data indexes of interest. 77 | * @return An array of radial offsets. 78 | **/ 79 | -(NSArray *)radialOffsetsForPieChart:(CPTPieChart *)pieChart recordIndexRange:(NSRange)indexRange; 80 | 81 | /** @brief @optional Offsets the slice radially from the center point. Can be used to @quote{explode} the chart. 82 | * This method will not be called if 83 | * @link CPTPieChartDataSource::radialOffsetsForPieChart:recordIndexRange: -radialOffsetsForPieChart:recordIndexRange: @endlink 84 | * is also implemented in the datasource. 85 | * @param pieChart The pie chart. 86 | * @param idx The data index of interest. 87 | * @return The radial offset in view coordinates. Zero is no offset. 88 | **/ 89 | -(CGFloat)radialOffsetForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)idx; 90 | 91 | /// @} 92 | 93 | /// @name Legends 94 | /// @{ 95 | 96 | /** @brief @optional Gets the legend title for the given pie chart slice. 97 | * @param pieChart The pie chart. 98 | * @param idx The data index of interest. 99 | * @return The title text for the legend entry for the point with the given index. 100 | **/ 101 | -(NSString *)legendTitleForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)idx; 102 | 103 | /// @} 104 | @end 105 | 106 | #pragma mark - 107 | 108 | /** 109 | * @brief Pie chart delegate. 110 | **/ 111 | @protocol CPTPieChartDelegate 112 | 113 | @optional 114 | 115 | /// @name Slice Selection 116 | /// @{ 117 | 118 | /** @brief @optional Informs the delegate that a pie slice was 119 | * @if MacOnly clicked. @endif 120 | * @if iOSOnly touched. @endif 121 | * @param plot The pie chart. 122 | * @param idx The index of the 123 | * @if MacOnly clicked pie slice. @endif 124 | * @if iOSOnly touched pie slice. @endif 125 | **/ 126 | -(void)pieChart:(CPTPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)idx; 127 | 128 | /** @brief @optional Informs the delegate that a pie slice was 129 | * @if MacOnly clicked. @endif 130 | * @if iOSOnly touched. @endif 131 | * @param plot The pie chart. 132 | * @param idx The index of the 133 | * @if MacOnly clicked pie slice. @endif 134 | * @if iOSOnly touched pie slice. @endif 135 | * @param event The event that triggered the selection. 136 | **/ 137 | -(void)pieChart:(CPTPieChart *)plot sliceWasSelectedAtRecordIndex:(NSUInteger)idx withEvent:(CPTNativeEvent *)event; 138 | 139 | /// @} 140 | 141 | @end 142 | 143 | #pragma mark - 144 | 145 | @interface CPTPieChart : CPTPlot { 146 | @private 147 | CGFloat pieRadius; 148 | CGFloat pieInnerRadius; 149 | CGFloat startAngle; 150 | CGFloat endAngle; 151 | CPTPieDirection sliceDirection; 152 | CGPoint centerAnchor; 153 | CPTLineStyle *borderLineStyle; 154 | CPTFill *overlayFill; 155 | BOOL labelRotationRelativeToRadius; 156 | } 157 | 158 | /// @name Appearance 159 | /// @{ 160 | @property (nonatomic, readwrite) CGFloat pieRadius; 161 | @property (nonatomic, readwrite) CGFloat pieInnerRadius; 162 | @property (nonatomic, readwrite) CGFloat startAngle; 163 | @property (nonatomic, readwrite) CGFloat endAngle; 164 | @property (nonatomic, readwrite) CPTPieDirection sliceDirection; 165 | @property (nonatomic, readwrite) CGPoint centerAnchor; 166 | /// @} 167 | 168 | /// @name Drawing 169 | /// @{ 170 | @property (nonatomic, readwrite, copy) CPTLineStyle *borderLineStyle; 171 | @property (nonatomic, readwrite, copy) CPTFill *overlayFill; 172 | /// @} 173 | 174 | /// @name Data Labels 175 | /// @{ 176 | @property (nonatomic, readwrite, assign) BOOL labelRotationRelativeToRadius; 177 | /// @} 178 | 179 | /// @name Information 180 | /// @{ 181 | -(NSUInteger)pieSliceIndexAtAngle:(CGFloat)angle; 182 | -(CGFloat)medianAngleForPieSliceIndex:(NSUInteger)index; 183 | /// @} 184 | 185 | /// @name Factory Methods 186 | /// @{ 187 | +(CPTColor *)defaultPieSliceColorForIndex:(NSUInteger)pieSliceIndex; 188 | /// @} 189 | 190 | @end 191 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTDefinitions.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | #import 5 | #import 6 | 7 | /// @file 8 | 9 | /** 10 | * @def CPT_SDK_SUPPORTS_WEAK 11 | * @hideinitializer 12 | * @brief Defined as @num{1} if the compiler and active SDK support weak references, @num{0} otherwise. 13 | **/ 14 | 15 | /** 16 | * @def __cpt_weak 17 | * @hideinitializer 18 | * @brief A custom definition for automatic reference counting (ARC) weak references that falls back to 19 | * __unsafe_unretained values on older platforms. 20 | **/ 21 | 22 | /** 23 | * @def cpt_weak_property 24 | * @hideinitializer 25 | * @brief A custom definition for automatic reference counting (ARC) weak properties that falls back to 26 | * assign on older platforms. 27 | **/ 28 | 29 | // This is based on Ryan Petrich's ZWRCompatibility: https://github.com/rpetrich/ZWRCompatibility 30 | 31 | #if TARGET_OS_IPHONE && defined(__IPHONE_5_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0) && __clang__ && (__clang_major__ >= 3) 32 | #define CPT_SDK_SUPPORTS_WEAK 1 33 | #elif TARGET_OS_MAC && defined(__MAC_10_7) && (MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_7) && __clang__ && (__clang_major__ >= 3) 34 | #define CPT_SDK_SUPPORTS_WEAK 1 35 | #else 36 | #define CPT_SDK_SUPPORTS_WEAK 0 37 | #endif 38 | 39 | #if CPT_SDK_SUPPORTS_WEAK 40 | #define __cpt_weak __weak 41 | #define cpt_weak_property weak 42 | #else 43 | #if __clang__ && (__clang_major__ >= 3) 44 | #define __cpt_weak __unsafe_unretained 45 | #else 46 | #define __cpt_weak 47 | #endif 48 | #define cpt_weak_property assign 49 | #endif 50 | 51 | // Type safety defines 52 | 53 | /** 54 | * @def CPTFloat 55 | * @hideinitializer 56 | * @param x The number to cast. 57 | * @brief Casts a number to @ref CGFloat. 58 | **/ 59 | #define CPTFloat(x) ( (CGFloat)(x) ) 60 | 61 | /** 62 | * @def CPTPointMake 63 | * @hideinitializer 64 | * @param x The x-coordinate of the point. 65 | * @param y The y-coordinate of the point. 66 | * @brief A replacement for @ref CGPointMake(), casting each parameter to @ref CGFloat. 67 | **/ 68 | #define CPTPointMake(x, y) CGPointMake( (CGFloat)(x), (CGFloat)(y) ) 69 | 70 | /** 71 | * @def CPTSizeMake 72 | * @hideinitializer 73 | * @param w The width of the size. 74 | * @param h The height of the size. 75 | * @brief A replacement for @ref CGSizeMake(), casting each parameter to @ref CGFloat. 76 | **/ 77 | #define CPTSizeMake(w, h) CGSizeMake( (CGFloat)(w), (CGFloat)(h) ) 78 | 79 | /** 80 | * @def CPTRectMake 81 | * @hideinitializer 82 | * @param x The x-coordinate of the rectangle. 83 | * @param y The y-coordinate of the rectangle. 84 | * @param w The width of the rectangle. 85 | * @param h The height of the rectangle. 86 | * @brief A replacement for @ref CGRectMake(), casting each parameter to @ref CGFloat. 87 | **/ 88 | #define CPTRectMake(x, y, w, h) CGRectMake( (CGFloat)(x), (CGFloat)(y), (CGFloat)(w), (CGFloat)(h) ) 89 | 90 | /** 91 | * @def CPTRectInset 92 | * @hideinitializer 93 | * @param rect The rectangle to offset. 94 | * @param dx The x-offset. 95 | * @param dy The y-offset. 96 | * @brief A replacement for @ref CGRectInset(), casting each offset parameter to @ref CGFloat. 97 | **/ 98 | #define CPTRectInset(rect, dx, dy) CGRectInset( rect, (CGFloat)(dx), (CGFloat)(dy) ) 99 | 100 | /** 101 | * @brief Enumeration of numeric types 102 | **/ 103 | typedef enum _CPTNumericType { 104 | CPTNumericTypeInteger, ///< Integer 105 | CPTNumericTypeFloat, ///< Float 106 | CPTNumericTypeDouble ///< Double 107 | } 108 | CPTNumericType; 109 | 110 | /** 111 | * @brief Enumeration of error bar types 112 | **/ 113 | typedef enum _CPTErrorBarType { 114 | CPTErrorBarTypeCustom, ///< Custom error bars 115 | CPTErrorBarTypeConstantRatio, ///< Constant ratio error bars 116 | CPTErrorBarTypeConstantValue ///< Constant value error bars 117 | } 118 | CPTErrorBarType; 119 | 120 | /** 121 | * @brief Enumeration of axis scale types 122 | **/ 123 | typedef enum _CPTScaleType { 124 | CPTScaleTypeLinear, ///< Linear axis scale 125 | CPTScaleTypeLog, ///< Logarithmic axis scale 126 | CPTScaleTypeAngular, ///< Angular axis scale (not implemented) 127 | CPTScaleTypeDateTime, ///< Date/time axis scale (not implemented) 128 | CPTScaleTypeCategory ///< Category axis scale (not implemented) 129 | } 130 | CPTScaleType; 131 | 132 | /** 133 | * @brief Enumeration of axis coordinates 134 | **/ 135 | typedef enum _CPTCoordinate { 136 | CPTCoordinateX = 0, ///< X axis 137 | CPTCoordinateY = 1, ///< Y axis 138 | CPTCoordinateZ = 2 ///< Z axis 139 | } 140 | CPTCoordinate; 141 | 142 | /** 143 | * @brief RGBA color for gradients 144 | **/ 145 | typedef struct _CPTRGBAColor { 146 | CGFloat red; ///< The red component (0 ≤ @par{red} ≤ 1). 147 | CGFloat green; ///< The green component (0 ≤ @par{green} ≤ 1). 148 | CGFloat blue; ///< The blue component (0 ≤ @par{blue} ≤ 1). 149 | CGFloat alpha; ///< The alpha component (0 ≤ @par{alpha} ≤ 1). 150 | } 151 | CPTRGBAColor; 152 | 153 | /** 154 | * @brief Enumeration of label positioning offset directions 155 | **/ 156 | typedef enum _CPTSign { 157 | CPTSignNone = 0, ///< No offset 158 | CPTSignPositive = +1, ///< Positive offset 159 | CPTSignNegative = -1 ///< Negative offset 160 | } 161 | CPTSign; 162 | 163 | /** 164 | * @brief Locations around the edge of a rectangle. 165 | **/ 166 | typedef enum _CPTRectAnchor { 167 | CPTRectAnchorBottomLeft, ///< The bottom left corner 168 | CPTRectAnchorBottom, ///< The bottom center 169 | CPTRectAnchorBottomRight, ///< The bottom right corner 170 | CPTRectAnchorLeft, ///< The left middle 171 | CPTRectAnchorRight, ///< The right middle 172 | CPTRectAnchorTopLeft, ///< The top left corner 173 | CPTRectAnchorTop, ///< The top center 174 | CPTRectAnchorTopRight, ///< The top right 175 | CPTRectAnchorCenter ///< The center of the rect 176 | } 177 | CPTRectAnchor; 178 | 179 | /** 180 | * @brief Label and constraint alignment constants. 181 | **/ 182 | typedef enum _CPTAlignment { 183 | CPTAlignmentLeft, ///< Align horizontally to the left side. 184 | CPTAlignmentCenter, ///< Align horizontally to the center. 185 | CPTAlignmentRight, ///< Align horizontally to the right side. 186 | CPTAlignmentTop, ///< Align vertically to the top. 187 | CPTAlignmentMiddle, ///< Align vertically to the middle. 188 | CPTAlignmentBottom ///< Align vertically to the bottom. 189 | } 190 | CPTAlignment; 191 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTBarPlot.h: -------------------------------------------------------------------------------- 1 | #import "CPTDefinitions.h" 2 | #import "CPTPlot.h" 3 | #import 4 | 5 | /// @file 6 | 7 | @class CPTLineStyle; 8 | @class CPTMutableNumericData; 9 | @class CPTNumericData; 10 | @class CPTFill; 11 | @class CPTPlotRange; 12 | @class CPTColor; 13 | @class CPTBarPlot; 14 | @class CPTTextLayer; 15 | @class CPTTextStyle; 16 | 17 | /// @ingroup plotBindingsBarPlot 18 | /// @{ 19 | extern NSString *const CPTBarPlotBindingBarLocations; 20 | extern NSString *const CPTBarPlotBindingBarTips; 21 | extern NSString *const CPTBarPlotBindingBarBases; 22 | extern NSString *const CPTBarPlotBindingBarFills; 23 | extern NSString *const CPTBarPlotBindingBarLineStyles; 24 | /// @} 25 | 26 | /** 27 | * @brief Enumeration of bar plot data source field types 28 | **/ 29 | typedef enum _CPTBarPlotField { 30 | CPTBarPlotFieldBarLocation, ///< Bar location on independent coordinate axis. 31 | CPTBarPlotFieldBarTip, ///< Bar tip value. 32 | CPTBarPlotFieldBarBase ///< Bar base (used only if @link CPTBarPlot::barBasesVary barBasesVary @endlink is YES). 33 | } 34 | CPTBarPlotField; 35 | 36 | #pragma mark - 37 | 38 | /** 39 | * @brief A bar plot data source. 40 | **/ 41 | @protocol CPTBarPlotDataSource 42 | @optional 43 | 44 | /// @name Bar Style 45 | /// @{ 46 | 47 | /** @brief @optional Gets an array of bar fills for the given bar plot. 48 | * @param barPlot The bar plot. 49 | * @param indexRange The range of the data indexes of interest. 50 | * @return An array of bar fills. 51 | **/ 52 | -(NSArray *)barFillsForBarPlot:(CPTBarPlot *)barPlot recordIndexRange:(NSRange)indexRange; 53 | 54 | /** @brief @optional Gets a bar fill for the given bar plot. 55 | * This method will not be called if 56 | * @link CPTBarPlotDataSource::barFillsForBarPlot:recordIndexRange: -barFillsForBarPlot:recordIndexRange: @endlink 57 | * is also implemented in the datasource. 58 | * @param barPlot The bar plot. 59 | * @param idx The data index of interest. 60 | * @return The bar fill for the bar with the given index. If the data source returns @nil, the default fill is used. 61 | * If the data source returns an NSNull object, no fill is drawn. 62 | **/ 63 | -(CPTFill *)barFillForBarPlot:(CPTBarPlot *)barPlot recordIndex:(NSUInteger)idx; 64 | 65 | /** @brief @optional Gets an array of bar line styles for the given bar plot. 66 | * @param barPlot The bar plot. 67 | * @param indexRange The range of the data indexes of interest. 68 | * @return An array of line styles. 69 | **/ 70 | -(NSArray *)barLineStylesForBarPlot:(CPTBarPlot *)barPlot recordIndexRange:(NSRange)indexRange; 71 | 72 | /** @brief @optional Gets a bar line style for the given bar plot. 73 | * This method will not be called if 74 | * @link CPTBarPlotDataSource::barLineStylesForBarPlot:recordIndexRange: -barLineStylesForBarPlot:recordIndexRange: @endlink 75 | * is also implemented in the datasource. 76 | * @param barPlot The bar plot. 77 | * @param idx The data index of interest. 78 | * @return The bar line style for the bar with the given index. If the data source returns @nil, the default line style is used. 79 | * If the data source returns an NSNull object, no line is drawn. 80 | **/ 81 | -(CPTLineStyle *)barLineStyleForBarPlot:(CPTBarPlot *)barPlot recordIndex:(NSUInteger)idx; 82 | 83 | /// @} 84 | 85 | /// @name Legends 86 | /// @{ 87 | 88 | /** @brief @optional Gets the legend title for the given bar plot bar. 89 | * @param barPlot The bar plot. 90 | * @param idx The data index of interest. 91 | * @return The title text for the legend entry for the point with the given index. 92 | **/ 93 | -(NSString *)legendTitleForBarPlot:(CPTBarPlot *)barPlot recordIndex:(NSUInteger)idx; 94 | 95 | /// @} 96 | @end 97 | 98 | #pragma mark - 99 | 100 | /** 101 | * @brief Bar plot delegate. 102 | **/ 103 | @protocol CPTBarPlotDelegate 104 | 105 | @optional 106 | 107 | /// @name Point Selection 108 | /// @{ 109 | 110 | /** @brief @optional Informs the delegate that a bar was 111 | * @if MacOnly clicked. @endif 112 | * @if iOSOnly touched. @endif 113 | * @param plot The bar plot. 114 | * @param idx The index of the 115 | * @if MacOnly clicked bar. @endif 116 | * @if iOSOnly touched bar. @endif 117 | **/ 118 | -(void)barPlot:(CPTBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)idx; 119 | 120 | /** @brief @optional Informs the delegate that a bar was 121 | * @if MacOnly clicked. @endif 122 | * @if iOSOnly touched. @endif 123 | * @param plot The bar plot. 124 | * @param idx The index of the 125 | * @if MacOnly clicked bar. @endif 126 | * @if iOSOnly touched bar. @endif 127 | * @param event The event that triggered the selection. 128 | **/ 129 | -(void)barPlot:(CPTBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)idx withEvent:(CPTNativeEvent *)event; 130 | 131 | /// @} 132 | 133 | @end 134 | 135 | #pragma mark - 136 | 137 | @interface CPTBarPlot : CPTPlot { 138 | @private 139 | CPTLineStyle *lineStyle; 140 | CPTFill *fill; 141 | NSDecimal barWidth; 142 | CGFloat barWidthScale; 143 | NSDecimal barOffset; 144 | CGFloat barOffsetScale; 145 | CGFloat barCornerRadius; 146 | CGFloat barBaseCornerRadius; 147 | NSDecimal baseValue; 148 | BOOL barsAreHorizontal; 149 | BOOL barBasesVary; 150 | BOOL barWidthsAreInViewCoordinates; 151 | CPTPlotRange *plotRange; 152 | } 153 | 154 | /// @name Appearance 155 | /// @{ 156 | @property (nonatomic, readwrite, assign) BOOL barWidthsAreInViewCoordinates; 157 | @property (nonatomic, readwrite, assign) NSDecimal barWidth; 158 | @property (nonatomic, readwrite, assign) CGFloat barWidthScale; 159 | @property (nonatomic, readwrite, assign) NSDecimal barOffset; 160 | @property (nonatomic, readwrite, assign) CGFloat barOffsetScale; 161 | @property (nonatomic, readwrite, assign) CGFloat barCornerRadius; 162 | @property (nonatomic, readwrite, assign) CGFloat barBaseCornerRadius; 163 | @property (nonatomic, readwrite, assign) BOOL barsAreHorizontal; 164 | @property (nonatomic, readwrite, assign) NSDecimal baseValue; 165 | @property (nonatomic, readwrite, assign) BOOL barBasesVary; 166 | @property (nonatomic, readwrite, copy) CPTPlotRange *plotRange; 167 | /// @} 168 | 169 | /// @name Drawing 170 | /// @{ 171 | @property (nonatomic, readwrite, copy) CPTLineStyle *lineStyle; 172 | @property (nonatomic, readwrite, copy) CPTFill *fill; 173 | /// @} 174 | 175 | /// @name Factory Methods 176 | /// @{ 177 | +(CPTBarPlot *)tubularBarPlotWithColor:(CPTColor *)color horizontalBars:(BOOL)horizontal; 178 | /// @} 179 | 180 | /// @name Data Ranges 181 | /// @{ 182 | -(CPTPlotRange *)plotRangeEnclosingBars; 183 | /// @} 184 | 185 | @end 186 | -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/KSSocketViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // KSSocketViewController.m 3 | // KSNetworkDemo 4 | // 5 | // Created by kesalin on 13/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import "KSSocketViewController.h" 10 | #import 11 | #import 12 | 13 | // See http://www.telnet.org/htm/places.htm 14 | // 15 | #define kTestHost @"telnet://towel.blinkenlights.nl" 16 | #define kTestPort 23 17 | 18 | @interface KSSocketViewController () 19 | 20 | @end 21 | 22 | @implementation KSSocketViewController 23 | 24 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 25 | { 26 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 27 | if (self) { 28 | // Custom initialization 29 | } 30 | return self; 31 | } 32 | 33 | - (void)viewDidLoad 34 | { 35 | [super viewDidLoad]; 36 | 37 | self.title = @"BSD Socket"; 38 | 39 | self.serverAddressTextField.delegate = self; 40 | self.serverPortTextField.delegate = self; 41 | 42 | self.serverAddressTextField.text = kTestHost; 43 | self.serverPortTextField.text = [[NSNumber numberWithInt:kTestPort] stringValue]; 44 | self.receiveTextView.text = @""; 45 | self.receiveTextView.editable = NO; 46 | } 47 | 48 | - (void)didReceiveMemoryWarning 49 | { 50 | [super didReceiveMemoryWarning]; 51 | // Dispose of any resources that can be recreated. 52 | } 53 | 54 | - (BOOL)textFieldShouldReturn:(UITextField *)textField 55 | { 56 | BOOL didResign = [textField resignFirstResponder]; 57 | return didResign; 58 | } 59 | 60 | - (void)showAlertWithTitle:(NSString *)title message:(NSString *)message 61 | { 62 | UIAlertView * alert = [[UIAlertView alloc] initWithTitle:title 63 | message:message 64 | delegate:nil 65 | cancelButtonTitle:@"Dismiss" 66 | otherButtonTitles:nil]; 67 | [alert show]; 68 | } 69 | 70 | - (IBAction)connectButtonClick:(id)sender 71 | { 72 | NSString * serverHost = self.serverAddressTextField.text; 73 | NSString * serverPort = self.serverPortTextField.text; 74 | 75 | if (serverHost == nil || [serverHost isEqualToString:@""]) { 76 | [self showAlertWithTitle:@"Error" message:@"Server address cann't be empty!"]; 77 | return; 78 | } 79 | 80 | if (serverPort == nil || [serverPort isEqualToString:@""]) { 81 | [self showAlertWithTitle:@"Error" message:@"Server port cann't be empty!"]; 82 | return; 83 | } 84 | 85 | self.connectButton.enabled = NO; 86 | self.receiveTextView.text = @"Connecting to server..."; 87 | [self.networkActivityView startAnimating]; 88 | 89 | NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@"%@:%@", serverHost, serverPort]]; 90 | NSThread * backgroundThread = [[NSThread alloc] initWithTarget:self 91 | selector:@selector(loadDataFromServerWithURL:) 92 | object:url]; 93 | [backgroundThread start]; 94 | } 95 | 96 | - (void)networkFailedWithErrorMessage:(NSString *)message 97 | { 98 | // Update UI 99 | // 100 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 101 | NSLog(@" >> %@", message); 102 | 103 | self.receiveTextView.text = message; 104 | self.connectButton.enabled = YES; 105 | [self.networkActivityView stopAnimating]; 106 | }]; 107 | } 108 | 109 | - (void)networkSucceedWithData:(NSData *)data 110 | { 111 | // Update UI 112 | // 113 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 114 | NSString * resultsString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 115 | NSLog(@" >> Received string: '%@'", resultsString); 116 | 117 | self.receiveTextView.text = resultsString; 118 | self.connectButton.enabled = YES; 119 | [self.networkActivityView stopAnimating]; 120 | }]; 121 | } 122 | 123 | #pragma mark - 124 | #pragma mark Socket 125 | 126 | - (void)loadDataFromServerWithURL:(NSURL *)url 127 | { 128 | NSString * host = [url host]; 129 | NSNumber * port = [url port]; 130 | 131 | // Create socket 132 | // 133 | int socketFileDescriptor = socket(AF_INET, SOCK_STREAM, 0); 134 | if (-1 == socketFileDescriptor) { 135 | NSLog(@"Failed to create socket."); 136 | return; 137 | } 138 | 139 | // Get IP address from host 140 | // 141 | struct hostent * remoteHostEnt = gethostbyname([host UTF8String]); 142 | if (NULL == remoteHostEnt) { 143 | close(socketFileDescriptor); 144 | 145 | [self networkFailedWithErrorMessage:@"Unable to resolve the hostname of the warehouse server."]; 146 | return; 147 | } 148 | 149 | struct in_addr * remoteInAddr = (struct in_addr *)remoteHostEnt->h_addr_list[0]; 150 | 151 | // Set the socket parameters 152 | // 153 | struct sockaddr_in socketParameters; 154 | socketParameters.sin_family = AF_INET; 155 | socketParameters.sin_addr = *remoteInAddr; 156 | socketParameters.sin_port = htons([port intValue]); 157 | 158 | // Connect the socket 159 | // 160 | int ret = connect(socketFileDescriptor, (struct sockaddr *) &socketParameters, sizeof(socketParameters)); 161 | if (-1 == ret) { 162 | close(socketFileDescriptor); 163 | 164 | NSString * errorInfo = [NSString stringWithFormat:@" >> Failed to connect to %@:%@", host, port]; 165 | [self networkFailedWithErrorMessage:errorInfo]; 166 | return; 167 | } 168 | 169 | NSLog(@" >> Successfully connected to %@:%@", host, port); 170 | 171 | NSMutableData * data = [[NSMutableData alloc] init]; 172 | BOOL waitingForData = YES; 173 | 174 | // Continually receive data until we reach the end of the data 175 | // 176 | int maxCount = 5; // just for test. 177 | int i = 0; 178 | while (waitingForData && i < maxCount) { 179 | const char * buffer[1024]; 180 | int length = sizeof(buffer); 181 | 182 | // Read a buffer's amount of data from the socket; the number of bytes read is returned 183 | // 184 | int result = recv(socketFileDescriptor, &buffer, length, 0); 185 | if (result > 0) { 186 | [data appendBytes:buffer length:result]; 187 | } 188 | else { 189 | // if we didn't get any data, stop the receive loop 190 | // 191 | waitingForData = NO; 192 | } 193 | 194 | ++i; 195 | } 196 | 197 | // Close the socket 198 | // 199 | close(socketFileDescriptor); 200 | 201 | [self networkSucceedWithData:data]; 202 | } 203 | 204 | @end 205 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/CorePlotLib/CorePlotHeaders/CPTPlotSpace.h: -------------------------------------------------------------------------------- 1 | #import "CPTDefinitions.h" 2 | #import "CPTResponder.h" 3 | 4 | @class CPTLayer; 5 | @class CPTPlotRange; 6 | @class CPTGraph; 7 | @class CPTPlotSpace; 8 | 9 | /// @name Plot Space 10 | /// @{ 11 | 12 | /** @brief Plot space coordinate change notification. 13 | * 14 | * This notification is posted to the default notification center whenever the mapping between 15 | * the plot space coordinate system and drawing coordinates changes. 16 | * @ingroup notification 17 | **/ 18 | extern NSString *const CPTPlotSpaceCoordinateMappingDidChangeNotification; 19 | 20 | /// @} 21 | 22 | /** 23 | * @brief Plot space delegate. 24 | **/ 25 | @protocol CPTPlotSpaceDelegate 26 | 27 | @optional 28 | 29 | /// @name Scaling 30 | /// @{ 31 | 32 | /** @brief @optional Informs the receiver that it should uniformly scale (e.g., in response to a pinch gesture). 33 | * @param space The plot space. 34 | * @param interactionScale The scaling factor. 35 | * @param interactionPoint The coordinates of the scaling centroid. 36 | * @return @YES if the gesture should be handled by the plot space, and @NO if not. 37 | * In either case, the delegate may choose to take extra actions, or handle the scaling itself. 38 | **/ 39 | -(BOOL)plotSpace:(CPTPlotSpace *)space shouldScaleBy:(CGFloat)interactionScale aboutPoint:(CGPoint)interactionPoint; 40 | 41 | /// @} 42 | 43 | /// @name Scrolling 44 | /// @{ 45 | 46 | /** @brief @optional Notifies that plot space is going to scroll. 47 | * @param space The plot space. 48 | * @param proposedDisplacementVector The proposed amount by which the plot space will shift. 49 | * @return The displacement actually applied. 50 | **/ 51 | -(CGPoint)plotSpace:(CPTPlotSpace *)space willDisplaceBy:(CGPoint)proposedDisplacementVector; 52 | 53 | /// @} 54 | 55 | /// @name Plot Range Changes 56 | /// @{ 57 | 58 | /** @brief @optional Notifies that plot space is going to change a plot range. 59 | * @param space The plot space. 60 | * @param newRange The proposed new plot range. 61 | * @param coordinate The coordinate of the range. 62 | * @return The new plot range to be used. 63 | **/ 64 | -(CPTPlotRange *)plotSpace:(CPTPlotSpace *)space willChangePlotRangeTo:(CPTPlotRange *)newRange forCoordinate:(CPTCoordinate)coordinate; 65 | 66 | /** @brief @optional Notifies that plot space has changed a plot range. 67 | * @param space The plot space. 68 | * @param coordinate The coordinate of the range. 69 | **/ 70 | -(void)plotSpace:(CPTPlotSpace *)space didChangePlotRangeForCoordinate:(CPTCoordinate)coordinate; 71 | 72 | /// @} 73 | 74 | /// @name User Interaction 75 | /// @{ 76 | 77 | /** @brief @optional Notifies that plot space intercepted a device down event. 78 | * @param space The plot space. 79 | * @param event The native event. 80 | * @param point The point in the host view. 81 | * @return Whether the plot space should handle the event or not. 82 | * In either case, the delegate may choose to take extra actions, or handle the scaling itself. 83 | **/ 84 | -(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceDownEvent:(CPTNativeEvent *)event atPoint:(CGPoint)point; 85 | 86 | /** @brief @optional Notifies that plot space intercepted a device dragged event. 87 | * @param space The plot space. 88 | * @param event The native event. 89 | * @param point The point in the host view. 90 | * @return Whether the plot space should handle the event or not. 91 | * In either case, the delegate may choose to take extra actions, or handle the scaling itself. 92 | **/ 93 | -(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceDraggedEvent:(CPTNativeEvent *)event atPoint:(CGPoint)point; 94 | 95 | /** @brief @optional Notifies that plot space intercepted a device cancelled event. 96 | * @param space The plot space. 97 | * @param event The native event. 98 | * @return Whether the plot space should handle the event or not. 99 | * In either case, the delegate may choose to take extra actions, or handle the scaling itself. 100 | **/ 101 | -(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceCancelledEvent:(CPTNativeEvent *)event; 102 | 103 | /** @brief @optional Notifies that plot space intercepted a device up event. 104 | * @param space The plot space. 105 | * @param event The native event. 106 | * @param point The point in the host view. 107 | * @return Whether the plot space should handle the event or not. 108 | * In either case, the delegate may choose to take extra actions, or handle the scaling itself. 109 | **/ 110 | -(BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceUpEvent:(CPTNativeEvent *)event atPoint:(CGPoint)point; 111 | 112 | /// @} 113 | 114 | @end 115 | 116 | #pragma mark - 117 | 118 | @interface CPTPlotSpace : NSObject { 119 | @private 120 | __cpt_weak CPTGraph *graph; 121 | id identifier; 122 | __cpt_weak id delegate; 123 | BOOL allowsUserInteraction; 124 | } 125 | 126 | @property (nonatomic, readwrite, copy) id identifier; 127 | @property (nonatomic, readwrite, assign) BOOL allowsUserInteraction; 128 | @property (nonatomic, readwrite, cpt_weak_property) __cpt_weak CPTGraph *graph; 129 | @property (nonatomic, readwrite, cpt_weak_property) __cpt_weak id delegate; 130 | 131 | @end 132 | 133 | #pragma mark - 134 | 135 | /** @category CPTPlotSpace(AbstractMethods) 136 | * @brief CPTPlotSpace abstract methods—must be overridden by subclasses 137 | **/ 138 | @interface CPTPlotSpace(AbstractMethods) 139 | 140 | /// @name Coordinate Space Conversions 141 | /// @{ 142 | -(CGPoint)plotAreaViewPointForPlotPoint:(NSDecimal *)plotPoint; 143 | -(CGPoint)plotAreaViewPointForDoublePrecisionPlotPoint:(double *)plotPoint; 144 | -(void)plotPoint:(NSDecimal *)plotPoint forPlotAreaViewPoint:(CGPoint)point; 145 | -(void)doublePrecisionPlotPoint:(double *)plotPoint forPlotAreaViewPoint:(CGPoint)point; 146 | 147 | -(CGPoint)plotAreaViewPointForEvent:(CPTNativeEvent *)event; 148 | -(void)plotPoint:(NSDecimal *)plotPoint forEvent:(CPTNativeEvent *)event; 149 | -(void)doublePrecisionPlotPoint:(double *)plotPoint forEvent:(CPTNativeEvent *)event; 150 | /// @} 151 | 152 | /// @name Coordinate Range 153 | /// @{ 154 | -(void)setPlotRange:(CPTPlotRange *)newRange forCoordinate:(CPTCoordinate)coordinate; 155 | -(CPTPlotRange *)plotRangeForCoordinate:(CPTCoordinate)coordinate; 156 | /// @} 157 | 158 | /// @name Scale Types 159 | /// @{ 160 | -(void)setScaleType:(CPTScaleType)newType forCoordinate:(CPTCoordinate)coordinate; 161 | -(CPTScaleType)scaleTypeForCoordinate:(CPTCoordinate)coordinate; 162 | /// @} 163 | 164 | /// @name Adjusting Ranges 165 | /// @{ 166 | -(void)scaleToFitPlots:(NSArray *)plots; 167 | -(void)scaleBy:(CGFloat)interactionScale aboutPoint:(CGPoint)interactionPoint; 168 | /// @} 169 | 170 | @end 171 | -------------------------------------------------------------------------------- /CorePlotDemo/CorePlotDemo/en.lproj/KSViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1552 5 | 12D78 6 | 3084 7 | 1187.37 8 | 626.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 2083 12 | 13 | 14 | IBProxyObject 15 | IBUIView 16 | 17 | 18 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 19 | 20 | 21 | PluginDependencyRecalculationVersion 22 | 23 | 24 | 25 | 26 | IBFilesOwner 27 | IBCocoaTouchFramework 28 | 29 | 30 | IBFirstResponder 31 | IBCocoaTouchFramework 32 | 33 | 34 | 35 | 274 36 | {{0, 20}, {320, 548}} 37 | 38 | 39 | 40 | 3 41 | MC43NQA 42 | 43 | 2 44 | 45 | 46 | NO 47 | 48 | 49 | IBUIScreenMetrics 50 | 51 | YES 52 | 53 | 54 | 55 | 56 | 57 | {320, 568} 58 | {568, 320} 59 | 60 | 61 | IBCocoaTouchFramework 62 | Retina 4 Full Screen 63 | 2 64 | 65 | IBCocoaTouchFramework 66 | 67 | 68 | 69 | 70 | 71 | 72 | view 73 | 74 | 75 | 76 | 7 77 | 78 | 79 | 80 | 81 | 82 | 0 83 | 84 | 85 | 86 | 87 | 88 | -1 89 | 90 | 91 | File's Owner 92 | 93 | 94 | -2 95 | 96 | 97 | 98 | 99 | 6 100 | 101 | 102 | 103 | 104 | 105 | 106 | KSViewController 107 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 108 | UIResponder 109 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 110 | CPTGraphHostingView 111 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 112 | 113 | 114 | 115 | 116 | 117 | 7 118 | 119 | 120 | 121 | 122 | CPTGraphHostingView 123 | UIView 124 | 125 | IBProjectSource 126 | ./Classes/CPTGraphHostingView.h 127 | 128 | 129 | 130 | KSViewController 131 | UIViewController 132 | 133 | IBProjectSource 134 | ./Classes/KSViewController.h 135 | 136 | 137 | 138 | 139 | 0 140 | IBCocoaTouchFramework 141 | YES 142 | 3 143 | YES 144 | 2083 145 | 146 | 147 | -------------------------------------------------------------------------------- /KSNetworkDemo/KSNetworkDemo/KSNSStreamViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // KSNSStreamViewController.m 3 | // KSNetworkDemo 4 | // 5 | // Created by kesalin on 15/4/13. 6 | // Copyright (c) 2013 kesalin@gmail.com. All rights reserved. 7 | // 8 | 9 | #import "KSNSStreamViewController.h" 10 | #import "NSStream+StreamsToHost.h" 11 | 12 | #define kBufferSize 1024 13 | 14 | // See http://www.telnet.org/htm/places.htm 15 | // 16 | #define kTestHost @"telnet://towel.blinkenlights.nl" 17 | #define kTestPort 23 18 | 19 | @interface KSNSStreamViewController () 20 | { 21 | NSMutableData * _receivedData; 22 | } 23 | 24 | @end 25 | 26 | @implementation KSNSStreamViewController 27 | 28 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 29 | { 30 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 31 | if (self) { 32 | // Custom initialization 33 | } 34 | return self; 35 | } 36 | 37 | - (void)viewDidLoad 38 | { 39 | [super viewDidLoad]; 40 | // Do any additional setup after loading the view from its nib. 41 | 42 | self.title = @"NSStream"; 43 | 44 | self.serverAddressTextField.delegate = self; 45 | self.serverPortTextField.delegate = self; 46 | 47 | self.serverAddressTextField.text = kTestHost; 48 | self.serverPortTextField.text = [[NSNumber numberWithInt:kTestPort] stringValue]; 49 | self.receiveTextView.text = @""; 50 | self.receiveTextView.editable = NO; 51 | } 52 | 53 | - (void)didReceiveMemoryWarning 54 | { 55 | [super didReceiveMemoryWarning]; 56 | // Dispose of any resources that can be recreated. 57 | } 58 | 59 | - (BOOL)textFieldShouldReturn:(UITextField *)textField 60 | { 61 | BOOL didResign = [textField resignFirstResponder]; 62 | return didResign; 63 | } 64 | 65 | - (void)showAlertWithTitle:(NSString *)title message:(NSString *)message 66 | { 67 | UIAlertView * alert = [[UIAlertView alloc] initWithTitle:title 68 | message:message 69 | delegate:nil 70 | cancelButtonTitle:@"Dismiss" 71 | otherButtonTitles:nil]; 72 | [alert show]; 73 | } 74 | 75 | - (IBAction)connectButtonClick:(id)sender 76 | { 77 | NSString * serverHost = self.serverAddressTextField.text; 78 | NSString * serverPort = self.serverPortTextField.text; 79 | 80 | if (serverHost == nil || [serverHost isEqualToString:@""]) { 81 | [self showAlertWithTitle:@"Error" message:@"Server address cann't be empty!"]; 82 | return; 83 | } 84 | 85 | if (serverPort == nil || [serverPort isEqualToString:@""]) { 86 | [self showAlertWithTitle:@"Error" message:@"Server port cann't be empty!"]; 87 | return; 88 | } 89 | 90 | self.connectButton.enabled = NO; 91 | self.receiveTextView.text = @"Connecting to server..."; 92 | [self.networkActivityView startAnimating]; 93 | 94 | NSLog(@" >> main thread %@", [NSThread currentThread]); 95 | 96 | NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@"%@:%@", serverHost, serverPort]]; 97 | NSThread * backgroundThread = [[NSThread alloc] initWithTarget:self 98 | selector:@selector(loadDataFromServerWithURL:) 99 | object:url]; 100 | [backgroundThread start]; 101 | } 102 | 103 | - (void)networkFailedWithErrorMessage:(NSString *)message 104 | { 105 | // Update UI 106 | // 107 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 108 | NSLog(@" >> %@", message); 109 | 110 | self.receiveTextView.text = message; 111 | self.connectButton.enabled = YES; 112 | [self.networkActivityView stopAnimating]; 113 | }]; 114 | } 115 | 116 | - (void)networkSucceedWithData:(NSData *)data 117 | { 118 | // Update UI 119 | // 120 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 121 | NSString * resultsString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 122 | NSLog(@" >> Received string: '%@'", resultsString); 123 | 124 | self.receiveTextView.text = resultsString; 125 | self.connectButton.enabled = YES; 126 | [self.networkActivityView stopAnimating]; 127 | }]; 128 | } 129 | 130 | #pragma mark - 131 | #pragma mark NSStream 132 | 133 | - (void)didReceiveData:(NSData *)data { 134 | if (_receivedData == nil) { 135 | _receivedData = [[NSMutableData alloc] init]; 136 | } 137 | 138 | [_receivedData appendData:data]; 139 | 140 | // Update UI 141 | // 142 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 143 | NSString * resultsString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 144 | self.receiveTextView.text = resultsString; 145 | }]; 146 | } 147 | 148 | - (void)didFinishReceivingData 149 | { 150 | [self networkSucceedWithData:_receivedData]; 151 | } 152 | 153 | - (void)loadDataFromServerWithURL:(NSURL *)url 154 | { 155 | NSInputStream * readStream; 156 | [NSStream getStreamsToHostNamed:[url host] 157 | port:[[url port] integerValue] 158 | inputStream:&readStream 159 | outputStream:NULL]; 160 | 161 | [readStream setDelegate:self]; 162 | [readStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 163 | [readStream open]; 164 | 165 | [[NSRunLoop currentRunLoop] run]; 166 | } 167 | 168 | #pragma mark NSStreamDelegate 169 | 170 | - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode 171 | { 172 | NSLog(@" >> NSStreamDelegate in Thread %@", [NSThread currentThread]); 173 | 174 | switch (eventCode) { 175 | case NSStreamEventHasBytesAvailable: { 176 | if (_receivedData == nil) { 177 | _receivedData = [[NSMutableData alloc] init]; 178 | } 179 | 180 | uint8_t buf[kBufferSize]; 181 | int numBytesRead = [(NSInputStream *)stream read:buf maxLength:1024]; 182 | 183 | if (numBytesRead > 0) { 184 | [self didReceiveData:[NSData dataWithBytes:buf length:numBytesRead]]; 185 | 186 | } else if (numBytesRead == 0) { 187 | NSLog(@" >> End of stream reached"); 188 | 189 | } else { 190 | NSLog(@" >> Read error occurred"); 191 | } 192 | 193 | break; 194 | } 195 | 196 | case NSStreamEventErrorOccurred: { 197 | NSError * error = [stream streamError]; 198 | NSString * errorInfo = [NSString stringWithFormat:@"Failed while reading stream; error '%@' (code %d)", error.localizedDescription, error.code]; 199 | 200 | [self cleanUpStream:stream]; 201 | 202 | [self networkFailedWithErrorMessage:errorInfo]; 203 | } 204 | 205 | case NSStreamEventEndEncountered: { 206 | 207 | [self cleanUpStream:stream]; 208 | 209 | [self didFinishReceivingData]; 210 | 211 | break; 212 | } 213 | 214 | default: 215 | break; 216 | } 217 | } 218 | 219 | - (void)cleanUpStream:(NSStream *)stream 220 | { 221 | [stream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 222 | [stream close]; 223 | 224 | stream = nil; 225 | } 226 | 227 | @end 228 | --------------------------------------------------------------------------------