├── .gitignore ├── 01_NuWhatIsIt └── README ├── 02_LetsGetStarted ├── README └── RandomApp │ ├── English.lproj │ └── MainMenu.nib │ │ ├── classes.nib │ │ ├── info.nib │ │ └── keyedobjects.nib │ ├── Nukefile │ └── nu │ └── main.nu ├── 05_TargetAction └── Speakline │ ├── English.lproj │ └── MainMenu.nib │ │ ├── classes.nib │ │ ├── info.nib │ │ └── keyedobjects.nib │ ├── Nukefile │ └── nu │ └── main.nu ├── 06_Helpers ├── SpeakLine_A │ ├── English.lproj │ │ ├── InfoPlist.strings │ │ └── MainMenu.nib │ │ │ ├── designable.nib │ │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── Nukefile │ ├── SpeakLine.xcodeproj │ │ └── project.pbxproj │ ├── SpeakLine_Prefix.pch │ ├── main.m │ └── nu │ │ └── main.nu └── SpeakLine_B │ ├── English.lproj │ ├── InfoPlist.strings │ └── MainMenu.nib │ │ ├── designable.nib │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── Nukefile │ ├── SpeakLine.xcodeproj │ └── project.pbxproj │ ├── SpeakLine_Prefix.pch │ ├── main.m │ └── nu │ └── main.nu ├── 07_KVC ├── KVCFun_A │ ├── English.lproj │ │ ├── InfoPlist.strings │ │ └── MainMenu.nib │ │ │ ├── designable.nib │ │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── KVCFun.xcodeproj │ │ └── project.pbxproj │ ├── KVCFun_Prefix.pch │ ├── Nukefile │ ├── main.m │ └── nu │ │ └── main.nu └── KVCFun_FINAL │ ├── English.lproj │ ├── InfoPlist.strings │ └── MainMenu.nib │ │ ├── designable.nib │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── KVCFun.xcodeproj │ └── project.pbxproj │ ├── KVCFun_Prefix.pch │ ├── Nukefile │ ├── main.m │ └── nu │ └── main.nu ├── 08_ArrayController └── RaiseMan │ ├── English.lproj │ ├── Credits.rtf │ ├── InfoPlist.strings │ ├── MainMenu.nib │ │ ├── designable.nib │ │ └── keyedobjects.nib │ └── MyDocument.nib │ │ ├── designable.nib │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── Nukefile │ ├── RaiseMan.xcodeproj │ └── project.pbxproj │ ├── RaiseMan_Prefix.pch │ ├── main.m │ └── nu │ └── main.nu ├── 09_Undo ├── RaiseMan_A │ ├── English.lproj │ │ ├── Credits.rtf │ │ ├── InfoPlist.strings │ │ ├── MainMenu.nib │ │ │ ├── designable.nib │ │ │ └── keyedobjects.nib │ │ └── MyDocument.nib │ │ │ ├── designable.nib │ │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── RaiseMan.xcodeproj │ │ └── project.pbxproj │ ├── RaiseMan_Prefix.pch │ ├── main.m │ └── nu │ │ └── main.nu └── RaiseMan_B │ ├── English.lproj │ ├── Credits.rtf │ ├── InfoPlist.strings │ ├── MainMenu.nib │ │ ├── designable.nib │ │ └── keyedobjects.nib │ └── MyDocument.nib │ │ ├── designable.nib │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── RaiseMan.xcodeproj │ └── project.pbxproj │ ├── RaiseMan_Prefix.pch │ ├── main.m │ └── nu │ └── main.nu ├── 11_CoreData ├── CarLot_A │ ├── CarLot.xcodeproj │ │ └── project.pbxproj │ ├── CarLot_Prefix.pch │ ├── English.lproj │ │ ├── Credits.rtf │ │ ├── InfoPlist.strings │ │ ├── MainMenu.nib │ │ │ ├── classes.nib │ │ │ ├── info.nib │ │ │ └── keyedobjects.nib │ │ └── MyDocument.nib │ │ │ ├── classes.nib │ │ │ ├── info.nib │ │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── MyDocument.xcdatamodel │ │ ├── elements │ │ └── layout │ ├── main.m │ ├── nu │ │ └── main.nu │ └── version.plist └── CarLot_FINAL │ ├── CarLot.xcodeproj │ └── project.pbxproj │ ├── CarLot_Prefix.pch │ ├── English.lproj │ ├── Credits.rtf │ ├── InfoPlist.strings │ ├── MainMenu.nib │ │ ├── classes.nib │ │ ├── info.nib │ │ └── keyedobjects.nib │ └── MyDocument.nib │ │ ├── classes.nib │ │ ├── info.nib │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── MyDocument.h │ ├── MyDocument.m │ ├── MyDocument.xcdatamodel │ ├── elements │ └── layout │ ├── main.m │ ├── nu │ └── main.nu │ └── version.plist ├── 12_MultiNib └── RaiseMan │ ├── BBall.icns │ ├── English.lproj │ ├── Credits.rtf │ ├── InfoPlist.strings │ ├── MainMenu.nib │ │ ├── designable.nib │ │ └── keyedobjects.nib │ └── MyDocument.nib │ │ ├── designable.nib │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── Preferences.nib │ ├── classes.nib │ ├── info.nib │ └── keyedobjects.nib │ ├── RaiseMan.xcodeproj │ └── project.pbxproj │ ├── RaiseMan_Prefix.pch │ ├── main.m │ └── nu │ └── main.nu ├── 14_Notifications └── RaiseMan │ ├── BBall.icns │ ├── English.lproj │ ├── Credits.rtf │ ├── InfoPlist.strings │ ├── MainMenu.nib │ │ ├── designable.nib │ │ └── keyedobjects.nib │ └── MyDocument.nib │ │ ├── designable.nib │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── Preferences.nib │ ├── classes.nib │ ├── info.nib │ └── keyedobjects.nib │ ├── RaiseMan.xcodeproj │ ├── aaron.mode1v3 │ ├── paulp.mode1v3 │ └── project.pbxproj │ ├── RaiseMan_Prefix.pch │ ├── main.m │ └── nu │ └── main.nu ├── 18_MouseEvents └── ImageFun │ ├── English.lproj │ ├── InfoPlist.strings │ └── MainMenu.nib │ │ ├── designable.nib │ │ └── keyedobjects.nib │ ├── ImageFun.xcodeproj │ └── project.pbxproj │ ├── ImageFun_Prefix.pch │ ├── Info.plist │ ├── main.m │ └── nu │ └── main.nu ├── 19_KeyboardEvents └── TypingTutor │ ├── English.lproj │ ├── InfoPlist.strings │ └── MainMenu.nib │ │ ├── designable.nib │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── Nukefile │ ├── TypingTutor.xcodeproj │ └── project.pbxproj │ ├── TypingTutor_Prefix.pch │ ├── main.m │ └── nu │ └── main.nu ├── 28_WebServices └── AmaZone │ ├── AmaZone.xcodeproj │ └── project.pbxproj │ ├── AmaZone_Prefix.pch │ ├── English.lproj │ ├── InfoPlist.strings │ └── MainMenu.nib │ │ ├── classes.nib │ │ ├── info.nib │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── Nukefile │ ├── main.m │ └── nu │ └── main.nu ├── 29_ViewSwapping └── Departments │ ├── DepartmentView.nib │ ├── classes.nib │ ├── info.nib │ └── keyedobjects.nib │ ├── Departments.xcodeproj │ └── project.pbxproj │ ├── Departments_Prefix.pch │ ├── EmployeeView.nib │ ├── designable.nib │ └── keyedobjects.nib │ ├── English.lproj │ ├── Credits.rtf │ ├── InfoPlist.strings │ ├── MainMenu.nib │ │ ├── classes.nib │ │ ├── info.nib │ │ └── keyedobjects.nib │ └── MyDocument.nib │ │ ├── classes.nib │ │ ├── info.nib │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── MyDocument.xcdatamodel │ ├── elements │ └── layout │ ├── main.m │ ├── nu │ └── main.nu │ └── version.plist ├── 32_CoreAnimation └── LayerPolynomials │ ├── English.lproj │ ├── InfoPlist.strings │ └── MainMenu.nib │ │ ├── designable.nib │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── Nu │ └── main.nu │ ├── Polynomial.h │ ├── Polynomial.m │ ├── Polynomials.xcodeproj │ └── project.pbxproj │ ├── Polynomials_Prefix.pch │ └── main.m ├── 34_NSTask ├── ZIPspector │ ├── English.lproj │ │ ├── Credits.rtf │ │ ├── InfoPlist.strings │ │ ├── MainMenu.nib │ │ │ ├── designable.nib │ │ │ └── keyedobjects.nib │ │ └── MyDocument.nib │ │ │ ├── designable.nib │ │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── ZIPspector.xcodeproj │ │ └── project.pbxproj │ ├── ZIPspector_Prefix.pch │ ├── main.m │ └── nu │ │ └── main.nu └── iPing │ ├── English.lproj │ ├── InfoPlist.strings │ └── MainMenu.nib │ │ ├── designable.nib │ │ └── keyedobjects.nib │ ├── Info.plist │ ├── iPing.xcodeproj │ └── project.pbxproj │ ├── iPing_Prefix.pch │ ├── main.m │ └── nu │ └── main.nu └── README /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *build* 3 | *.app 4 | *.pbxuser 5 | *.perspectivev3 6 | *.mode1v3 7 | TemplateIcon.icns 8 | -------------------------------------------------------------------------------- /01_NuWhatIsIt/README: -------------------------------------------------------------------------------- 1 | (load "Nu:vision") -------------------------------------------------------------------------------- /02_LetsGetStarted/README: -------------------------------------------------------------------------------- 1 | This chapter teaches the basics of working with XCode 2 | and Interface Builder. The aspiring Nu programmer will 3 | need to know corresponding information about TextMate. 4 | 5 | I have opted to create these first few chapters in 6 | Interface Builder to demonstrate how IB can be used 7 | from Nu. Many would prefer to construct the interface 8 | in code, and there are plenty of examples how to do so. 9 | (See the RandomApp in the Nu source, for example.) -------------------------------------------------------------------------------- /02_LetsGetStarted/RandomApp/English.lproj/MainMenu.nib/classes.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBClasses 6 | 7 | 8 | ACTIONS 9 | 10 | generate 11 | id 12 | seed 13 | id 14 | 15 | CLASS 16 | Foo 17 | LANGUAGE 18 | ObjC 19 | OUTLETS 20 | 21 | textField 22 | id 23 | 24 | 25 | 26 | IBVersion 27 | 1 28 | 29 | 30 | -------------------------------------------------------------------------------- /02_LetsGetStarted/RandomApp/English.lproj/MainMenu.nib/info.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBFramework Version 6 | 629 7 | IBOldestOS 8 | 5 9 | IBOpenObjects 10 | 11 | 29 12 | 368 13 | 14 | IBSystem Version 15 | 9C7010 16 | targetFramework 17 | IBCocoaFramework 18 | 19 | 20 | -------------------------------------------------------------------------------- /02_LetsGetStarted/RandomApp/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/02_LetsGetStarted/RandomApp/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /02_LetsGetStarted/RandomApp/Nukefile: -------------------------------------------------------------------------------- 1 | ;; Nukefile for AmaZone 2 | 3 | ;; source files 4 | (set @nu_files (filelist "nu/.*\.nu$")) 5 | (set @nib_files (filelist "^English\.lproj/[^/]*\.nib$")) 6 | 7 | ;; application description 8 | (set @application "RandomApp") 9 | (set @application_identifier "nu.programming.randomapp") 10 | 11 | ;; build tasks 12 | (application-tasks) 13 | (task "default" => "application") 14 | -------------------------------------------------------------------------------- /02_LetsGetStarted/RandomApp/nu/main.nu: -------------------------------------------------------------------------------- 1 | ;; randomapp.nu 2 | 3 | ;; Rewritten from Cocoa Programming Third Edition 4 | ;; and Tim Burks original RandomApp in Nu. 5 | 6 | ;; Various things we need to include for Nu 7 | (load "Nu:nu") ;; basics 8 | (load "Nu:cocoa") ;; cocoa definitions 9 | (load "Nu:menu") ;; menu generation 10 | 11 | ;; Start by building the interface in Interface Builder 12 | ;; See the MainMenu.nib file in English.lproj/ 13 | 14 | ;; @class Foo 15 | ;; @description This controller class accepts the seed: and generate: 16 | ;; events and makes appropriate changes to textField. 17 | (class Foo is NSObject 18 | (ivar (id) textField) 19 | 20 | (- (void) seed: (id) sender is 21 | (NuMath srandom:((NSCalendarDate calendarDate) timeIntervalSince1970)) 22 | (@textField setStringValue:"generator seeded")) 23 | 24 | (- (void) generate: (id) sender is 25 | (@textField setIntValue:(+ 1 (% (NuMath random) 100))))) 26 | 27 | ;; Create an instance of Foo in Interface Builder, give it seed: and 28 | ;; generate: actions and a textField outlet. Connect these to the 29 | ;; appropriate interface elements. 30 | 31 | ;; this makes the application window take focus when we've started it from the terminal 32 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 33 | 34 | ;; run the main Cocoa event loop 35 | (NSApplicationMain 0 nil) 36 | -------------------------------------------------------------------------------- /05_TargetAction/Speakline/English.lproj/MainMenu.nib/classes.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBClasses 6 | 7 | 8 | ACTIONS 9 | 10 | changeTextColor 11 | id 12 | sayIt 13 | id 14 | stopIt 15 | id 16 | 17 | CLASS 18 | AppController 19 | LANGUAGE 20 | ObjC 21 | OUTLETS 22 | 23 | colorWell 24 | id 25 | textField 26 | id 27 | 28 | 29 | 30 | IBVersion 31 | 1 32 | 33 | 34 | -------------------------------------------------------------------------------- /05_TargetAction/Speakline/English.lproj/MainMenu.nib/info.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBFramework Version 6 | 629 7 | IBOldestOS 8 | 5 9 | IBOpenObjects 10 | 11 | 368 12 | 13 | IBSystem Version 14 | 9C7010 15 | targetFramework 16 | IBCocoaFramework 17 | 18 | 19 | -------------------------------------------------------------------------------- /05_TargetAction/Speakline/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/05_TargetAction/Speakline/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /05_TargetAction/Speakline/Nukefile: -------------------------------------------------------------------------------- 1 | ;; Nukefile for AmaZone 2 | 3 | ;; source files 4 | (set @nu_files (filelist "nu/.*\.nu$")) 5 | (set @nib_files (filelist "^English\.lproj/[^/]*\.nib$")) 6 | 7 | ;; application description 8 | (set @application "SpeakLine") 9 | (set @application_identifier "nu.programming.speakline") 10 | 11 | ;; build tasks 12 | (application-tasks) 13 | (task "default" => "application") 14 | -------------------------------------------------------------------------------- /05_TargetAction/Speakline/nu/main.nu: -------------------------------------------------------------------------------- 1 | ;; main.nu 2 | 3 | ;; Rewritten from Cocoa Programming, Second Edition 4 | ;; and Tim Burks' various Nu examples 5 | 6 | ;; Various things we need to include for Nu 7 | (load "Nu:nu") ;; basics 8 | (load "Nu:cocoa") ;; cocoa definitions 9 | (load "Nu:menu") ;; menu generation 10 | 11 | ;; Start by building the interface in Interface Builder 12 | ;; See the MainMenu.nib file in English.lproj/ 13 | 14 | ;; @class AppController 15 | ;; @description This controller class accepts the sayIt:, stopIt: 16 | ;; and changeTextColor: actions. 17 | (class AppController is NSObject 18 | (ivar (id) textField 19 | (id) colorWell 20 | (id) speechSynth) 21 | 22 | (- (id) init is 23 | (super init) 24 | (set @speechSynth ((NSSpeechSynthesizer alloc) initWithVoice:nil)) 25 | self) 26 | 27 | (- awakeFromNib is 28 | (@colorWell setColor:(@textField textColor))) 29 | 30 | (- changeTextColor:(id)sender is 31 | (@textField setTextColor:(@colorWell color))) 32 | 33 | (- sayIt:(id)sender is 34 | (@speechSynth startSpeakingString:(@textField stringValue))) 35 | 36 | (- stopIt:(id)sender is 37 | (@speechSynth stopSpeaking))) 38 | 39 | ;; Create an instance of Foo in Interface Builder, give it seed: and 40 | ;; generate: actions and a textField outlet. Connect these to the 41 | ;; appropriate interface elements. 42 | 43 | ;; this makes the application window take focus when we've started it from the terminal 44 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 45 | 46 | ;; run the main Cocoa event loop 47 | (NSApplicationMain 0 nil) 48 | -------------------------------------------------------------------------------- /06_Helpers/SpeakLine_A/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/06_Helpers/SpeakLine_A/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /06_Helpers/SpeakLine_A/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/06_Helpers/SpeakLine_A/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /06_Helpers/SpeakLine_A/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.yourcompany.SpeakLine 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | NSMainNibFile 24 | MainMenu 25 | NSPrincipalClass 26 | NSApplication 27 | 28 | 29 | -------------------------------------------------------------------------------- /06_Helpers/SpeakLine_A/Nukefile: -------------------------------------------------------------------------------- 1 | ;; Nukefile for SpeakLine 2 | 3 | ;; source files 4 | (set @nu_files (filelist "nu/.*\.nu$")) 5 | (set @resources (filelist "^English\.lproj/Infoplist.strings$")) 6 | (set @nib_files (filelist "^English\.lproj/[^/]*\.nib$")) 7 | 8 | ;; application description 9 | (set @application "SpeakLine") 10 | (set @application_identifier "nu.programming.speakline") 11 | 12 | ;; build tasks 13 | (application-tasks) 14 | (task "default" => "application") 15 | -------------------------------------------------------------------------------- /06_Helpers/SpeakLine_A/SpeakLine_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'SpeakLine' target in the 'SpeakLine' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /06_Helpers/SpeakLine_A/main.m: -------------------------------------------------------------------------------- 1 | int NuMain(int argc, const char *argv[]); 2 | 3 | int main(int argc, const char *argv[]) 4 | { 5 | return NuMain(argc, argv); 6 | } -------------------------------------------------------------------------------- /06_Helpers/SpeakLine_A/nu/main.nu: -------------------------------------------------------------------------------- 1 | (import Cocoa) ;; bridgesupport 2 | (load "console") ;; interactive console 3 | 4 | (class AppController is NSObject 5 | (ivar (id) textField (id) speechSynth (id) stopButton (id) startButton) 6 | 7 | (- (id) init is 8 | (super init) 9 | ;; Set the global variable $ac equal to the appController for easy access in the console. 10 | (set $ac self) 11 | (NSLog "init") 12 | (set @speechSynth ((NSSpeechSynthesizer alloc) initWithVoice:nil)) 13 | (@speechSynth setDelegate:self) 14 | self) 15 | 16 | (- (void) sayIt: (id) sender is 17 | (set string (@textField stringValue)) 18 | (unless (eq 0 (string length)) 19 | (@speechSynth startSpeakingString:string) 20 | (NSLog "Have started to say #{string}") 21 | (@stopButton setEnabled:YES) 22 | (@startButton setEnabled:NO))) 23 | 24 | (- (void) stopIt: (id) sender is 25 | (NSLog "stopping") 26 | (@speechSynth stopSpeaking)) 27 | 28 | (- (void) speechSynthesizer: (id) sender didFinishSpeaking: (BOOL) finishedNormally is 29 | (NSLog "didFinish:#{finishedNormally}") 30 | (@stopButton setEnabled:NO) 31 | (@startButton setEnabled:YES))) 32 | 33 | (set SHOW_CONSOLE_AT_STARTUP nil) 34 | 35 | ;; @class ApplicationDelegate 36 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 37 | (class ApplicationDelegate is NSObject 38 | 39 | ;; This method is called after Cocoa has finished its basic application setup. 40 | ;; It instantiates application-specific components. 41 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 42 | (- (void) applicationDidFinishLaunching:(id) sender is 43 | (set $console ((NuConsoleWindowController alloc) init)) 44 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 45 | 46 | ;; install the delegate and keep a reference to it since the application won't retain it. 47 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 48 | 49 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 50 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 51 | 52 | ;; run the main Cocoa event loop 53 | (NSApplicationMain 0 nil) 54 | -------------------------------------------------------------------------------- /06_Helpers/SpeakLine_B/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/06_Helpers/SpeakLine_B/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /06_Helpers/SpeakLine_B/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/06_Helpers/SpeakLine_B/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /06_Helpers/SpeakLine_B/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.yourcompany.SpeakLine 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | NSMainNibFile 24 | MainMenu 25 | NSPrincipalClass 26 | NSApplication 27 | 28 | 29 | -------------------------------------------------------------------------------- /06_Helpers/SpeakLine_B/Nukefile: -------------------------------------------------------------------------------- 1 | ;; Nukefile for SpeakLine 2 | 3 | ;; source files 4 | (set @nu_files (filelist "nu/.*\.nu$")) 5 | (set @resources (filelist "^English\.lproj/Infoplist.strings$")) 6 | (set @nib_files (filelist "^English\.lproj/[^/]*\.nib$")) 7 | 8 | ;; application description 9 | (set @application "SpeakLine") 10 | (set @application_identifier "nu.programming.speakline") 11 | 12 | ;; build tasks 13 | (application-tasks) 14 | (task "default" => "application") 15 | -------------------------------------------------------------------------------- /06_Helpers/SpeakLine_B/SpeakLine_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'SpeakLine' target in the 'SpeakLine' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /06_Helpers/SpeakLine_B/main.m: -------------------------------------------------------------------------------- 1 | int NuMain(int argc, const char *argv[]); 2 | 3 | int main(int argc, const char *argv[]) 4 | { 5 | return NuMain(argc, argv); 6 | } -------------------------------------------------------------------------------- /06_Helpers/SpeakLine_B/nu/main.nu: -------------------------------------------------------------------------------- 1 | (import Cocoa) ;; bridgesupport 2 | (load "console") ;; interactive console 3 | 4 | (class AppController is NSObject 5 | (ivar (id) textField (id) speechSynth (id) stopButton (id) startButton (id) voiceList (id) tableView) 6 | 7 | (- (id) init is 8 | (super init) 9 | ;; Set the global variable $ac equal to the appController for easy access in the console. 10 | (set $ac self) 11 | (set @speechSynth ((NSSpeechSynthesizer alloc) initWithVoice:nil)) 12 | (@speechSynth setDelegate:self) 13 | (set @voiceList (NSSpeechSynthesizer availableVoices)) 14 | self) 15 | 16 | (- (void) awakeFromNib is 17 | (set defaultVoice (NSSpeechSynthesizer defaultVoice)) 18 | (set defaultRow (@voiceList indexOfObject:defaultVoice)) 19 | (@tableView selectRow:defaultRow byExtendingSelection:NO) 20 | (@tableView scrollRowToVisible:defaultRow)) 21 | 22 | (- (void) sayIt: (id) sender is 23 | (set string (@textField stringValue)) 24 | (unless (eq 0 (string length)) 25 | (@speechSynth startSpeakingString:string) 26 | (NSLog "Have started to say #{string}") 27 | (@stopButton setEnabled:YES) 28 | (@startButton setEnabled:NO) 29 | (@tableView setEnabled:NO))) 30 | 31 | (- (void) stopIt: (id) sender is 32 | (NSLog "stopping") 33 | (@speechSynth stopSpeaking)) 34 | 35 | (- (void) speechSynthesizer: (id) sender didFinishSpeaking: (BOOL) finishedNormally is 36 | (NSLog "didFinish:#{finishedNormally}") 37 | (@stopButton setEnabled:NO) 38 | (@startButton setEnabled:YES) 39 | (@tableView setEnabled:YES)) 40 | 41 | (- (void) tableViewSelectionDidChange: (id) note is 42 | (set row (@tableView selectedRow)) 43 | (unless (eq row -1) 44 | (set selectedVoice (@voiceList row)) 45 | (@speechSynth setVoice:selectedVoice) 46 | (NSLog "new voice = #{selectedVoice}"))) 47 | 48 | (- (int) numberOfRowsInTableView: (id) tv is 49 | (@voiceList count)) 50 | 51 | (- (id) tableView: (id) tv objectValueForTableColumn: (id) tc row: (int) row is 52 | (set dict (NSSpeechSynthesizer attributesForVoice:(@voiceList row))) 53 | (dict objectForKey:NSVoiceName))) 54 | 55 | (set SHOW_CONSOLE_AT_STARTUP nil) 56 | 57 | ;; @class ApplicationDelegate 58 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 59 | (class ApplicationDelegate is NSObject 60 | 61 | ;; This method is called after Cocoa has finished its basic application setup. 62 | ;; It instantiates application-specific components. 63 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 64 | (- (void) applicationDidFinishLaunching:(id) sender is 65 | (set $console ((NuConsoleWindowController alloc) init)) 66 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 67 | 68 | ;; install the delegate and keep a reference to it since the application won't retain it. 69 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 70 | 71 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 72 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 73 | 74 | ;; run the main Cocoa event loop 75 | (NSApplicationMain 0 nil) 76 | -------------------------------------------------------------------------------- /07_KVC/KVCFun_A/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/07_KVC/KVCFun_A/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /07_KVC/KVCFun_A/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/07_KVC/KVCFun_A/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /07_KVC/KVCFun_A/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.yourcompany.KVCFun 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | NSMainNibFile 24 | MainMenu 25 | NSPrincipalClass 26 | NSApplication 27 | 28 | 29 | -------------------------------------------------------------------------------- /07_KVC/KVCFun_A/KVCFun.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 45; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; }; 11 | 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; }; 12 | 8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; }; 13 | 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; 14 | AB79517C0DEB859500DCF3C8 /* main.nu in Resources */ = {isa = PBXBuildFile; fileRef = AB79517B0DEB859500DCF3C8 /* main.nu */; }; 15 | AB79517E0DEB85A800DCF3C8 /* Nu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB79517D0DEB85A800DCF3C8 /* Nu.framework */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; }; 20 | 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; 21 | 13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = ""; }; 22 | 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 23 | 29B97319FDCFA39411CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MainMenu.nib; sourceTree = ""; }; 24 | 29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = ""; }; 25 | 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; 26 | 32CA4F630368D1EE00C91783 /* KVCFun_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KVCFun_Prefix.pch; sourceTree = ""; }; 27 | 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | 8D1107320486CEB800E47090 /* KVCFun.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KVCFun.app; sourceTree = BUILT_PRODUCTS_DIR; }; 29 | AB79517B0DEB859500DCF3C8 /* main.nu */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.nu; path = nu/main.nu; sourceTree = ""; }; 30 | AB79517D0DEB85A800DCF3C8 /* Nu.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nu.framework; path = /Library/Frameworks/Nu.framework; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | 8D11072E0486CEB800E47090 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */, 39 | AB79517E0DEB85A800DCF3C8 /* Nu.framework in Frameworks */, 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXFrameworksBuildPhase section */ 44 | 45 | /* Begin PBXGroup section */ 46 | 080E96DDFE201D6D7F000001 /* Nu */ = { 47 | isa = PBXGroup; 48 | children = ( 49 | AB79517B0DEB859500DCF3C8 /* main.nu */, 50 | ); 51 | name = Nu; 52 | sourceTree = ""; 53 | }; 54 | 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */, 58 | ); 59 | name = "Linked Frameworks"; 60 | sourceTree = ""; 61 | }; 62 | 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | 29B97324FDCFA39411CA2CEA /* AppKit.framework */, 66 | 13E42FB307B3F0F600E4EEF1 /* CoreData.framework */, 67 | 29B97325FDCFA39411CA2CEA /* Foundation.framework */, 68 | ); 69 | name = "Other Frameworks"; 70 | sourceTree = ""; 71 | }; 72 | 19C28FACFE9D520D11CA2CBB /* Products */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 8D1107320486CEB800E47090 /* KVCFun.app */, 76 | ); 77 | name = Products; 78 | sourceTree = ""; 79 | }; 80 | 29B97314FDCFA39411CA2CEA /* KVCFun */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | 080E96DDFE201D6D7F000001 /* Nu */, 84 | 29B97315FDCFA39411CA2CEA /* Other Sources */, 85 | 29B97317FDCFA39411CA2CEA /* Resources */, 86 | 29B97323FDCFA39411CA2CEA /* Frameworks */, 87 | 19C28FACFE9D520D11CA2CBB /* Products */, 88 | ); 89 | name = KVCFun; 90 | sourceTree = ""; 91 | }; 92 | 29B97315FDCFA39411CA2CEA /* Other Sources */ = { 93 | isa = PBXGroup; 94 | children = ( 95 | 32CA4F630368D1EE00C91783 /* KVCFun_Prefix.pch */, 96 | 29B97316FDCFA39411CA2CEA /* main.m */, 97 | ); 98 | name = "Other Sources"; 99 | sourceTree = ""; 100 | }; 101 | 29B97317FDCFA39411CA2CEA /* Resources */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 8D1107310486CEB800E47090 /* Info.plist */, 105 | 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */, 106 | 29B97318FDCFA39411CA2CEA /* MainMenu.nib */, 107 | ); 108 | name = Resources; 109 | sourceTree = ""; 110 | }; 111 | 29B97323FDCFA39411CA2CEA /* Frameworks */ = { 112 | isa = PBXGroup; 113 | children = ( 114 | AB79517D0DEB85A800DCF3C8 /* Nu.framework */, 115 | 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */, 116 | 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */, 117 | ); 118 | name = Frameworks; 119 | sourceTree = ""; 120 | }; 121 | /* End PBXGroup section */ 122 | 123 | /* Begin PBXNativeTarget section */ 124 | 8D1107260486CEB800E47090 /* KVCFun */ = { 125 | isa = PBXNativeTarget; 126 | buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "KVCFun" */; 127 | buildPhases = ( 128 | 8D1107290486CEB800E47090 /* Resources */, 129 | 8D11072C0486CEB800E47090 /* Sources */, 130 | 8D11072E0486CEB800E47090 /* Frameworks */, 131 | ); 132 | buildRules = ( 133 | ); 134 | dependencies = ( 135 | ); 136 | name = KVCFun; 137 | productInstallPath = "$(HOME)/Applications"; 138 | productName = KVCFun; 139 | productReference = 8D1107320486CEB800E47090 /* KVCFun.app */; 140 | productType = "com.apple.product-type.application"; 141 | }; 142 | /* End PBXNativeTarget section */ 143 | 144 | /* Begin PBXProject section */ 145 | 29B97313FDCFA39411CA2CEA /* Project object */ = { 146 | isa = PBXProject; 147 | buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "KVCFun" */; 148 | compatibilityVersion = "Xcode 3.1"; 149 | hasScannedForEncodings = 1; 150 | mainGroup = 29B97314FDCFA39411CA2CEA /* KVCFun */; 151 | projectDirPath = ""; 152 | projectRoot = ""; 153 | targets = ( 154 | 8D1107260486CEB800E47090 /* KVCFun */, 155 | ); 156 | }; 157 | /* End PBXProject section */ 158 | 159 | /* Begin PBXResourcesBuildPhase section */ 160 | 8D1107290486CEB800E47090 /* Resources */ = { 161 | isa = PBXResourcesBuildPhase; 162 | buildActionMask = 2147483647; 163 | files = ( 164 | 8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */, 165 | 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */, 166 | AB79517C0DEB859500DCF3C8 /* main.nu in Resources */, 167 | ); 168 | runOnlyForDeploymentPostprocessing = 0; 169 | }; 170 | /* End PBXResourcesBuildPhase section */ 171 | 172 | /* Begin PBXSourcesBuildPhase section */ 173 | 8D11072C0486CEB800E47090 /* Sources */ = { 174 | isa = PBXSourcesBuildPhase; 175 | buildActionMask = 2147483647; 176 | files = ( 177 | 8D11072D0486CEB800E47090 /* main.m in Sources */, 178 | ); 179 | runOnlyForDeploymentPostprocessing = 0; 180 | }; 181 | /* End PBXSourcesBuildPhase section */ 182 | 183 | /* Begin PBXVariantGroup section */ 184 | 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */ = { 185 | isa = PBXVariantGroup; 186 | children = ( 187 | 089C165DFE840E0CC02AAC07 /* English */, 188 | ); 189 | name = InfoPlist.strings; 190 | sourceTree = ""; 191 | }; 192 | 29B97318FDCFA39411CA2CEA /* MainMenu.nib */ = { 193 | isa = PBXVariantGroup; 194 | children = ( 195 | 29B97319FDCFA39411CA2CEA /* English */, 196 | ); 197 | name = MainMenu.nib; 198 | sourceTree = ""; 199 | }; 200 | /* End PBXVariantGroup section */ 201 | 202 | /* Begin XCBuildConfiguration section */ 203 | C01FCF4B08A954540054247B /* Debug */ = { 204 | isa = XCBuildConfiguration; 205 | buildSettings = { 206 | ALWAYS_SEARCH_USER_PATHS = NO; 207 | COPY_PHASE_STRIP = NO; 208 | GCC_DYNAMIC_NO_PIC = NO; 209 | GCC_ENABLE_FIX_AND_CONTINUE = YES; 210 | GCC_MODEL_TUNING = G5; 211 | GCC_OPTIMIZATION_LEVEL = 0; 212 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 213 | GCC_PREFIX_HEADER = KVCFun_Prefix.pch; 214 | INFOPLIST_FILE = Info.plist; 215 | INSTALL_PATH = "$(HOME)/Applications"; 216 | PRODUCT_NAME = KVCFun; 217 | }; 218 | name = Debug; 219 | }; 220 | C01FCF4C08A954540054247B /* Release */ = { 221 | isa = XCBuildConfiguration; 222 | buildSettings = { 223 | ALWAYS_SEARCH_USER_PATHS = NO; 224 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 225 | GCC_MODEL_TUNING = G5; 226 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 227 | GCC_PREFIX_HEADER = KVCFun_Prefix.pch; 228 | INFOPLIST_FILE = Info.plist; 229 | INSTALL_PATH = "$(HOME)/Applications"; 230 | PRODUCT_NAME = KVCFun; 231 | }; 232 | name = Release; 233 | }; 234 | C01FCF4F08A954540054247B /* Debug */ = { 235 | isa = XCBuildConfiguration; 236 | buildSettings = { 237 | ALWAYS_SEARCH_USER_PATHS = NO; 238 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 239 | GCC_OPTIMIZATION_LEVEL = 0; 240 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 241 | GCC_WARN_UNUSED_VARIABLE = YES; 242 | ONLY_ACTIVE_ARCH = YES; 243 | PREBINDING = NO; 244 | SDKROOT = macosx10.5; 245 | }; 246 | name = Debug; 247 | }; 248 | C01FCF5008A954540054247B /* Release */ = { 249 | isa = XCBuildConfiguration; 250 | buildSettings = { 251 | ALWAYS_SEARCH_USER_PATHS = NO; 252 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 253 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 254 | GCC_WARN_UNUSED_VARIABLE = YES; 255 | PREBINDING = NO; 256 | SDKROOT = macosx10.5; 257 | }; 258 | name = Release; 259 | }; 260 | /* End XCBuildConfiguration section */ 261 | 262 | /* Begin XCConfigurationList section */ 263 | C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "KVCFun" */ = { 264 | isa = XCConfigurationList; 265 | buildConfigurations = ( 266 | C01FCF4B08A954540054247B /* Debug */, 267 | C01FCF4C08A954540054247B /* Release */, 268 | ); 269 | defaultConfigurationIsVisible = 0; 270 | defaultConfigurationName = Release; 271 | }; 272 | C01FCF4E08A954540054247B /* Build configuration list for PBXProject "KVCFun" */ = { 273 | isa = XCConfigurationList; 274 | buildConfigurations = ( 275 | C01FCF4F08A954540054247B /* Debug */, 276 | C01FCF5008A954540054247B /* Release */, 277 | ); 278 | defaultConfigurationIsVisible = 0; 279 | defaultConfigurationName = Release; 280 | }; 281 | /* End XCConfigurationList section */ 282 | }; 283 | rootObject = 29B97313FDCFA39411CA2CEA /* Project object */; 284 | } 285 | -------------------------------------------------------------------------------- /07_KVC/KVCFun_A/KVCFun_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'KVCFun' target in the 'KVCFun' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /07_KVC/KVCFun_A/Nukefile: -------------------------------------------------------------------------------- 1 | ;; Nukefile for KVCFun 2 | 3 | ;; source files 4 | (set @nu_files (filelist "nu/.*\.nu$")) 5 | (set @resources (filelist "^English\.lproj/Infoplist.strings$")) 6 | (set @nib_files (filelist "^English\.lproj/[^/]*\.nib$")) 7 | 8 | ;; application description 9 | (set @application "KVCFun") 10 | (set @application_identifier "nu.programming.kvcfun") 11 | 12 | ;; build tasks 13 | (application-tasks) 14 | (task "default" => "application") 15 | -------------------------------------------------------------------------------- /07_KVC/KVCFun_A/main.m: -------------------------------------------------------------------------------- 1 | int NuMain(int argc, const char *argv[]); 2 | 3 | int main(int argc, const char *argv[]) 4 | { 5 | return NuMain(argc, argv); 6 | } -------------------------------------------------------------------------------- /07_KVC/KVCFun_A/nu/main.nu: -------------------------------------------------------------------------------- 1 | (import Cocoa) ;; bridgesupport 2 | (load "console") ;; interactive console 3 | 4 | (class AppController is NSObject 5 | (ivar (int) fido) 6 | 7 | (- (id) init is 8 | (super init) 9 | ;; Set the global variable $ac equal to the appController for easy access in the console. 10 | (set $ac self) 11 | (self setValue:5 forKey:"fido") 12 | (set n (self valueForKey:"fido")) 13 | (NSLog "fido = #{n}") 14 | self) 15 | 16 | (- (void) incrementFido: (id) sender is 17 | ;; We don't need to call willChangeValueForKey or didChangeValueForKey 18 | (set @fido (+ @fido 1)) 19 | (NSLog "fido is now #{@fido}")) 20 | 21 | (- (int) fido is 22 | (NSLog "-fido is returning #{@fido}") 23 | @fido) 24 | 25 | (- (void) setFido: (int) x is 26 | (NSLog "-setFido: is called with #{x}") 27 | (set @fido x))) 28 | 29 | 30 | (set SHOW_CONSOLE_AT_STARTUP nil) 31 | 32 | ;; @class ApplicationDelegate 33 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 34 | (class ApplicationDelegate is NSObject 35 | 36 | ;; This method is called after Cocoa has finished its basic application setup. 37 | ;; It instantiates application-specific components. 38 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 39 | (- (void) applicationDidFinishLaunching:(id) sender is 40 | (set $console ((NuConsoleWindowController alloc) init)) 41 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 42 | 43 | ;; install the delegate and keep a reference to it since the application won't retain it. 44 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 45 | 46 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 47 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 48 | 49 | ;; run the main Cocoa event loop 50 | (NSApplicationMain 0 nil) 51 | -------------------------------------------------------------------------------- /07_KVC/KVCFun_FINAL/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/07_KVC/KVCFun_FINAL/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /07_KVC/KVCFun_FINAL/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/07_KVC/KVCFun_FINAL/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /07_KVC/KVCFun_FINAL/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.yourcompany.KVCFun 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | NSMainNibFile 24 | MainMenu 25 | NSPrincipalClass 26 | NSApplication 27 | 28 | 29 | -------------------------------------------------------------------------------- /07_KVC/KVCFun_FINAL/KVCFun_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'KVCFun' target in the 'KVCFun' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /07_KVC/KVCFun_FINAL/Nukefile: -------------------------------------------------------------------------------- 1 | ;; Nukefile for KVCFun 2 | 3 | ;; source files 4 | (set @nu_files (filelist "nu/.*\.nu$")) 5 | (set @resources (filelist "^English\.lproj/Infoplist.strings$")) 6 | (set @nib_files (filelist "^English\.lproj/[^/]*\.nib$")) 7 | 8 | ;; application description 9 | (set @application "KVCFun") 10 | (set @application_identifier "nu.programming.kvcfun") 11 | 12 | ;; build tasks 13 | (application-tasks) 14 | (task "default" => "application") 15 | -------------------------------------------------------------------------------- /07_KVC/KVCFun_FINAL/main.m: -------------------------------------------------------------------------------- 1 | int NuMain(int argc, const char *argv[]); 2 | 3 | int main(int argc, const char *argv[]) 4 | { 5 | return NuMain(argc, argv); 6 | } -------------------------------------------------------------------------------- /07_KVC/KVCFun_FINAL/nu/main.nu: -------------------------------------------------------------------------------- 1 | (import Cocoa) ;; bridgesupport 2 | (load "console") ;; interactive console 3 | 4 | (class AppController is NSObject 5 | (ivar (int) fido) 6 | (ivar-accessors) ;; The Nu equivalent of @synthesize 7 | 8 | (- (id) init is 9 | (super init) 10 | ;; Set the global variable $ac equal to the appController for easy access in the console. 11 | (set $ac self) 12 | (self setValue:5 forKey:"fido") 13 | (set n (self valueForKey:"fido")) 14 | (NSLog "fido = #{n}") 15 | self) 16 | 17 | (- (void) incrementFido: (id) sender is 18 | ;; We don't need to call willChangeValueForKey or didChangeValueForKey 19 | (set @fido (+ @fido 1)) 20 | (NSLog "fido is now #{@fido}"))) 21 | 22 | (set SHOW_CONSOLE_AT_STARTUP nil) 23 | 24 | ;; @class ApplicationDelegate 25 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 26 | (class ApplicationDelegate is NSObject 27 | 28 | ;; This method is called after Cocoa has finished its basic application setup. 29 | ;; It instantiates application-specific components. 30 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 31 | (- (void) applicationDidFinishLaunching:(id) sender is 32 | (set $console ((NuConsoleWindowController alloc) init)) 33 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 34 | 35 | ;; install the delegate and keep a reference to it since the application won't retain it. 36 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 37 | 38 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 39 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 40 | 41 | ;; run the main Cocoa event loop 42 | (NSApplicationMain 0 nil) 43 | -------------------------------------------------------------------------------- /08_ArrayController/RaiseMan/English.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /08_ArrayController/RaiseMan/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/08_ArrayController/RaiseMan/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /08_ArrayController/RaiseMan/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/08_ArrayController/RaiseMan/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /08_ArrayController/RaiseMan/English.lproj/MyDocument.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/08_ArrayController/RaiseMan/English.lproj/MyDocument.nib/keyedobjects.nib -------------------------------------------------------------------------------- /08_ArrayController/RaiseMan/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeExtensions 11 | 12 | ???? 13 | 14 | CFBundleTypeIconFile 15 | 16 | CFBundleTypeName 17 | DocumentType 18 | CFBundleTypeOSTypes 19 | 20 | ???? 21 | 22 | CFBundleTypeRole 23 | Editor 24 | NSDocumentClass 25 | MyDocument 26 | 27 | 28 | CFBundleExecutable 29 | ${EXECUTABLE_NAME} 30 | CFBundleIconFile 31 | 32 | CFBundleIdentifier 33 | com.yourcompany.RaiseMan 34 | CFBundleInfoDictionaryVersion 35 | 6.0 36 | CFBundleName 37 | ${PRODUCT_NAME} 38 | CFBundlePackageType 39 | APPL 40 | CFBundleSignature 41 | ???? 42 | CFBundleVersion 43 | 1.0 44 | NSMainNibFile 45 | MainMenu 46 | NSPrincipalClass 47 | NSApplication 48 | 49 | 50 | -------------------------------------------------------------------------------- /08_ArrayController/RaiseMan/Nukefile: -------------------------------------------------------------------------------- 1 | ;; Nukefile for RaiseMan 2 | 3 | ;; source files 4 | (set @nu_files (filelist "nu/.*\.nu$")) 5 | (set @resources (filelist "^English\.lproj/InfoPlist.strings$")) 6 | (@resources unionSet:(filelist "^English\.lproj/Credits.rtf$")) 7 | (set @nib_files (filelist "^English\.lproj/[^/]*\.nib$")) 8 | 9 | ;; specify the document type, this will be added into the standard Info.plist generated by nuke. 10 | (set @info 11 | (dict "CFBundleDocumentTypes" 12 | (array (dict "CFBundleTypeName" "DocumentType" 13 | "CFBundleTypeRole" "Editor" 14 | "NSDocumentClass" "MyDocument")))) 15 | 16 | ;; application description 17 | (set @application "RaiseMan") 18 | (set @application_identifier "nu.programming.raiseman") 19 | 20 | ;; build tasks 21 | (application-tasks) 22 | (task "default" => "application") 23 | -------------------------------------------------------------------------------- /08_ArrayController/RaiseMan/RaiseMan_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'RaiseMan' target in the 'RaiseMan' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /08_ArrayController/RaiseMan/main.m: -------------------------------------------------------------------------------- 1 | int NuMain(int argc, const char *argv[]); 2 | 3 | int main(int argc, const char *argv[]) 4 | { 5 | return NuMain(argc, argv); 6 | } -------------------------------------------------------------------------------- /08_ArrayController/RaiseMan/nu/main.nu: -------------------------------------------------------------------------------- 1 | (import Cocoa) ;; bridgesupport 2 | (load "console") ;; interactive console 3 | 4 | (class Person is NSObject 5 | (ivar (id) personName (float) expectedRaise) 6 | (ivar-accessors) 7 | 8 | (- (id) init is 9 | (super init) 10 | (set @expectedRaise 5.0) 11 | (set @personName "New Person") 12 | self) 13 | 14 | (- (void) setNilValueForKey: (id) key is 15 | (if (key isEqual:"expectedRaise") 16 | (self setExpectedRaise:0.0) 17 | (else (super setNilValueForKey:key))))) 18 | 19 | (class MyDocument is NSDocument 20 | (ivar (id) employees) 21 | 22 | (- (id) init is 23 | (super init) 24 | (set @employees (array)) 25 | (return self)) 26 | 27 | (- (id)windowNibName is "MyDocument") 28 | 29 | (- (void)windowControllerDidLoadNib:(id)windowController is 30 | (super windowControllerDidLoadNib:windowController) 31 | ;; user interface preparation code 32 | ) 33 | 34 | (- (void) setEmployees: (id) a is 35 | (set @employees a))) 36 | 37 | (set SHOW_CONSOLE_AT_STARTUP nil) 38 | 39 | ;; @class ApplicationDelegate 40 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 41 | (class ApplicationDelegate is NSObject 42 | 43 | ;; This method is called after Cocoa has finished its basic application setup. 44 | ;; It instantiates application-specific components. 45 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 46 | (- (void) applicationDidFinishLaunching:(id) sender is 47 | (set $console ((NuConsoleWindowController alloc) init)) 48 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 49 | 50 | ;; install the delegate and keep a reference to it since the application won't retain it. 51 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 52 | 53 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 54 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 55 | 56 | ;; run the main Cocoa event loop 57 | (NSApplicationMain 0 nil) 58 | -------------------------------------------------------------------------------- /09_Undo/RaiseMan_A/English.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /09_Undo/RaiseMan_A/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/09_Undo/RaiseMan_A/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /09_Undo/RaiseMan_A/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/09_Undo/RaiseMan_A/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /09_Undo/RaiseMan_A/English.lproj/MyDocument.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/09_Undo/RaiseMan_A/English.lproj/MyDocument.nib/keyedobjects.nib -------------------------------------------------------------------------------- /09_Undo/RaiseMan_A/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeExtensions 11 | 12 | ???? 13 | 14 | CFBundleTypeIconFile 15 | 16 | CFBundleTypeName 17 | DocumentType 18 | CFBundleTypeOSTypes 19 | 20 | ???? 21 | 22 | CFBundleTypeRole 23 | Editor 24 | NSDocumentClass 25 | MyDocument 26 | 27 | 28 | CFBundleExecutable 29 | ${EXECUTABLE_NAME} 30 | CFBundleIconFile 31 | 32 | CFBundleIdentifier 33 | com.yourcompany.RaiseMan 34 | CFBundleInfoDictionaryVersion 35 | 6.0 36 | CFBundleName 37 | ${PRODUCT_NAME} 38 | CFBundlePackageType 39 | APPL 40 | CFBundleSignature 41 | ???? 42 | CFBundleVersion 43 | 1.0 44 | NSMainNibFile 45 | MainMenu 46 | NSPrincipalClass 47 | NSApplication 48 | 49 | 50 | -------------------------------------------------------------------------------- /09_Undo/RaiseMan_A/RaiseMan_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'RaiseMan' target in the 'RaiseMan' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /09_Undo/RaiseMan_A/main.m: -------------------------------------------------------------------------------- 1 | int NuMain(int argc, const char *argv[]); 2 | 3 | int main(int argc, const char *argv[]) 4 | { 5 | return NuMain(argc, argv); 6 | } -------------------------------------------------------------------------------- /09_Undo/RaiseMan_A/nu/main.nu: -------------------------------------------------------------------------------- 1 | (import Cocoa) ;; bridgesupport 2 | (load "console") ;; interactive console 3 | 4 | (class Person is NSObject 5 | (ivar (id) personName (float) expectedRaise) 6 | (ivar-accessors) 7 | 8 | (- (id) init is 9 | (super init) 10 | (set @expectedRaise 5.0) 11 | (set @personName "New Person") 12 | self) 13 | 14 | (- (void) setNilValueForKey: (id) key is 15 | (if (key isEqual:"expectedRaise") 16 | (self setExpectedRaise:0.0) 17 | (else (super setNilValueForKey:key))))) 18 | 19 | (class MyDocument is NSDocument 20 | (ivar (id) employees) 21 | 22 | (- (id) init is 23 | (super init) 24 | (self setEmployees:(array)) 25 | self) 26 | 27 | (- (void) startObservingPerson: (id) person is 28 | (person addObserver:self 29 | forKeyPath:"personName" 30 | options:NSKeyValueObservingOptionOld 31 | context:nil) 32 | (person addObserver:self 33 | forKeyPath:"expectedRaise" 34 | options:NSKeyValueObservingOptionOld 35 | context:nil)) 36 | 37 | (- (void) stopObservingPerson: (id) person is 38 | (person removeObserver:self forKeyPath:"personName") 39 | (person removeObserver:self forKeyPath:"expectedRaise")) 40 | 41 | (- (void) insertObject: (id) p inEmployeesAtIndex: (int) r is 42 | ;; Register the undo 43 | (set undo (self undoManager)) 44 | ((undo prepareWithInvocationTarget:self) 45 | removeObjectFromEmployeesAtIndex:r) 46 | (unless (undo isUndoing) 47 | (undo setActionName:"Insert Person")) 48 | ;; Add the person to the array 49 | (self startObservingPerson:p) 50 | (@employees insertObject:p atIndex:r)) 51 | 52 | (- (void) removeObjectFromEmployeesAtIndex: (int) r is 53 | (set p (@employees r)) 54 | (set undo (self undoManager)) 55 | ((undo prepareWithInvocationTarget:self) 56 | insertObject:p inEmployeesAtIndex:r) 57 | (unless (undo isUndoing) 58 | (undo setActionName:"Delete Person")) 59 | (self stopObservingPerson:p) 60 | (@employees removeObjectAtIndex:r)) 61 | 62 | (- (void) setEmployees: (id) arr is 63 | (@employees each:(do (p) (self stopObservingPerson:p))) 64 | (set @employees arr) 65 | (@employees each:(do (p) (self startObservingPerson:p)))) 66 | 67 | (- (void) changeKeyPath: (id) keyPath ofObject: (id) obj toValue:(id) newValue is 68 | (obj setValue:newValue forKeyPath:keyPath)) 69 | 70 | (- (void) observeValueForKeyPath: (id) keyPath ofObject: (id) obj 71 | change: (id) change context: (id) context is 72 | (set undo (self undoManager)) 73 | (set oldValue (change objectForKey:NSKeyValueChangeOldKey)) 74 | (if (eq oldValue (NSNull null)) 75 | (set oldValue nil)) 76 | (NSLog "oldValue = #{oldValue}") 77 | ((undo prepareWithInvocationTarget:self) 78 | changeKeyPath:keyPath ofObject:obj toValue:oldValue) 79 | (undo setActionName:"Edit")) 80 | 81 | (- (id) windowNibName is "MyDocument") 82 | 83 | (- (void) windowControllerDidLoadNib: (id) aController is 84 | (super windowControllerDidLoadNib:aController) 85 | ;; Add any code here that needs to be executed once the windowController has loaded the document's window. 86 | )) 87 | 88 | (set SHOW_CONSOLE_AT_STARTUP nil) 89 | 90 | ;; @class ApplicationDelegate 91 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 92 | (class ApplicationDelegate is NSObject 93 | 94 | ;; This method is called after Cocoa has finished its basic application setup. 95 | ;; It instantiates application-specific components. 96 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 97 | (- (void) applicationDidFinishLaunching:(id) sender is 98 | (set $console ((NuConsoleWindowController alloc) init)) 99 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 100 | 101 | ;; install the delegate and keep a reference to it since the application won't retain it. 102 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 103 | 104 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 105 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 106 | 107 | ;; run the main Cocoa event loop 108 | (NSApplicationMain 0 nil) 109 | -------------------------------------------------------------------------------- /09_Undo/RaiseMan_B/English.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /09_Undo/RaiseMan_B/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/09_Undo/RaiseMan_B/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /09_Undo/RaiseMan_B/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/09_Undo/RaiseMan_B/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /09_Undo/RaiseMan_B/English.lproj/MyDocument.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/09_Undo/RaiseMan_B/English.lproj/MyDocument.nib/keyedobjects.nib -------------------------------------------------------------------------------- /09_Undo/RaiseMan_B/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeExtensions 11 | 12 | ???? 13 | 14 | CFBundleTypeIconFile 15 | 16 | CFBundleTypeName 17 | DocumentType 18 | CFBundleTypeOSTypes 19 | 20 | ???? 21 | 22 | CFBundleTypeRole 23 | Editor 24 | NSDocumentClass 25 | MyDocument 26 | 27 | 28 | CFBundleExecutable 29 | ${EXECUTABLE_NAME} 30 | CFBundleIconFile 31 | 32 | CFBundleIdentifier 33 | com.yourcompany.RaiseMan 34 | CFBundleInfoDictionaryVersion 35 | 6.0 36 | CFBundleName 37 | ${PRODUCT_NAME} 38 | CFBundlePackageType 39 | APPL 40 | CFBundleSignature 41 | ???? 42 | CFBundleVersion 43 | 1.0 44 | NSMainNibFile 45 | MainMenu 46 | NSPrincipalClass 47 | NSApplication 48 | 49 | 50 | -------------------------------------------------------------------------------- /09_Undo/RaiseMan_B/RaiseMan_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'RaiseMan' target in the 'RaiseMan' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /09_Undo/RaiseMan_B/main.m: -------------------------------------------------------------------------------- 1 | int NuMain(int argc, const char *argv[]); 2 | 3 | int main(int argc, const char *argv[]) 4 | { 5 | return NuMain(argc, argv); 6 | } -------------------------------------------------------------------------------- /09_Undo/RaiseMan_B/nu/main.nu: -------------------------------------------------------------------------------- 1 | (import Cocoa) ;; bridgesupport 2 | (load "console") ;; interactive console 3 | 4 | (class Person is NSObject 5 | (ivar (id) personName (float) expectedRaise) 6 | (ivar-accessors) 7 | 8 | (- (id) init is 9 | (super init) 10 | (set @expectedRaise 5.0) 11 | (set @personName "New Person") 12 | self) 13 | 14 | (- (void) setNilValueForKey: (id) key is 15 | (if (key isEqual:"expectedRaise") 16 | (self setExpectedRaise:0.0) 17 | (else (super setNilValueForKey:key))))) 18 | 19 | (class MyDocument is NSDocument 20 | (ivar (id) employees (id) employeeController (id) tableView) 21 | 22 | (- (id) init is 23 | (super init) 24 | (self setEmployees:(array)) 25 | self) 26 | 27 | (- (BOOL) endEditing is 28 | (set w (@tableView window)) 29 | (set editingEnded (w makeFirstResponder:w)) 30 | (unless (editingEnded) NO) 31 | (set undo (self undoManager)) 32 | (if (undo groupingLevel) 33 | (undo endUndoGrouping) 34 | (undo beginUndoGrouping)) 35 | YES) 36 | 37 | (- (void) createEmployee: (id) sender is 38 | ; If a field is being edited, end editing 39 | (unless (eq NO (self endEditing)) 40 | 41 | (set p (@employeeController newObject)) 42 | (@employeeController addObject:p) 43 | 44 | ; In case the user has sorted the content array 45 | (@employeeController rearrangeObjects) 46 | 47 | ; Find the row of the new object 48 | (set a (@employeeController arrangedObjects)) 49 | (set row (a indexOfObjectIdenticalTo:p)) 50 | 51 | ; Start editing in the first column 52 | (@tableView editColumn:0 row:row withEvent:nil select:YES))) 53 | 54 | (- (void) startObservingPerson: (id) person is 55 | (person addObserver:self 56 | forKeyPath:"personName" 57 | options:NSKeyValueObservingOptionOld 58 | context:nil) 59 | (person addObserver:self 60 | forKeyPath:"expectedRaise" 61 | options:NSKeyValueObservingOptionOld 62 | context:nil)) 63 | 64 | (- (void) stopObservingPerson: (id) person is 65 | (person removeObserver:self forKeyPath:"personName") 66 | (person removeObserver:self forKeyPath:"expectedRaise")) 67 | 68 | (- (void) insertObject: (id) p inEmployeesAtIndex: (int) r is 69 | ;; Register the undo 70 | (set undo (self undoManager)) 71 | ((undo prepareWithInvocationTarget:self) 72 | removeObjectFromEmployeesAtIndex:r) 73 | (unless (undo isUndoing) 74 | (undo setActionName:"Insert Person")) 75 | ;; Add the person to the array 76 | (self startObservingPerson:p) 77 | (@employees insertObject:p atIndex:r)) 78 | 79 | (- (void) removeObjectFromEmployeesAtIndex: (int) r is 80 | (set p (@employees r)) 81 | (set undo (self undoManager)) 82 | ((undo prepareWithInvocationTarget:self) 83 | insertObject:p inEmployeesAtIndex:r) 84 | (unless (undo isUndoing) 85 | (undo setActionName:"Delete Person")) 86 | (self stopObservingPerson:p) 87 | (@employees removeObjectAtIndex:r)) 88 | 89 | (- (void) setEmployees: (id) arr is 90 | (@employees each:(do (p) (self stopObservingPerson:p))) 91 | (set @employees arr) 92 | (@employees each:(do (p) (self startObservingPerson:p)))) 93 | 94 | (- (void) changeKeyPath: (id) keyPath ofObject: (id) obj toValue:(id) newValue is 95 | (obj setValue:newValue forKeyPath:keyPath)) 96 | 97 | (- (void) observeValueForKeyPath: (id) keyPath ofObject: (id) obj 98 | change: (id) change context: (id) context is 99 | (set undo (self undoManager)) 100 | (set oldValue (change objectForKey:NSKeyValueChangeOldKey)) 101 | (if (eq oldValue (NSNull null)) 102 | (set oldValue nil)) 103 | (NSLog "oldValue = #{oldValue}") 104 | ((undo prepareWithInvocationTarget:self) 105 | changeKeyPath:keyPath ofObject:obj toValue:oldValue) 106 | (undo setActionName:"Edit")) 107 | 108 | (- (id) windowNibName is "MyDocument") 109 | 110 | (- (void) windowControllerDidLoadNib: (id) aController is 111 | (super windowControllerDidLoadNib:aController) 112 | ;; Add any code here that needs to be executed once the windowController has loaded the document's window. 113 | )) 114 | 115 | (set SHOW_CONSOLE_AT_STARTUP nil) 116 | 117 | ;; @class ApplicationDelegate 118 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 119 | (class ApplicationDelegate is NSObject 120 | 121 | ;; This method is called after Cocoa has finished its basic application setup. 122 | ;; It instantiates application-specific components. 123 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 124 | (- (void) applicationDidFinishLaunching:(id) sender is 125 | (set $console ((NuConsoleWindowController alloc) init)) 126 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 127 | 128 | ;; install the delegate and keep a reference to it since the application won't retain it. 129 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 130 | 131 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 132 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 133 | 134 | ;; run the main Cocoa event loop 135 | (NSApplicationMain 0 nil) 136 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_A/CarLot_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'CarLot' target in the 'CarLot' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #import 9 | #endif 10 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_A/English.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_A/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/11_CoreData/CarLot_A/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /11_CoreData/CarLot_A/English.lproj/MainMenu.nib/classes.nib: -------------------------------------------------------------------------------- 1 | { 2 | IBClasses = ( 3 | { 4 | CLASS = FirstResponder; 5 | LANGUAGE = ObjC; 6 | SUPERCLASS = NSObject; 7 | } 8 | ); 9 | IBVersion = 1; 10 | } -------------------------------------------------------------------------------- /11_CoreData/CarLot_A/English.lproj/MainMenu.nib/info.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBDocumentLocation 6 | 474 126 356 240 0 0 1680 1028 7 | IBEditorPositions 8 | 9 | 29 10 | 338 633 459 44 0 0 1680 1028 11 | 12 | IBFramework Version 13 | 461.0 14 | IBOldestOS 15 | 4 16 | IBOpenObjects 17 | 18 | 29 19 | 20 | IBSystem Version 21 | 9A440 22 | IBUsesTextArchiving 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_A/English.lproj/MyDocument.nib/classes.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBClasses 6 | 7 | 8 | CLASS 9 | FirstResponder 10 | LANGUAGE 11 | ObjC 12 | SUPERCLASS 13 | NSObject 14 | 15 | 16 | CLASS 17 | MyDocument 18 | LANGUAGE 19 | ObjC 20 | SUPERCLASS 21 | NSPersistentDocument 22 | 23 | 24 | CLASS 25 | NSPersistentDocument 26 | LANGUAGE 27 | ObjC 28 | SUPERCLASS 29 | NSDocument 30 | 31 | 32 | IBVersion 33 | 1 34 | 35 | 36 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_A/English.lproj/MyDocument.nib/info.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBFramework Version 6 | 629 7 | IBOldestOS 8 | 5 9 | IBOpenObjects 10 | 11 | 5 12 | 13 | IBSystem Version 14 | 9B18 15 | targetFramework 16 | IBCocoaFramework 17 | 18 | 19 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_A/English.lproj/MyDocument.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/11_CoreData/CarLot_A/English.lproj/MyDocument.nib/keyedobjects.nib -------------------------------------------------------------------------------- /11_CoreData/CarLot_A/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeExtensions 11 | 12 | binary 13 | 14 | CFBundleTypeMIMETypes 15 | 16 | application/octet-stream 17 | 18 | CFBundleTypeName 19 | Binary 20 | CFBundleTypeRole 21 | Editor 22 | LSTypeIsPackage 23 | 24 | NSDocumentClass 25 | MyDocument 26 | NSPersistentStoreTypeKey 27 | Binary 28 | 29 | 30 | CFBundleTypeExtensions 31 | 32 | sqlite 33 | 34 | CFBundleTypeMIMETypes 35 | 36 | application/octet-stream 37 | 38 | CFBundleTypeName 39 | SQLite 40 | CFBundleTypeRole 41 | Editor 42 | LSTypeIsPackage 43 | 44 | NSDocumentClass 45 | MyDocument 46 | NSPersistentStoreTypeKey 47 | SQLite 48 | 49 | 50 | CFBundleTypeExtensions 51 | 52 | xml 53 | 54 | CFBundleTypeIconFile 55 | 56 | CFBundleTypeMIMETypes 57 | 58 | text/xml 59 | 60 | CFBundleTypeName 61 | XML 62 | CFBundleTypeOSTypes 63 | 64 | ???? 65 | 66 | CFBundleTypeRole 67 | Editor 68 | LSTypeIsPackage 69 | 70 | NSDocumentClass 71 | MyDocument 72 | NSPersistentStoreTypeKey 73 | XML 74 | 75 | 76 | CFBundleName 77 | ${PRODUCT_NAME} 78 | CFBundleExecutable 79 | ${EXECUTABLE_NAME} 80 | CFBundleIconFile 81 | 82 | CFBundleIdentifier 83 | com.yourcompany.CarLotApp 84 | CFBundleInfoDictionaryVersion 85 | 6.0 86 | CFBundlePackageType 87 | APPL 88 | CFBundleShortVersionString 89 | 1.2 90 | CFBundleSignature 91 | ???? 92 | CFBundleVersion 93 | 22 94 | NSMainNibFile 95 | MainMenu 96 | NSPrincipalClass 97 | NSApplication 98 | 99 | 100 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_A/MyDocument.xcdatamodel/elements: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/11_CoreData/CarLot_A/MyDocument.xcdatamodel/elements -------------------------------------------------------------------------------- /11_CoreData/CarLot_A/MyDocument.xcdatamodel/layout: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/11_CoreData/CarLot_A/MyDocument.xcdatamodel/layout -------------------------------------------------------------------------------- /11_CoreData/CarLot_A/main.m: -------------------------------------------------------------------------------- 1 | int NuMain(int argc, const char *argv[]); 2 | 3 | int main(int argc, const char *argv[]) 4 | { 5 | return NuMain(argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_A/nu/main.nu: -------------------------------------------------------------------------------- 1 | ;; file main.nu 2 | ;; discussion Entry point for a Nu program. 3 | ; 4 | ;; copyright Copyright (c) 2008 Tim Burks, Neon Design Technology, Inc. 5 | 6 | (import Cocoa) ;; bridgesupport 7 | (load "console") ;; interactive console 8 | 9 | (class MyDocument is NSPersistentDocument 10 | 11 | (- (id)init is 12 | (set self (super init)) 13 | (if self 14 | ;; initialization code 15 | ) 16 | self) 17 | 18 | (- (id)windowNibName is "MyDocument") 19 | 20 | (- (void)windowControllerDidLoadNib:(id)windowController is 21 | (super windowControllerDidLoadNib:windowController) 22 | ;; user interface preparation code 23 | )) 24 | 25 | (set SHOW_CONSOLE_AT_STARTUP nil) 26 | 27 | ;; @class ApplicationDelegate 28 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 29 | (class ApplicationDelegate is NSObject 30 | 31 | ;; This method is called after Cocoa has finished its basic application setup. 32 | ;; It instantiates application-specific components. 33 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 34 | (- (void) applicationDidFinishLaunching:(id) sender is 35 | (set $console ((NuConsoleWindowController alloc) init)) 36 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 37 | 38 | ;; install the delegate and keep a reference to it since the application won't retain it. 39 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 40 | 41 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 42 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 43 | 44 | ;; run the main Cocoa event loop 45 | (NSApplicationMain 0 nil) 46 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_A/version.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildVersion 6 | 9 7 | CFBundleVersion 8 | 1.0 9 | ProjectName 10 | NibPBTemplates 11 | SourceVersion 12 | 1200000 13 | 14 | 15 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_FINAL/CarLot_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'CarLot' target in the 'CarLot' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #import 9 | #endif 10 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_FINAL/English.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_FINAL/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/11_CoreData/CarLot_FINAL/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /11_CoreData/CarLot_FINAL/English.lproj/MainMenu.nib/classes.nib: -------------------------------------------------------------------------------- 1 | { 2 | IBClasses = ( 3 | { 4 | CLASS = FirstResponder; 5 | LANGUAGE = ObjC; 6 | SUPERCLASS = NSObject; 7 | } 8 | ); 9 | IBVersion = 1; 10 | } -------------------------------------------------------------------------------- /11_CoreData/CarLot_FINAL/English.lproj/MainMenu.nib/info.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBDocumentLocation 6 | 474 126 356 240 0 0 1680 1028 7 | IBEditorPositions 8 | 9 | 29 10 | 338 633 459 44 0 0 1680 1028 11 | 12 | IBFramework Version 13 | 461.0 14 | IBOldestOS 15 | 4 16 | IBOpenObjects 17 | 18 | 29 19 | 20 | IBSystem Version 21 | 9A440 22 | IBUsesTextArchiving 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_FINAL/English.lproj/MyDocument.nib/classes.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBClasses 6 | 7 | 8 | CLASS 9 | FirstResponder 10 | LANGUAGE 11 | ObjC 12 | SUPERCLASS 13 | NSObject 14 | 15 | 16 | CLASS 17 | MyDocument 18 | LANGUAGE 19 | ObjC 20 | SUPERCLASS 21 | NSPersistentDocument 22 | 23 | 24 | CLASS 25 | NSPersistentDocument 26 | LANGUAGE 27 | ObjC 28 | SUPERCLASS 29 | NSDocument 30 | 31 | 32 | CLASS 33 | CarArrayController 34 | LANGUAGE 35 | ObjC 36 | SUPERCLASS 37 | NSArrayController 38 | 39 | 40 | IBVersion 41 | 1 42 | 43 | 44 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_FINAL/English.lproj/MyDocument.nib/info.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBFramework Version 6 | 629 7 | IBOldestOS 8 | 5 9 | IBOpenObjects 10 | 11 | 31 12 | 13 | IBSystem Version 14 | 9B18 15 | targetFramework 16 | IBCocoaFramework 17 | 18 | 19 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_FINAL/English.lproj/MyDocument.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/11_CoreData/CarLot_FINAL/English.lproj/MyDocument.nib/keyedobjects.nib -------------------------------------------------------------------------------- /11_CoreData/CarLot_FINAL/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeExtensions 11 | 12 | binary 13 | 14 | CFBundleTypeMIMETypes 15 | 16 | application/octet-stream 17 | 18 | CFBundleTypeName 19 | Binary 20 | CFBundleTypeRole 21 | Editor 22 | LSTypeIsPackage 23 | 24 | NSDocumentClass 25 | MyDocument 26 | NSPersistentStoreTypeKey 27 | Binary 28 | 29 | 30 | CFBundleTypeExtensions 31 | 32 | sqlite 33 | 34 | CFBundleTypeMIMETypes 35 | 36 | application/octet-stream 37 | 38 | CFBundleTypeName 39 | SQLite 40 | CFBundleTypeRole 41 | Editor 42 | LSTypeIsPackage 43 | 44 | NSDocumentClass 45 | MyDocument 46 | NSPersistentStoreTypeKey 47 | SQLite 48 | 49 | 50 | CFBundleTypeExtensions 51 | 52 | xml 53 | 54 | CFBundleTypeIconFile 55 | 56 | CFBundleTypeMIMETypes 57 | 58 | text/xml 59 | 60 | CFBundleTypeName 61 | XML 62 | CFBundleTypeOSTypes 63 | 64 | ???? 65 | 66 | CFBundleTypeRole 67 | Editor 68 | LSTypeIsPackage 69 | 70 | NSDocumentClass 71 | MyDocument 72 | NSPersistentStoreTypeKey 73 | XML 74 | 75 | 76 | CFBundleName 77 | ${PRODUCT_NAME} 78 | CFBundleExecutable 79 | ${EXECUTABLE_NAME} 80 | CFBundleIconFile 81 | 82 | CFBundleIdentifier 83 | com.yourcompany.CarLotApp 84 | CFBundleInfoDictionaryVersion 85 | 6.0 86 | CFBundlePackageType 87 | APPL 88 | CFBundleShortVersionString 89 | 1.2 90 | CFBundleSignature 91 | ???? 92 | CFBundleVersion 93 | 22 94 | NSMainNibFile 95 | MainMenu 96 | NSPrincipalClass 97 | NSApplication 98 | 99 | 100 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_FINAL/MyDocument.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/11_CoreData/CarLot_FINAL/MyDocument.h -------------------------------------------------------------------------------- /11_CoreData/CarLot_FINAL/MyDocument.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/11_CoreData/CarLot_FINAL/MyDocument.m -------------------------------------------------------------------------------- /11_CoreData/CarLot_FINAL/MyDocument.xcdatamodel/elements: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/11_CoreData/CarLot_FINAL/MyDocument.xcdatamodel/elements -------------------------------------------------------------------------------- /11_CoreData/CarLot_FINAL/MyDocument.xcdatamodel/layout: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/11_CoreData/CarLot_FINAL/MyDocument.xcdatamodel/layout -------------------------------------------------------------------------------- /11_CoreData/CarLot_FINAL/main.m: -------------------------------------------------------------------------------- 1 | int NuMain(int argc, const char *argv[]); 2 | 3 | int main(int argc, const char *argv[]) 4 | { 5 | return NuMain(argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_FINAL/nu/main.nu: -------------------------------------------------------------------------------- 1 | ;; file main.nu 2 | ;; discussion Entry point for a Nu program. 3 | ; 4 | ;; copyright Copyright (c) 2008 Tim Burks, Neon Design Technology, Inc. 5 | 6 | (import Cocoa) ;; bridgesupport 7 | (load "console") ;; interactive console 8 | 9 | (class MyDocument is NSPersistentDocument 10 | 11 | (- (id)init is 12 | (set self (super init)) 13 | (if self 14 | ;; initialization code 15 | ) 16 | self) 17 | 18 | (- (id)windowNibName is "MyDocument") 19 | 20 | (- (void)windowControllerDidLoadNib:(id)windowController is 21 | (super windowControllerDidLoadNib:windowController) 22 | ;; user interface preparation code 23 | )) 24 | 25 | (class CarArrayController is NSArrayController 26 | (- (id)newObject is 27 | (set newCar (super newObject)) 28 | (newCar setValue:(NSDate date) forKey:"datePurchased") 29 | newCar)) 30 | 31 | (set SHOW_CONSOLE_AT_STARTUP nil) 32 | 33 | ;; @class ApplicationDelegate 34 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 35 | (class ApplicationDelegate is NSObject 36 | 37 | ;; This method is called after Cocoa has finished its basic application setup. 38 | ;; It instantiates application-specific components. 39 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 40 | (- (void) applicationDidFinishLaunching:(id) sender is 41 | (set $console ((NuConsoleWindowController alloc) init)) 42 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 43 | 44 | ;; install the delegate and keep a reference to it since the application won't retain it. 45 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 46 | 47 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 48 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 49 | 50 | ;; run the main Cocoa event loop 51 | (NSApplicationMain 0 nil) 52 | -------------------------------------------------------------------------------- /11_CoreData/CarLot_FINAL/version.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildVersion 6 | 9 7 | CFBundleVersion 8 | 1.0 9 | ProjectName 10 | NibPBTemplates 11 | SourceVersion 12 | 1200000 13 | 14 | 15 | -------------------------------------------------------------------------------- /12_MultiNib/RaiseMan/BBall.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/12_MultiNib/RaiseMan/BBall.icns -------------------------------------------------------------------------------- /12_MultiNib/RaiseMan/English.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /12_MultiNib/RaiseMan/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/12_MultiNib/RaiseMan/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /12_MultiNib/RaiseMan/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/12_MultiNib/RaiseMan/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /12_MultiNib/RaiseMan/English.lproj/MyDocument.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/12_MultiNib/RaiseMan/English.lproj/MyDocument.nib/keyedobjects.nib -------------------------------------------------------------------------------- /12_MultiNib/RaiseMan/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeExtensions 11 | 12 | rsmn 13 | 14 | CFBundleTypeIconFile 15 | BBall 16 | CFBundleTypeName 17 | RaiseMan Doc 18 | CFBundleTypeOSTypes 19 | 20 | ???? 21 | 22 | CFBundleTypeRole 23 | Editor 24 | NSDocumentClass 25 | MyDocument 26 | 27 | 28 | CFBundleExecutable 29 | ${EXECUTABLE_NAME} 30 | CFBundleIconFile 31 | BBall 32 | CFBundleIdentifier 33 | com.bignerdranch.RaiseMan 34 | CFBundleInfoDictionaryVersion 35 | 6.0 36 | CFBundleName 37 | ${PRODUCT_NAME} 38 | CFBundlePackageType 39 | APPL 40 | CFBundleSignature 41 | ???? 42 | CFBundleVersion 43 | 1.0 44 | NSMainNibFile 45 | MainMenu 46 | NSPrincipalClass 47 | NSApplication 48 | 49 | 50 | -------------------------------------------------------------------------------- /12_MultiNib/RaiseMan/Preferences.nib/classes.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBClasses 6 | 7 | 8 | ACTIONS 9 | 10 | changeBackgroundColor 11 | id 12 | changeNewEmptyDoc 13 | id 14 | 15 | CLASS 16 | PreferenceController 17 | LANGUAGE 18 | ObjC 19 | OUTLETS 20 | 21 | checkbox 22 | NSButton 23 | colorWell 24 | NSColorWell 25 | 26 | SUPERCLASS 27 | NSWindowController 28 | 29 | 30 | CLASS 31 | FirstResponder 32 | LANGUAGE 33 | ObjC 34 | SUPERCLASS 35 | NSObject 36 | 37 | 38 | IBVersion 39 | 1 40 | 41 | 42 | -------------------------------------------------------------------------------- /12_MultiNib/RaiseMan/Preferences.nib/info.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBFramework Version 6 | 623 7 | IBLastKnownRelativeProjectPath 8 | ../RaiseMan.xcodeproj 9 | IBOldestOS 10 | 5 11 | IBOpenObjects 12 | 13 | 9 14 | 15 | IBSystem Version 16 | 9A528d 17 | targetFramework 18 | IBCocoaFramework 19 | 20 | 21 | -------------------------------------------------------------------------------- /12_MultiNib/RaiseMan/Preferences.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/12_MultiNib/RaiseMan/Preferences.nib/keyedobjects.nib -------------------------------------------------------------------------------- /12_MultiNib/RaiseMan/RaiseMan_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'RaiseMan' target in the 'RaiseMan' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /12_MultiNib/RaiseMan/main.m: -------------------------------------------------------------------------------- 1 | int NuMain(int argc, const char *argv[]); 2 | 3 | int main(int argc, const char *argv[]) 4 | { 5 | return NuMain(argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /12_MultiNib/RaiseMan/nu/main.nu: -------------------------------------------------------------------------------- 1 | ;; file main.nu 2 | ;; discussion Entry point for a Nu program. 3 | ; 4 | ;; copyright Copyright (c) 2008 Tim Burks, Neon Design Technology, Inc. 5 | 6 | (import Cocoa) ;; bridgesupport 7 | (load "console") ;; interactive console 8 | 9 | (class AppController is NSObject 10 | (ivar (id) preferenceController) 11 | 12 | (- (void)showPreferencePanel:(id)sender is 13 | (unless @preferenceController 14 | (set @preferenceController ((PreferenceController alloc) init))) 15 | (NSLog "Showing #{@preferenceController)") 16 | (@preferenceController showWindow:self))) 17 | 18 | (class PreferenceController is NSWindowController 19 | (ivar (id) colorWell (id) checkbox) 20 | 21 | (- (id)init is 22 | (unless (super initWithWindowNibName:"Preferences") 23 | (return nil)) 24 | (set $p self) 25 | self) 26 | 27 | (- (void)windowDidLoad is 28 | (NSLog "nib file loaded")) 29 | 30 | (- (void)changeBackgroundColor:(id)sender is 31 | (NSLog "Color changed: #{(@colorWell color))")) 32 | 33 | (- (void)changeNewEmptyDoc:(id)sender is 34 | (NSLog "Checkbox changed: #{(@checkbox state))"))) 35 | 36 | (class Person is NSObject 37 | (ivar (id) personName (float) expectedRaise) 38 | 39 | (- (id)init is 40 | (super init) 41 | (set @expectedRaise 5.0) 42 | (set @personName "New Person") 43 | self) 44 | 45 | (- (id)initWithCoder:(id)c is 46 | (super init) 47 | (set @personName (c decodeObjectForKey:"personName")) 48 | (set @expectedRaise (c decodeFloatForKey:"expectedRaise")) 49 | self) 50 | 51 | (- (void)encodeWithCoder:(id)c is 52 | (c encodeObject:@personName forKey:"personName") 53 | (c encodeFloat:@expectedRaise forKey:"expectedRaise"))) 54 | 55 | 56 | (class MyDocument is NSDocument 57 | (ivar (id) tableView (id) employeeController (id) employees) 58 | 59 | (- (id)init is 60 | (unless (super init) (return nil)) 61 | (self setEmployees:(NSMutableArray array)) 62 | self) 63 | 64 | (- (void)createEmployee:(id)sender is 65 | (set w (@tableView window)) 66 | (set editingEnded (w makeFirstResponder:w)) 67 | (unless editingEnded (return)) 68 | (set undo (self undoManager)) 69 | (if (undo groupingLevel) 70 | (undo endUndoGrouping) 71 | (undo beginUndoGrouping)) 72 | 73 | (set p (@employeeController newObject)) 74 | (@employeeController addObject:p) 75 | 76 | ;; In case the user has sorted the content array 77 | (@employeeController rearrangeObjects) 78 | 79 | ;; Find the row of the new object 80 | (set a (@employeeController arrangedObjects)) 81 | (set row (a indexOfObjectIdenticalTo:p)) 82 | 83 | ;; Start editing in the first column 84 | (@tableView editColumn:0 row:row withEvent:nil select:YES)) 85 | 86 | (- (void)startObservingPerson:(id)person is 87 | (person addObserver:self forKeyPath:"personName" options:NSKeyValueObservingOptionOld context:nil) 88 | (person addObserver:self forKeyPath:"expectedRaise" options:NSKeyValueObservingOptionOld context:nil)) 89 | 90 | (- (void)stopObservingPerson:(id)person is 91 | (person removeObserver:self forKeyPath:"personName") 92 | (person removeObserver:self forKeyPath:"expectedRaise")) 93 | 94 | (- (void)insertObject:(id)p inEmployeesAtIndex:(int)r is 95 | ;; Register the undo 96 | (set undo (self undoManager)) 97 | ((undo prepareWithInvocationTarget:self) 98 | removeObjectFromEmployeesAtIndex:r) 99 | (unless (undo isUndoing) (undo setActionName:"Insert Person")) 100 | ;; Add the person to the array 101 | (self startObservingPerson:p) 102 | (@employees insertObject:p atIndex:r)) 103 | 104 | (- (void)removeObjectFromEmployeesAtIndex:(int)r is 105 | (set p (@employees objectAtIndex:r)) 106 | (set undo (self undoManager)) 107 | ((undo prepareWithInvocationTarget:self) insertObject:p inEmployeesAtIndex:r) 108 | (unless (undo isUndoing) (undo setActionName:"Delete Person")) 109 | (self stopObservingPerson:p) 110 | (@employees removeObjectAtIndex:r)) 111 | 112 | (- (void)setEmployees:(id)a is 113 | (if (eq a @employees) (return)) 114 | (@employees each:(do (p) (self stopObservingPerson:p))) 115 | (set @employees a) 116 | (@employees each:(do (p) (self startObservingPerson:p)))) 117 | 118 | (- (void)changeKeyPath:(id)keyPath ofObject:(id)obj toValue:(id)newValue is 119 | (obj setValue:newValue forKeyPath:keyPath)) 120 | 121 | (- (void)observeValueForKeyPath:(id)keyPath ofObject:(id)obj change:(id)change context:(void *)context is 122 | (set undo (self undoManager)) 123 | (set oldValue (change objectForKey:NSKeyValueChangeOldKey)) 124 | (NSLog "oldValue = #{oldValue}") 125 | ((undo prepareWithInvocationTarget:self) 126 | changeKeyPath:keyPath 127 | ofObject:obj 128 | toValue:oldValue) 129 | (undo setActionName:"Edit")) 130 | 131 | (- (id)windowNibName is "MyDocument") 132 | 133 | (- (void)windowControllerDidLoadNib:(id) aController is 134 | (super windowControllerDidLoadNib:aController) 135 | ;; Add any code here that needs to be executed once the windowController has loaded the document's window. 136 | ) 137 | 138 | (- (void)presentError:(id)error modalForWindow:(id)window delegate:(id)delegate didPresentSelector:(SEL)didPresentSelector contextInfo:(void *)contextInfo is 139 | (set ui (error userInfo)) 140 | (set underlying (ui objectForKey:NSUnderlyingErrorKey)) 141 | (NSLog "error = #{error}, userInfo = #{ui}, underlying info = #{(underlying userInfo)}") 142 | (super presentError:error 143 | modalForWindow:window 144 | delegate:delegate 145 | didPresentSelector:didPresentSelector 146 | contextInfo:contextInfo)) 147 | 148 | (- (id)dataOfType:(id)typeName error:(id *)outError is 149 | ((@tableView window) endEditingFor:nil) 150 | (NSKeyedArchiver archivedDataWithRootObject:@employees)) 151 | 152 | (- (BOOL)readFromData:(id)data ofType:(id)typeName error:(id *)outError is 153 | (set a nil) 154 | (try (set a (NSKeyedUnarchiver unarchiveObjectWithData:data)) 155 | (catch (obj) 156 | (if outError 157 | (set d (dict NSLocalizedFailureReasonErrorKey "This file is corrupted like Noriega.")) 158 | (outError setValue:(NSError errorWithDomain:NSOSStatusErrorDomain 159 | code:unimpErr 160 | userInfo:d))) 161 | (return NO))) 162 | (self setEmployees:a) 163 | YES)) 164 | 165 | (set SHOW_CONSOLE_AT_STARTUP nil) 166 | 167 | ;; @class ApplicationDelegate 168 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 169 | (class ApplicationDelegate is NSObject 170 | 171 | ;; This method is called after Cocoa has finished its basic application setup. 172 | ;; It instantiates application-specific components. 173 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 174 | (- (void) applicationDidFinishLaunching:(id) sender is 175 | (set $console ((NuConsoleWindowController alloc) init)) 176 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 177 | 178 | ;; install the delegate and keep a reference to it since the application won't retain it. 179 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 180 | 181 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 182 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 183 | 184 | ;; run the main Cocoa event loop 185 | (NSApplicationMain 0 nil) 186 | -------------------------------------------------------------------------------- /14_Notifications/RaiseMan/BBall.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/14_Notifications/RaiseMan/BBall.icns -------------------------------------------------------------------------------- /14_Notifications/RaiseMan/English.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /14_Notifications/RaiseMan/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/14_Notifications/RaiseMan/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /14_Notifications/RaiseMan/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/14_Notifications/RaiseMan/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /14_Notifications/RaiseMan/English.lproj/MyDocument.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/14_Notifications/RaiseMan/English.lproj/MyDocument.nib/keyedobjects.nib -------------------------------------------------------------------------------- /14_Notifications/RaiseMan/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeExtensions 11 | 12 | rsmn 13 | 14 | CFBundleTypeIconFile 15 | BBall 16 | CFBundleTypeName 17 | RaiseMan Doc 18 | CFBundleTypeOSTypes 19 | 20 | ???? 21 | 22 | CFBundleTypeRole 23 | Editor 24 | NSDocumentClass 25 | MyDocument 26 | 27 | 28 | CFBundleExecutable 29 | ${EXECUTABLE_NAME} 30 | CFBundleIconFile 31 | BBall 32 | CFBundleIdentifier 33 | com.bignerdranch.RaiseMan 34 | CFBundleInfoDictionaryVersion 35 | 6.0 36 | CFBundleName 37 | ${PRODUCT_NAME} 38 | CFBundlePackageType 39 | APPL 40 | CFBundleSignature 41 | ???? 42 | CFBundleVersion 43 | 1.0 44 | NSMainNibFile 45 | MainMenu 46 | NSPrincipalClass 47 | NSApplication 48 | 49 | 50 | -------------------------------------------------------------------------------- /14_Notifications/RaiseMan/Preferences.nib/classes.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBClasses 6 | 7 | 8 | ACTIONS 9 | 10 | changeBackgroundColor 11 | id 12 | changeNewEmptyDoc 13 | id 14 | 15 | CLASS 16 | PreferenceController 17 | LANGUAGE 18 | ObjC 19 | OUTLETS 20 | 21 | checkbox 22 | NSButton 23 | colorWell 24 | NSColorWell 25 | 26 | SUPERCLASS 27 | NSWindowController 28 | 29 | 30 | CLASS 31 | FirstResponder 32 | LANGUAGE 33 | ObjC 34 | SUPERCLASS 35 | NSObject 36 | 37 | 38 | IBVersion 39 | 1 40 | 41 | 42 | -------------------------------------------------------------------------------- /14_Notifications/RaiseMan/Preferences.nib/info.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBFramework Version 6 | 623 7 | IBLastKnownRelativeProjectPath 8 | ../RaiseMan.xcodeproj 9 | IBOldestOS 10 | 5 11 | IBOpenObjects 12 | 13 | 9 14 | 15 | IBSystem Version 16 | 9A528d 17 | targetFramework 18 | IBCocoaFramework 19 | 20 | 21 | -------------------------------------------------------------------------------- /14_Notifications/RaiseMan/Preferences.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/14_Notifications/RaiseMan/Preferences.nib/keyedobjects.nib -------------------------------------------------------------------------------- /14_Notifications/RaiseMan/RaiseMan_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'RaiseMan' target in the 'RaiseMan' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /14_Notifications/RaiseMan/main.m: -------------------------------------------------------------------------------- 1 | int NuMain(int argc, const char *argv[]); 2 | 3 | int main(int argc, const char *argv[]) 4 | { 5 | return NuMain(argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /14_Notifications/RaiseMan/nu/main.nu: -------------------------------------------------------------------------------- 1 | ;; file main.nu 2 | ;; discussion Entry point for a Nu program. 3 | 4 | (import Cocoa) ;; bridgesupport 5 | (load "console") ;; interactive console 6 | 7 | (set BNRTableBgColorKey "TableBackgroundColor") 8 | (set BNREmptyDocKey "EmptyDocumentFlag") 9 | (set BNRColorChangedNotification "BNRColorChanged") 10 | 11 | (class AppController is NSObject 12 | (ivar (id) preferenceController) 13 | 14 | (+ (void) initialize is 15 | (set defaultValues (NSMutableDictionary dictionary)) 16 | (set colorAsData (NSKeyedArchiver archivedDataWithRootObject:(NSColor yellowColor))) 17 | (defaultValues setObject: colorAsData forKey: BNRTableBgColorKey) 18 | (defaultValues setObject: (NSNumber numberWithBool:YES) forKey:BNREmptyDocKey) 19 | ((NSUserDefaults standardUserDefaults) registerDefaults:defaultValues) 20 | (NSLog "registered: #{defaultValues}")) 21 | 22 | (- (void)showPreferencePanel:(id)sender is 23 | (unless @preferenceController 24 | (set @preferenceController ((PreferenceController alloc) init))) 25 | (NSLog "Showing #{@preferenceController}") 26 | (@preferenceController showWindow:self)) 27 | 28 | (- (BOOL) applicationShouldOpenUntitledFile:(id)sender is 29 | (NSLog "applicationShouldOpenUntitledFile") 30 | ((NSUserDefaults standardUserDefaults) boolForKey:BNREmptyDocKey))) 31 | 32 | (class PreferenceController is NSWindowController 33 | (ivar (id) colorWell (id) checkbox) 34 | 35 | (- (id)init is 36 | (unless (super initWithWindowNibName:"Preferences") 37 | (return nil)) 38 | (set $p self) 39 | self) 40 | 41 | (- (id)tableBgColor is 42 | (set defaults (NSUserDefaults standardUserDefaults)) 43 | (set colorAsData (defaults objectForKey:BNRTableBgColorKey)) 44 | (NSKeyedUnarchiver unarchiveObjectWithData:colorAsData)) 45 | 46 | (- (BOOL)emptyDoc is 47 | (set defaults (NSUserDefaults standardUserDefaults)) 48 | (defaults boolForKey:BNREmptyDocKey)) 49 | 50 | (- (void)windowDidLoad is 51 | (@colorWell setColor:(self tableBgColor)) 52 | (@checkbox setState:(self emptyDoc))) 53 | 54 | (- (void)changeBackgroundColor:(id)sender is 55 | (set color (@colorWell color)) 56 | (set colorAsData (NSKeyedArchiver archivedDataWithRootObject:color)) 57 | (set defaults (NSUserDefaults standardUserDefaults)) 58 | (defaults setObject:colorAsData forKey:BNRTableBgColorKey) 59 | 60 | (NSLog "sending color changed notification") 61 | (set nc (NSNotificationCenter defaultCenter)) 62 | (set d (NSDictionary dictionaryWithObject:color forKey:"color")) 63 | 64 | (nc postNotificationName:BNRColorChangedNotification object:self userInfo:d)) 65 | 66 | (- (void)changeNewEmptyDoc:(id)sender is 67 | (set defaults (NSUserDefaults standardUserDefaults)) 68 | (defaults setBool:(checkbox state) forKey:BNREmptyDocKey))) 69 | 70 | (class Person is NSObject 71 | ; @property (readwrite, copy) NSString *personName; 72 | ; @property (readwrite) float expectedRaise; 73 | (ivar (id) personName (float) expectedRaise) 74 | (ivar-accessors) 75 | 76 | (- (id)init is 77 | (super init) 78 | (set @expectedRaise 5.0) 79 | (set @personName "New Person") 80 | self) 81 | 82 | (- (id)initWithCoder:(id)c is 83 | (super init) 84 | (set @personName (c decodeObjectForKey:"personName")) 85 | (set @expectedRaise (c decodeFloatForKey:"expectedRaise")) 86 | self) 87 | 88 | (- (void)encodeWithCoder:(id)c is 89 | (c encodeObject:@personName forKey:"personName") 90 | (c encodeFloat:@expectedRaise forKey:"expectedRaise"))) 91 | 92 | (class MyDocument is NSDocument 93 | (ivar (id) tableView (id) employeeController (id) employees) 94 | 95 | (- (id)init is 96 | (unless (super init) (return nil)) 97 | (self setEmployees:(NSMutableArray array)) 98 | 99 | (set nc (NSNotificationCenter defaultCenter)) 100 | (nc addObserver:self 101 | selector:"handleColorChange:" 102 | name:BNRColorChangedNotification 103 | object:nil) 104 | (NSLog "registered for notification") 105 | self) 106 | 107 | (- (void)createEmployee:(id)sender is 108 | (set w (@tableView window)) 109 | (set editingEnded (w makeFirstResponder:w)) 110 | (unless editingEnded (return)) 111 | (set undo (self undoManager)) 112 | (if (undo groupingLevel) 113 | (undo endUndoGrouping) 114 | (undo beginUndoGrouping)) 115 | 116 | (set p (@employeeController newObject)) 117 | (@employeeController addObject:p) 118 | 119 | ;; In case the user has sorted the content array 120 | (@employeeController rearrangeObjects) 121 | 122 | ;; Find the row of the new object 123 | (set a (@employeeController arrangedObjects)) 124 | (set row (a indexOfObjectIdenticalTo:p)) 125 | 126 | ;; Start editing in the first column 127 | (@tableView editColumn:0 row:row withEvent:nil select:YES)) 128 | 129 | (- (void)startObservingPerson:(id)person is 130 | (person addObserver:self forKeyPath:"personName" options:NSKeyValueObservingOptionOld context:nil) 131 | (person addObserver:self forKeyPath:"expectedRaise" options:NSKeyValueObservingOptionOld context:nil)) 132 | 133 | (- (void)stopObservingPerson:(id)person is 134 | (person removeObserver:self forKeyPath:"personName") 135 | (person removeObserver:self forKeyPath:"expectedRaise")) 136 | 137 | (- (void)insertObject:(id)p inEmployeesAtIndex:(int)r is 138 | ;; Register the undo 139 | (set undo (self undoManager)) 140 | ((undo prepareWithInvocationTarget:self) 141 | removeObjectFromEmployeesAtIndex:r) 142 | (unless (undo isUndoing) (undo setActionName:"Insert Person")) 143 | ;; Add the person to the array 144 | (self startObservingPerson:p) 145 | (@employees insertObject:p atIndex:r)) 146 | 147 | (- (void)removeObjectFromEmployeesAtIndex:(int)r is 148 | (set p (@employees objectAtIndex:r)) 149 | (set undo (self undoManager)) 150 | ((undo prepareWithInvocationTarget:self) insertObject:p inEmployeesAtIndex:r) 151 | (unless (undo isUndoing) (undo setActionName:"Delete Person")) 152 | (self stopObservingPerson:p) 153 | (@employees removeObjectAtIndex:r)) 154 | 155 | (- (void)setEmployees:(id)a is 156 | (if (eq a @employees) (return)) 157 | (@employees each:(do (p) (self stopObservingPerson:p))) 158 | (set @employees a) 159 | (@employees each:(do (p) (self startObservingPerson:p)))) 160 | 161 | (- (void)changeKeyPath:(id)keyPath ofObject:(id)obj toValue:(id)newValue is 162 | (obj setValue:newValue forKeyPath:keyPath)) 163 | 164 | (- (void)observeValueForKeyPath:(id)keyPath ofObject:(id)obj change:(id)change context:(void *)context is 165 | (set undo (self undoManager)) 166 | (set oldValue (change objectForKey:NSKeyValueChangeOldKey)) 167 | (NSLog "oldValue = #{oldValue}") 168 | ((undo prepareWithInvocationTarget:self) 169 | changeKeyPath:keyPath 170 | ofObject:obj 171 | toValue:oldValue) 172 | (undo setActionName:"Edit")) 173 | 174 | (- (id)windowNibName is "MyDocument") 175 | 176 | (- (void)windowControllerDidLoadNib:(id) aController is 177 | (super windowControllerDidLoadNib:aController) 178 | (set defaults (NSUserDefaults standardUserDefaults)) 179 | (set colorAsData (defaults objectForKey:BNRTableBgColorKey)) 180 | (set color (NSKeyedUnarchiver unarchiveObjectWithData:colorAsData)) 181 | (@tableView setBackgroundColor:color)) 182 | 183 | (- (void)presentError:(id)error modalForWindow:(id)window delegate:(id)delegate didPresentSelector:(SEL)didPresentSelector contextInfo:(void *)contextInfo is 184 | (set ui (error userInfo)) 185 | (set underlying (ui objectForKey:NSUnderlyingErrorKey)) 186 | (NSLog "error = #{error}, userInfo = #{ui}, underlying info = #{(underlying userInfo)}") 187 | (super presentError:error 188 | modalForWindow:window 189 | delegate:delegate 190 | didPresentSelector:didPresentSelector 191 | contextInfo:contextInfo)) 192 | 193 | (- (id)dataOfType:(id)typeName error:(id *)outError is 194 | ((@tableView window) endEditingFor:nil) 195 | (NSKeyedArchiver archivedDataWithRootObject:@employees)) 196 | 197 | (- (BOOL)readFromData:(id)data ofType:(id)typeName error:(id *)outError is 198 | (set a nil) 199 | (try (set a (NSKeyedUnarchiver unarchiveObjectWithData:data)) 200 | (catch (obj) 201 | (if outError 202 | (set d (dict NSLocalizedFailureReasonErrorKey "This file is corrupted like Noriega.")) 203 | (outError setValue:(NSError errorWithDomain:NSOSStatusErrorDomain 204 | code:unimpErr 205 | userInfo:d))) 206 | (return NO))) 207 | (self setEmployees:a) 208 | YES) 209 | 210 | (- (void)handleColorChange:(id)note is 211 | (NSLog "notification arrived: #{note}") 212 | (set newColor ((note userInfo) objectForKey:"color")) 213 | (@tableView setBackgroundColor:newColor)) 214 | ) 215 | 216 | (set SHOW_CONSOLE_AT_STARTUP nil) 217 | 218 | ;; @class ApplicationDelegate 219 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 220 | (class ApplicationDelegate is NSObject 221 | 222 | ;; This method is called after Cocoa has finished its basic application setup. 223 | ;; It instantiates application-specific components. 224 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 225 | (- (void) applicationDidFinishLaunching:(id) sender is 226 | (set $console ((NuConsoleWindowController alloc) init)) 227 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 228 | 229 | ;; install the delegate and keep a reference to it since the application won't retain it. 230 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 231 | 232 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 233 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 234 | 235 | ;; run the main Cocoa event loop 236 | (NSApplicationMain 0 nil) -------------------------------------------------------------------------------- /18_MouseEvents/ImageFun/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/18_MouseEvents/ImageFun/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /18_MouseEvents/ImageFun/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/18_MouseEvents/ImageFun/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /18_MouseEvents/ImageFun/ImageFun.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 44; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 222A5BFF0DE889630005D8EA /* Nu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 222A5BFE0DE889630005D8EA /* Nu.framework */; }; 11 | 222A5C040DE8897A0005D8EA /* main.nu in Resources */ = {isa = PBXBuildFile; fileRef = 222A5C030DE8897A0005D8EA /* main.nu */; }; 12 | 8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; }; 13 | 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; }; 14 | 8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; }; 15 | 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; }; 20 | 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; 21 | 13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = ""; }; 22 | 222A5BFE0DE889630005D8EA /* Nu.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nu.framework; path = /Library/Frameworks/Nu.framework; sourceTree = ""; }; 23 | 222A5C030DE8897A0005D8EA /* main.nu */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.nu; path = nu/main.nu; sourceTree = ""; }; 24 | 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 25 | 29B97319FDCFA39411CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MainMenu.nib; sourceTree = ""; }; 26 | 29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = ""; }; 27 | 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; 28 | 32CA4F630368D1EE00C91783 /* ImageFun_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageFun_Prefix.pch; sourceTree = ""; }; 29 | 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 8D1107320486CEB800E47090 /* ImageFun.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ImageFun.app; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | 8D11072E0486CEB800E47090 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */, 39 | 222A5BFF0DE889630005D8EA /* Nu.framework in Frameworks */, 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXFrameworksBuildPhase section */ 44 | 45 | /* Begin PBXGroup section */ 46 | 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = { 47 | isa = PBXGroup; 48 | children = ( 49 | 222A5BFE0DE889630005D8EA /* Nu.framework */, 50 | 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */, 51 | ); 52 | name = "Linked Frameworks"; 53 | sourceTree = ""; 54 | }; 55 | 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = { 56 | isa = PBXGroup; 57 | children = ( 58 | 29B97324FDCFA39411CA2CEA /* AppKit.framework */, 59 | 13E42FB307B3F0F600E4EEF1 /* CoreData.framework */, 60 | 29B97325FDCFA39411CA2CEA /* Foundation.framework */, 61 | ); 62 | name = "Other Frameworks"; 63 | sourceTree = ""; 64 | }; 65 | 19C28FACFE9D520D11CA2CBB /* Products */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | 8D1107320486CEB800E47090 /* ImageFun.app */, 69 | ); 70 | name = Products; 71 | sourceTree = ""; 72 | }; 73 | 222A5C020DE8896A0005D8EA /* Nu */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | 222A5C030DE8897A0005D8EA /* main.nu */, 77 | ); 78 | name = Nu; 79 | sourceTree = ""; 80 | }; 81 | 29B97314FDCFA39411CA2CEA /* ImageFun */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | 222A5C020DE8896A0005D8EA /* Nu */, 85 | 29B97315FDCFA39411CA2CEA /* Other Sources */, 86 | 29B97317FDCFA39411CA2CEA /* Resources */, 87 | 29B97323FDCFA39411CA2CEA /* Frameworks */, 88 | 19C28FACFE9D520D11CA2CBB /* Products */, 89 | ); 90 | name = ImageFun; 91 | sourceTree = ""; 92 | }; 93 | 29B97315FDCFA39411CA2CEA /* Other Sources */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | 32CA4F630368D1EE00C91783 /* ImageFun_Prefix.pch */, 97 | 29B97316FDCFA39411CA2CEA /* main.m */, 98 | ); 99 | name = "Other Sources"; 100 | sourceTree = ""; 101 | }; 102 | 29B97317FDCFA39411CA2CEA /* Resources */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | 8D1107310486CEB800E47090 /* Info.plist */, 106 | 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */, 107 | 29B97318FDCFA39411CA2CEA /* MainMenu.nib */, 108 | ); 109 | name = Resources; 110 | sourceTree = ""; 111 | }; 112 | 29B97323FDCFA39411CA2CEA /* Frameworks */ = { 113 | isa = PBXGroup; 114 | children = ( 115 | 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */, 116 | 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */, 117 | ); 118 | name = Frameworks; 119 | sourceTree = ""; 120 | }; 121 | /* End PBXGroup section */ 122 | 123 | /* Begin PBXNativeTarget section */ 124 | 8D1107260486CEB800E47090 /* ImageFun */ = { 125 | isa = PBXNativeTarget; 126 | buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "ImageFun" */; 127 | buildPhases = ( 128 | 8D1107290486CEB800E47090 /* Resources */, 129 | 8D11072C0486CEB800E47090 /* Sources */, 130 | 8D11072E0486CEB800E47090 /* Frameworks */, 131 | ); 132 | buildRules = ( 133 | ); 134 | dependencies = ( 135 | ); 136 | name = ImageFun; 137 | productInstallPath = "$(HOME)/Applications"; 138 | productName = ImageFun; 139 | productReference = 8D1107320486CEB800E47090 /* ImageFun.app */; 140 | productType = "com.apple.product-type.application"; 141 | }; 142 | /* End PBXNativeTarget section */ 143 | 144 | /* Begin PBXProject section */ 145 | 29B97313FDCFA39411CA2CEA /* Project object */ = { 146 | isa = PBXProject; 147 | buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ImageFun" */; 148 | compatibilityVersion = "Xcode 3.0"; 149 | hasScannedForEncodings = 1; 150 | mainGroup = 29B97314FDCFA39411CA2CEA /* ImageFun */; 151 | projectDirPath = ""; 152 | projectRoot = ""; 153 | targets = ( 154 | 8D1107260486CEB800E47090 /* ImageFun */, 155 | ); 156 | }; 157 | /* End PBXProject section */ 158 | 159 | /* Begin PBXResourcesBuildPhase section */ 160 | 8D1107290486CEB800E47090 /* Resources */ = { 161 | isa = PBXResourcesBuildPhase; 162 | buildActionMask = 2147483647; 163 | files = ( 164 | 8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */, 165 | 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */, 166 | 222A5C040DE8897A0005D8EA /* main.nu in Resources */, 167 | ); 168 | runOnlyForDeploymentPostprocessing = 0; 169 | }; 170 | /* End PBXResourcesBuildPhase section */ 171 | 172 | /* Begin PBXSourcesBuildPhase section */ 173 | 8D11072C0486CEB800E47090 /* Sources */ = { 174 | isa = PBXSourcesBuildPhase; 175 | buildActionMask = 2147483647; 176 | files = ( 177 | 8D11072D0486CEB800E47090 /* main.m in Sources */, 178 | ); 179 | runOnlyForDeploymentPostprocessing = 0; 180 | }; 181 | /* End PBXSourcesBuildPhase section */ 182 | 183 | /* Begin PBXVariantGroup section */ 184 | 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */ = { 185 | isa = PBXVariantGroup; 186 | children = ( 187 | 089C165DFE840E0CC02AAC07 /* English */, 188 | ); 189 | name = InfoPlist.strings; 190 | sourceTree = ""; 191 | }; 192 | 29B97318FDCFA39411CA2CEA /* MainMenu.nib */ = { 193 | isa = PBXVariantGroup; 194 | children = ( 195 | 29B97319FDCFA39411CA2CEA /* English */, 196 | ); 197 | name = MainMenu.nib; 198 | sourceTree = ""; 199 | }; 200 | /* End PBXVariantGroup section */ 201 | 202 | /* Begin XCBuildConfiguration section */ 203 | C01FCF4B08A954540054247B /* Debug */ = { 204 | isa = XCBuildConfiguration; 205 | buildSettings = { 206 | COPY_PHASE_STRIP = NO; 207 | GCC_DYNAMIC_NO_PIC = NO; 208 | GCC_ENABLE_FIX_AND_CONTINUE = YES; 209 | GCC_MODEL_TUNING = G5; 210 | GCC_OPTIMIZATION_LEVEL = 0; 211 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 212 | GCC_PREFIX_HEADER = ImageFun_Prefix.pch; 213 | INFOPLIST_FILE = Info.plist; 214 | INSTALL_PATH = "$(HOME)/Applications"; 215 | PRODUCT_NAME = ImageFun; 216 | WRAPPER_EXTENSION = app; 217 | ZERO_LINK = YES; 218 | }; 219 | name = Debug; 220 | }; 221 | C01FCF4C08A954540054247B /* Release */ = { 222 | isa = XCBuildConfiguration; 223 | buildSettings = { 224 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 225 | GCC_MODEL_TUNING = G5; 226 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 227 | GCC_PREFIX_HEADER = ImageFun_Prefix.pch; 228 | INFOPLIST_FILE = Info.plist; 229 | INSTALL_PATH = "$(HOME)/Applications"; 230 | PRODUCT_NAME = ImageFun; 231 | WRAPPER_EXTENSION = app; 232 | }; 233 | name = Release; 234 | }; 235 | C01FCF4F08A954540054247B /* Debug */ = { 236 | isa = XCBuildConfiguration; 237 | buildSettings = { 238 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 239 | GCC_WARN_UNUSED_VARIABLE = YES; 240 | PREBINDING = NO; 241 | SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk"; 242 | }; 243 | name = Debug; 244 | }; 245 | C01FCF5008A954540054247B /* Release */ = { 246 | isa = XCBuildConfiguration; 247 | buildSettings = { 248 | ARCHS = ( 249 | ppc, 250 | i386, 251 | ); 252 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 253 | GCC_WARN_UNUSED_VARIABLE = YES; 254 | PREBINDING = NO; 255 | SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk"; 256 | }; 257 | name = Release; 258 | }; 259 | /* End XCBuildConfiguration section */ 260 | 261 | /* Begin XCConfigurationList section */ 262 | C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "ImageFun" */ = { 263 | isa = XCConfigurationList; 264 | buildConfigurations = ( 265 | C01FCF4B08A954540054247B /* Debug */, 266 | C01FCF4C08A954540054247B /* Release */, 267 | ); 268 | defaultConfigurationIsVisible = 0; 269 | defaultConfigurationName = Release; 270 | }; 271 | C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ImageFun" */ = { 272 | isa = XCConfigurationList; 273 | buildConfigurations = ( 274 | C01FCF4F08A954540054247B /* Debug */, 275 | C01FCF5008A954540054247B /* Release */, 276 | ); 277 | defaultConfigurationIsVisible = 0; 278 | defaultConfigurationName = Release; 279 | }; 280 | /* End XCConfigurationList section */ 281 | }; 282 | rootObject = 29B97313FDCFA39411CA2CEA /* Project object */; 283 | } 284 | -------------------------------------------------------------------------------- /18_MouseEvents/ImageFun/ImageFun_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'ImageFun' target in the 'ImageFun' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /18_MouseEvents/ImageFun/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.yourcompany.ImageFun 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | NSMainNibFile 24 | MainMenu 25 | NSPrincipalClass 26 | NSApplication 27 | 28 | 29 | -------------------------------------------------------------------------------- /18_MouseEvents/ImageFun/main.m: -------------------------------------------------------------------------------- 1 | int NuMain(int argc, const char *argv[]); 2 | 3 | int main(int argc, const char *argv[]) 4 | { 5 | return NuMain(argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /18_MouseEvents/ImageFun/nu/main.nu: -------------------------------------------------------------------------------- 1 | ;; file main.nu 2 | ;; discussion Entry point for a Nu program. 3 | ;; copyright Copyright (c) 2008 Tim Burks, Neon Design Technology, Inc. 4 | 5 | (import Cocoa) ;; bridgesupport 6 | (load "console") ;; interactive console 7 | 8 | (set random (NuBridgedFunction functionWithName:"random" signature:"l")) 9 | (function min (a b) (if (< a b) then a else b)) 10 | (function max (a b) (if (> a b) then a else b)) 11 | 12 | (class AppController is NSObject 13 | (ivar (id) stretchView) 14 | 15 | (- (void)showOpenPanel:(id)sender is 16 | (set op (NSOpenPanel openPanel)) 17 | (op beginSheetForDirectory:nil 18 | file:nil 19 | types:(NSImage imageFileTypes) 20 | modalForWindow:(@stretchView window) 21 | modalDelegate:self 22 | didEndSelector:"openPanelDidEnd:returnCode:contextInfo:" 23 | contextInfo:nil)) 24 | 25 | (- (void)openPanelDidEnd:(id)op 26 | returnCode:(int)returnCode 27 | contextInfo:(void *)ci is 28 | (if (eq returnCode NSOKButton) 29 | (set path (op filename)) 30 | (set image ((NSImage alloc) initWithContentsOfFile:path)) 31 | (@stretchView setImage:image)))) 32 | 33 | (class StretchView is NSView 34 | (ivar (id) path (id) image (float) opacity (NSPoint) downPoint (NSPoint) currentPoint) 35 | 36 | (- (id)initWithFrame:(NSRect)frame is 37 | (unless (super initWithFrame:frame) (return nil)) 38 | ;; srandom(time(NULL)) 39 | (set @path ((NSBezierPath alloc) init)) 40 | (@path setLineWidth:3.0) 41 | (set p (self randomPoint)) 42 | (@path moveToPoint:p) 43 | (15 times: 44 | (do (i) 45 | (set p (self randomPoint)) 46 | (@path lineToPoint:p))) 47 | (@path closePath) 48 | (set @opacity 1.0) 49 | self) 50 | 51 | (- (NSPoint)randomPoint is 52 | (set bounds (self bounds)) 53 | (list (+ (bounds first) (% (random) ((bounds third) intValue))) 54 | (+ (bounds second) (% (random) ((bounds fourth) intValue))))) 55 | 56 | (- (void)drawRect:(NSRect)rect is 57 | (set bounds (self bounds)) 58 | ((NSColor greenColor) set) 59 | (NSBezierPath fillRect:bounds) 60 | ((NSColor whiteColor) set) 61 | (@path fill) 62 | (if @image 63 | (set imageRect (append '(0 0) (@image size))) 64 | (set drawingRect (self currentRect)) 65 | (puts "drawing image in #{imageRect} #{drawingRect}") 66 | (@image drawInRect:drawingRect 67 | fromRect:imageRect 68 | operation:NSCompositeSourceOver 69 | fraction:@opacity))) 70 | 71 | (- (void)mouseDown:(id)event is 72 | (set p (event locationInWindow)) 73 | (set @downPoint (self convertPoint:p fromView:nil)) 74 | (set @currentPoint @downPoint) 75 | (self setNeedsDisplay:YES)) 76 | 77 | (- (void)mouseDragged:(id)event is 78 | (set p (event locationInWindow)) 79 | (set @currentPoint (self convertPoint:p fromView:nil)) 80 | (self autoscroll:event) 81 | (self setNeedsDisplay:YES)) 82 | 83 | (- (void)mouseUp:(id)event is 84 | (set p (event locationInWindow)) 85 | (set @currentPoint (self convertPoint:p fromView:nil)) 86 | (self setNeedsDisplay:YES)) 87 | 88 | (- (NSRect)currentRect is 89 | (set minX (min (@downPoint first) (@currentPoint first))) 90 | (set minY (min (@downPoint second) (@currentPoint second))) 91 | (set maxX (max (@downPoint first) (@currentPoint first))) 92 | (set maxY (max (@downPoint second) (@currentPoint second))) 93 | (list minX minY (- maxX minX) (- maxY minY))) 94 | 95 | (- (void)setImage:(id)i is 96 | (set @image i) 97 | (set imageSize (i size)) 98 | (set @downPoint '(0 0)) 99 | (set @currentPoint imageSize) 100 | (self setNeedsDisplay:YES)) 101 | 102 | (- (float)opacity is @opacity) 103 | 104 | (- (void)setOpacity:(float)f is 105 | (set @opacity f) 106 | (self setNeedsDisplay:YES))) 107 | 108 | (set SHOW_CONSOLE_AT_STARTUP nil) 109 | 110 | ;; @class ApplicationDelegate 111 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 112 | (class ApplicationDelegate is NSObject 113 | 114 | ;; This method is called after Cocoa has finished its basic application setup. 115 | ;; It instantiates application-specific components. 116 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 117 | (- (void) applicationDidFinishLaunching:(id) sender is 118 | (set $console ((NuConsoleWindowController alloc) init)) 119 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 120 | 121 | ;; install the delegate and keep a reference to it since the application won't retain it. 122 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 123 | 124 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 125 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 126 | 127 | ;; run the main Cocoa event loop 128 | (NSApplicationMain 0 nil) -------------------------------------------------------------------------------- /19_KeyboardEvents/TypingTutor/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/19_KeyboardEvents/TypingTutor/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /19_KeyboardEvents/TypingTutor/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/19_KeyboardEvents/TypingTutor/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /19_KeyboardEvents/TypingTutor/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.yourcompany.TypingTutor 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | NSMainNibFile 24 | MainMenu 25 | NSPrincipalClass 26 | NSApplication 27 | 28 | 29 | -------------------------------------------------------------------------------- /19_KeyboardEvents/TypingTutor/Nukefile: -------------------------------------------------------------------------------- 1 | ;; Nukefile for TypingTutor 2 | 3 | ;; source files 4 | (set @nu_files (filelist "nu/.*\.nu$")) 5 | (set @resources (filelist "^English\.lproj/Infoplist.strings$")) 6 | (set @nib_files (filelist "^English\.lproj/[^/]*\.nib$")) 7 | 8 | ;; application description 9 | (set @application "TypingTutor") 10 | (set @application_identifier "nu.programming.typingtutor") 11 | 12 | ;; build tasks 13 | (application-tasks) 14 | (task "default" => "application") 15 | -------------------------------------------------------------------------------- /19_KeyboardEvents/TypingTutor/TypingTutor_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'TypingTutor' target in the 'TypingTutor' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /19_KeyboardEvents/TypingTutor/main.m: -------------------------------------------------------------------------------- 1 | int NuMain(int argc, const char *argv[]); 2 | 3 | int main(int argc, const char *argv[]) 4 | { 5 | return NuMain(argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /19_KeyboardEvents/TypingTutor/nu/main.nu: -------------------------------------------------------------------------------- 1 | ;; file main.nu 2 | ;; discussion Entry point for a Nu program. 3 | 4 | (import Cocoa) ;; bridgesupport 5 | (load "console") ;; interactive console 6 | 7 | (set SHOW_CONSOLE_AT_STARTUP nil) 8 | 9 | (class BigLetterView is NSView 10 | (ivar (id) bgColor (id) string) 11 | (ivar-accessors) 12 | 13 | (- (id)initWithFrame:(NSRect)frame is 14 | (super initWithFrame:frame) 15 | (NSLog "initWithFrame:") 16 | (set @bgColor (NSColor yellowColor)) 17 | (set @string " ") 18 | (set $view self) 19 | self) 20 | 21 | (- (void)drawRect:(NSRect)rect is 22 | (set bounds (self bounds)) 23 | (@bgColor set) 24 | (NSBezierPath fillRect:bounds) 25 | (if (and (eq ((self window) firstResponder) self) 26 | (NSGraphicsContext currentContextDrawingToScreen)) 27 | (NSGraphicsContext saveGraphicsState) 28 | (NSSetFocusRingStyle NSFocusRingOnly) 29 | (NSBezierPath fillRect:bounds) 30 | (NSGraphicsContext restoreGraphicsState))) 31 | 32 | (- (BOOL)isOpaque is 33 | (NSLog "isOpaque") 34 | YES) 35 | 36 | (- (BOOL)acceptsFirstResponder is 37 | (NSLog "Accepting") 38 | YES) 39 | 40 | (- (BOOL)resignFirstResponder is 41 | (NSLog "Resigning") 42 | (self setNeedsDisplay:YES) 43 | YES) 44 | 45 | (- (BOOL)becomeFirstResponder is 46 | (NSLog "Becoming") 47 | (self setNeedsDisplay:YES) 48 | YES) 49 | 50 | (- (void)keyDown:(id)e is 51 | (self interpretKeyEvents:(NSArray arrayWithObject:e))) 52 | 53 | (- (void)insertText:(id)s is 54 | (self setString:s)) 55 | 56 | (- (void)insertTab:(id)sender is 57 | ((self window) selectNextKeyView:nil)) 58 | 59 | (- (void)insertBacktab:(id)sender is 60 | ((self window) selectPreviousKeyView:nil)) 61 | 62 | (- (void)deleteBackward:(id)sender is 63 | (self setString:" "))) 64 | 65 | ;; @class ApplicationDelegate 66 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 67 | (class ApplicationDelegate is NSObject 68 | 69 | ;; This method is called after Cocoa has finished its basic application setup. 70 | ;; It instantiates application-specific components. 71 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 72 | (- (void) applicationDidFinishLaunching:(id) sender is 73 | (set $console ((NuConsoleWindowController alloc) init)) 74 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 75 | 76 | ;; install the delegate and keep a reference to it since the application won't retain it. 77 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 78 | 79 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 80 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 81 | 82 | ;; run the main Cocoa event loop 83 | (NSApplicationMain 0 nil) 84 | -------------------------------------------------------------------------------- /28_WebServices/AmaZone/AmaZone_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'AmaZone' target in the 'AmaZone' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /28_WebServices/AmaZone/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/28_WebServices/AmaZone/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /28_WebServices/AmaZone/English.lproj/MainMenu.nib/classes.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBClasses 6 | 7 | 8 | CLASS 9 | FirstResponder 10 | LANGUAGE 11 | ObjC 12 | SUPERCLASS 13 | NSObject 14 | 15 | 16 | ACTIONS 17 | 18 | fetchBooks 19 | id 20 | 21 | CLASS 22 | AppController 23 | LANGUAGE 24 | ObjC 25 | OUTLETS 26 | 27 | progress 28 | NSProgressIndicator 29 | searchField 30 | NSTextField 31 | tableView 32 | NSTableView 33 | 34 | SUPERCLASS 35 | NSObject 36 | 37 | 38 | IBVersion 39 | 1 40 | 41 | 42 | -------------------------------------------------------------------------------- /28_WebServices/AmaZone/English.lproj/MainMenu.nib/info.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBFramework Version 6 | 629 7 | IBLastKnownRelativeProjectPath 8 | ../../AmaZone.xcodeproj 9 | IBOldestOS 10 | 5 11 | IBOpenObjects 12 | 13 | 2 14 | 15 | IBSystem Version 16 | 9B18 17 | targetFramework 18 | IBCocoaFramework 19 | 20 | 21 | -------------------------------------------------------------------------------- /28_WebServices/AmaZone/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/28_WebServices/AmaZone/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /28_WebServices/AmaZone/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | AmaZone 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.apple.myCocoaApplication 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundlePackageType 16 | APPL 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1.0 21 | NSMainNibFile 22 | MainMenu 23 | NSPrincipalClass 24 | NSApplication 25 | 26 | 27 | -------------------------------------------------------------------------------- /28_WebServices/AmaZone/Nukefile: -------------------------------------------------------------------------------- 1 | ;; Nukefile for AmaZone 2 | 3 | ;; source files 4 | (set @nu_files (filelist "nu/.*\.nu$")) 5 | (set @resources (filelist "^English\.lproj/Infoplist.strings$")) 6 | (set @nib_files (filelist "^English\.lproj/[^/]*\.nib$")) 7 | 8 | ;; application description 9 | (set @application "AmaZone") 10 | (set @application_identifier "nu.programming.amazone") 11 | 12 | ;; build tasks 13 | (application-tasks) 14 | (task "default" => "application") 15 | -------------------------------------------------------------------------------- /28_WebServices/AmaZone/main.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @file main.m 3 | @copyright Copyright (c) 2007 Neon Design Technology, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | int NuMain(int argc, const char *argv[]); 18 | 19 | int main(int argc, const char *argv[]) 20 | { 21 | return NuMain(argc, argv); 22 | } 23 | -------------------------------------------------------------------------------- /28_WebServices/AmaZone/nu/main.nu: -------------------------------------------------------------------------------- 1 | ;; file main.nu 2 | ;; discussion Entry point for a Nu program. 3 | ;; 4 | ;; copyright Copyright (c) 2008 Tim Burks, Neon Design Technology, Inc. 5 | 6 | (import Cocoa) ;; bridgesupport 7 | (load "console") ;; interactive console 8 | 9 | (set AWS_ID "1CKE6MZ6S27EFQ458402") 10 | 11 | (function stringForKind (k) 12 | (case k 13 | (NSXMLDocumentKind "Document") 14 | (NSXMLElementKind "Element") 15 | (NSXMLTextKind "Text") 16 | (else (k stringValue)))) 17 | 18 | ;; To see the output of this function, look at the Nu console (command-L). 19 | (function ShowTree (node level) 20 | (set kind (node kind)) 21 | (set kindString (stringForKind kind)) 22 | (level times:(do (i) (print " "))) 23 | (if (eq kind NSXMLTextKind) 24 | (then (puts (+ kindString ": " (node stringValue)))) 25 | (else (puts (+ kindString ": " (node name))))) 26 | ((node children) each: 27 | (do (child) 28 | (ShowTree child (+ 1 level))))) 29 | 30 | (class AppController is NSObject 31 | (ivar (id) progress (id) searchField (id) tableView (id) doc (id) itemNodes) 32 | (ivar-accessors) 33 | 34 | (- (void)awakeFromNib is 35 | (@tableView setDoubleAction:"openItem:") 36 | (@tableView setTarget:self)) 37 | 38 | (- (void)fetchBooks:(id)sender is 39 | ;; Show the user that something is going on 40 | (@progress startAnimation:nil) 41 | 42 | ;; Put together the request 43 | ;; See http://www.amazon.com/gp/aws/landing.html 44 | 45 | ;; Get the string and percent-escape for insertion into URL 46 | (set searchString ((@searchField stringValue) stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding)) 47 | (NSLog "searchString = #{searchString}") 48 | 49 | ;; Create the URL 50 | (set urlString "http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&Operation=ItemSearch&SubscriptionId=#{AWS_ID}&SearchIndex=Books&Keywords=#{searchString}") 51 | (set url (NSURL URLWithString:urlString)) 52 | (set urlRequest (NSURLRequest requestWithURL:url 53 | cachePolicy:NSURLRequestReturnCacheDataElseLoad 54 | timeoutInterval:30)) 55 | 56 | ;; Fetch the XML response 57 | (set urlData (NSURLConnection sendSynchronousRequest:urlRequest 58 | returningResponse:(set responsep (NuReference new)) 59 | error:(set errorp (NuReference new)))) 60 | (unless urlData 61 | (NSRunAlertPanel "Error loading" ((errorp value) localizedDescription) nil nil nil) 62 | (return)) 63 | 64 | ;; Parse the XML response 65 | (set @doc ((NSXMLDocument alloc) initWithData:urlData 66 | options:0 67 | error:errorp)) 68 | (NSLog "doc = #{@doc}") 69 | 70 | (ShowTree @doc 0) 71 | 72 | (unless @doc 73 | (set alert (NSAlert alertWithError:(errorp value))) 74 | (alert runModal) 75 | (return)) 76 | 77 | (set @itemNodes (@doc nodesForXPath:@"ItemSearchResponse/Items/Item" error:errorp)) 78 | (unless @itemNodes 79 | (set alert (NSAlert alertWithError:(errorp value))) 80 | (alert runModal) 81 | (return)) 82 | 83 | ;; Update the interface 84 | (@tableView reloadData) 85 | (@progress stopAnimation:nil)) 86 | 87 | (- (void)openItem:(id)sender is 88 | (set row (@tableView clickedRow)) 89 | (if (eq row -1) (return)) 90 | (set clickedItem (@itemNodes row)) 91 | (set urlString (self stringForPath:"DetailPageURL" ofNode:clickedItem)) 92 | (set url (NSURL URLWithString:urlString)) 93 | ((NSWorkspace sharedWorkspace) openURL:url)) 94 | 95 | (- (id)stringForPath:(id)xp ofNode:(id)n is 96 | (set nodes (n nodesForXPath:xp error:(set perror (NuReference new)))) 97 | (cond ((eq nodes nil) 98 | (set alert (NSAlert alertWithError (perror value))) 99 | (alert runModal)) 100 | ((eq (nodes count) 0) 101 | nil) 102 | (else ((nodes objectAtIndex:0) stringValue)))) 103 | 104 | (- (int)numberOfRowsInTableView:(id) tv is 105 | (@itemNodes count)) 106 | 107 | (- (id)tableView:(id)tv objectValueForTableColumn:(id)tableColumn row:(int)row is 108 | (set itemNode (@itemNodes objectAtIndex:row)) 109 | (set xPath (tableColumn identifier)) 110 | (self stringForPath:xPath ofNode:itemNode))) 111 | 112 | (set SHOW_CONSOLE_AT_STARTUP nil) 113 | 114 | ;; @class ApplicationDelegate 115 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 116 | (class ApplicationDelegate is NSObject 117 | 118 | ;; This method is called after Cocoa has finished its basic application setup. 119 | ;; It instantiates application-specific components. 120 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 121 | (- (void) applicationDidFinishLaunching:(id) sender is 122 | (set $console ((NuConsoleWindowController alloc) init)) 123 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 124 | 125 | ;; install the delegate and keep a reference to it since the application won't retain it. 126 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 127 | 128 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 129 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 130 | 131 | ;; run the main Cocoa event loop 132 | (NSApplicationMain 0 nil) 133 | -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/DepartmentView.nib/classes.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBClasses 6 | 7 | 8 | CLASS 9 | DepartmentViewController 10 | LANGUAGE 11 | ObjC 12 | SUPERCLASS 13 | NSViewController 14 | 15 | 16 | CLASS 17 | FirstResponder 18 | LANGUAGE 19 | ObjC 20 | SUPERCLASS 21 | NSObject 22 | 23 | 24 | IBVersion 25 | 1 26 | 27 | 28 | -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/DepartmentView.nib/info.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBFramework Version 6 | 629 7 | IBLastKnownRelativeProjectPath 8 | ../Departments.xcodeproj 9 | IBOldestOS 10 | 5 11 | IBOpenObjects 12 | 13 | 129 14 | 15 | IBSystem Version 16 | 9B18 17 | targetFramework 18 | IBCocoaFramework 19 | 20 | 21 | -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/DepartmentView.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/29_ViewSwapping/Departments/DepartmentView.nib/keyedobjects.nib -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/Departments_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'Departments' target in the 'Departments' project 3 | // 4 | #ifdef __OBJC__ 5 | #import 6 | #endif 7 | -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/EmployeeView.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/29_ViewSwapping/Departments/EmployeeView.nib/keyedobjects.nib -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/English.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/29_ViewSwapping/Departments/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/English.lproj/MainMenu.nib/classes.nib: -------------------------------------------------------------------------------- 1 | { 2 | IBClasses = ( 3 | { 4 | CLASS = FirstResponder; 5 | LANGUAGE = ObjC; 6 | SUPERCLASS = NSObject; 7 | } 8 | ); 9 | IBVersion = 1; 10 | } -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/English.lproj/MainMenu.nib/info.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBDocumentLocation 6 | 474 126 356 240 0 0 1680 1028 7 | IBEditorPositions 8 | 9 | 29 10 | 338 633 459 44 0 0 1680 1028 11 | 12 | IBFramework Version 13 | 461.0 14 | IBOldestOS 15 | 4 16 | IBOpenObjects 17 | 18 | 29 19 | 20 | IBSystem Version 21 | 9A440 22 | IBUsesTextArchiving 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/English.lproj/MyDocument.nib/classes.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBClasses 6 | 7 | 8 | CLASS 9 | FirstResponder 10 | LANGUAGE 11 | ObjC 12 | SUPERCLASS 13 | NSObject 14 | 15 | 16 | ACTIONS 17 | 18 | changeViewController 19 | id 20 | 21 | CLASS 22 | MyDocument 23 | LANGUAGE 24 | ObjC 25 | OUTLETS 26 | 27 | box 28 | NSBox 29 | popUp 30 | NSPopUpButton 31 | 32 | SUPERCLASS 33 | NSPersistentDocument 34 | 35 | 36 | CLASS 37 | NSPersistentDocument 38 | LANGUAGE 39 | ObjC 40 | SUPERCLASS 41 | NSDocument 42 | 43 | 44 | IBVersion 45 | 1 46 | 47 | 48 | -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/English.lproj/MyDocument.nib/info.nib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IBFramework Version 6 | 629 7 | IBLastKnownRelativeProjectPath 8 | ../../Departments.xcodeproj 9 | IBOldestOS 10 | 5 11 | IBOpenObjects 12 | 13 | 6 14 | 15 | IBSystem Version 16 | 9B18 17 | targetFramework 18 | IBCocoaFramework 19 | 20 | 21 | -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/English.lproj/MyDocument.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/29_ViewSwapping/Departments/English.lproj/MyDocument.nib/keyedobjects.nib -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeExtensions 11 | 12 | binary 13 | 14 | CFBundleTypeMIMETypes 15 | 16 | application/octet-stream 17 | 18 | CFBundleTypeName 19 | Binary 20 | CFBundleTypeRole 21 | Editor 22 | LSTypeIsPackage 23 | 24 | NSDocumentClass 25 | MyDocument 26 | NSPersistentStoreTypeKey 27 | Binary 28 | 29 | 30 | CFBundleTypeExtensions 31 | 32 | sqlite 33 | 34 | CFBundleTypeMIMETypes 35 | 36 | application/octet-stream 37 | 38 | CFBundleTypeName 39 | SQLite 40 | CFBundleTypeRole 41 | Editor 42 | LSTypeIsPackage 43 | 44 | NSDocumentClass 45 | MyDocument 46 | NSPersistentStoreTypeKey 47 | SQLite 48 | 49 | 50 | CFBundleTypeExtensions 51 | 52 | xml 53 | 54 | CFBundleTypeIconFile 55 | 56 | CFBundleTypeMIMETypes 57 | 58 | text/xml 59 | 60 | CFBundleTypeName 61 | XML 62 | CFBundleTypeOSTypes 63 | 64 | ???? 65 | 66 | CFBundleTypeRole 67 | Editor 68 | LSTypeIsPackage 69 | 70 | NSDocumentClass 71 | MyDocument 72 | NSPersistentStoreTypeKey 73 | XML 74 | 75 | 76 | CFBundleName 77 | ${PRODUCT_NAME} 78 | CFBundleExecutable 79 | ${EXECUTABLE_NAME} 80 | CFBundleIconFile 81 | 82 | CFBundleIdentifier 83 | com.yourcompany.DepartmentsApp 84 | CFBundleInfoDictionaryVersion 85 | 6.0 86 | CFBundlePackageType 87 | APPL 88 | CFBundleShortVersionString 89 | 1.2 90 | CFBundleSignature 91 | ???? 92 | CFBundleVersion 93 | 22 94 | NSMainNibFile 95 | MainMenu 96 | NSPrincipalClass 97 | NSApplication 98 | 99 | 100 | -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/MyDocument.xcdatamodel/elements: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/29_ViewSwapping/Departments/MyDocument.xcdatamodel/elements -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/MyDocument.xcdatamodel/layout: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/29_ViewSwapping/Departments/MyDocument.xcdatamodel/layout -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/main.m: -------------------------------------------------------------------------------- 1 | int NuMain(int argc, const char *argv[]); 2 | 3 | int main(int argc, const char *argv[]) 4 | { 5 | return NuMain(argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/nu/main.nu: -------------------------------------------------------------------------------- 1 | ;; file main.nu 2 | ;; discussion Entry point for a Nu program. 3 | ;; copyright Copyright (c) 2008 Tim Burks, Neon Design Technology, Inc. 4 | 5 | (import Cocoa) ;; bridgesupport 6 | (load "console") ;; interactive console 7 | 8 | (class ManagingViewController is NSViewController 9 | (ivar (id) managedObjectContext) 10 | (- (void)setManagedObjectContext:(id)moc is 11 | (set @managedObjectContext moc))) 12 | 13 | (class EmployeeViewController is ManagingViewController 14 | (- (id)init is 15 | (unless (super initWithNibName:"EmployeeView" bundle:nil) 16 | (return nil)) 17 | (self setTitle:"Employees") 18 | self)) 19 | 20 | (class DepartmentViewController is ManagingViewController 21 | (- (id)init is 22 | (unless (super initWithNibName:"DepartmentView" bundle:nil) 23 | (return nil)) 24 | (self setTitle:"Departments") 25 | self)) 26 | 27 | (class MyDocument is NSPersistentDocument 28 | (ivar (id) box (id) popUp (id) viewControllers) 29 | 30 | (- (void)prepareViewControllers is 31 | (set @viewControllers (array (((DepartmentViewController alloc) init) 32 | set:(managedObjectContext:(self managedObjectContext))) 33 | (((EmployeeViewController alloc) init) 34 | set:(managedObjectContext:(self managedObjectContext)))))) 35 | 36 | (- (id)init is 37 | (unless (super init) (return nil)) 38 | (self prepareViewControllers) 39 | self) 40 | 41 | (- (void)windowControllerDidLoadNib:(id)windowController is 42 | (super windowControllerDidLoadNib:windowController) 43 | (set menu (@popUp menu)) 44 | (@viewControllers eachWithIndex: 45 | (do (vc i) 46 | (set mi ((NSMenuItem alloc) initWithTitle:(vc title) action:"changeViewController:" keyEquivalent:"")) 47 | (mi setTag:i) 48 | (menu addItem:mi) 49 | (NSLog "added #{mi} to #{menu}"))) 50 | (self displayViewController:(@viewControllers objectAtIndex:0)) 51 | (@popUp selectItemAtIndex:0)) 52 | 53 | (- (void)displayViewController:(id)vc is 54 | (set w (@box window)) 55 | (set ended (w makeFirstResponder:w)) 56 | (unless ended 57 | (NSBeep) 58 | (return)) 59 | (set v (vc view)) 60 | (set currentSize ((((@box contentView) frame) cdr) cdr)) 61 | (set newSize (((v frame) cdr) cdr)) 62 | (set deltaWidth (- (newSize first) (currentSize first))) 63 | (set deltaHeight (- (newSize second) (currentSize second))) 64 | (set windowFrame (w frame)) 65 | (set windowFrame (list (windowFrame first) 66 | (- (windowFrame second) deltaHeight) 67 | (+ (windowFrame third) deltaWidth) 68 | (+ (windowFrame fourth) deltaHeight))) 69 | (@box setContentView:nil) 70 | (w setFrame:windowFrame display:YES animate:YES) 71 | (@box setContentView:v) 72 | ;; Put the view controller in the responder chain 73 | (v setNextResponder:vc) 74 | (vc setNextResponder:@box)) 75 | 76 | (- (void)changeViewController:(id)sender is 77 | (self displayViewController:(@viewControllers objectAtIndex:(sender tag)))) 78 | 79 | (- (id)windowNibName is "MyDocument")) 80 | 81 | (set SHOW_CONSOLE_AT_STARTUP nil) 82 | 83 | ;; @class ApplicationDelegate 84 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 85 | (class ApplicationDelegate is NSObject 86 | 87 | ;; This method is called after Cocoa has finished its basic application setup. 88 | ;; It instantiates application-specific components. 89 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 90 | (- (void) applicationDidFinishLaunching:(id) sender is 91 | (set $console ((NuConsoleWindowController alloc) init)) 92 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 93 | 94 | ;; install the delegate and keep a reference to it since the application won't retain it. 95 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 96 | 97 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 98 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 99 | 100 | ;; run the main Cocoa event loop 101 | (NSApplicationMain 0 nil) -------------------------------------------------------------------------------- /29_ViewSwapping/Departments/version.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildVersion 6 | 9 7 | CFBundleVersion 8 | 1.0 9 | ProjectName 10 | NibPBTemplates 11 | SourceVersion 12 | 1200000 13 | 14 | 15 | -------------------------------------------------------------------------------- /32_CoreAnimation/LayerPolynomials/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/32_CoreAnimation/LayerPolynomials/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /32_CoreAnimation/LayerPolynomials/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/32_CoreAnimation/LayerPolynomials/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /32_CoreAnimation/LayerPolynomials/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.yourcompany.Polynomials 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | NSMainNibFile 24 | MainMenu 25 | NSPrincipalClass 26 | NSApplication 27 | 28 | 29 | -------------------------------------------------------------------------------- /32_CoreAnimation/LayerPolynomials/Nu/main.nu: -------------------------------------------------------------------------------- 1 | ;; file main.nu 2 | ;; discussion Entry point for a Nu program. 3 | ;; copyright Copyright (c) 2008 Tim Burks, Neon Design Technology, Inc. 4 | 5 | (import Cocoa) ;; bridgesupport 6 | (load "console") ;; interactive console 7 | 8 | (set MARGIN 10) 9 | 10 | (global M_PI 3.1415927) 11 | (global hypot (NuBridgedFunction functionWithName:"hypot" signature:"ddd")) 12 | (global random (NuBridgedFunction functionWithName:"random" signature:"l")) 13 | (global cos (NuBridgedFunction functionWithName:"cos" signature:"dd")) 14 | (global sin (NuBridgedFunction functionWithName:"sin" signature:"dd")) 15 | 16 | (class PolynomialView is NSView 17 | (ivar (id) polynomials (BOOL) blasted) 18 | 19 | (- (id)initWithFrame:(NSRect)frame is 20 | (super initWithFrame:frame) 21 | (set @polynomials (array)) 22 | (set @blasted NO) 23 | self) 24 | 25 | (- (void)resizeAndRedrawPolynomialLayers is 26 | (set b ((self layer) bounds)) 27 | (set b (CGRectInset b MARGIN MARGIN)) 28 | (NSAnimationContext beginGrouping) 29 | ((NSAnimationContext currentContext) setDuration:0) 30 | (set polynomialLayers ((self layer) sublayers)) 31 | (polynomialLayers each: 32 | (do (layer) 33 | (layer setFrame:(list ((layer frame) 0) 34 | ((layer frame) 1) 35 | (b 2) 36 | (b 3))) 37 | (layer setNeedsDisplay))) 38 | (NSAnimationContext endGrouping)) 39 | 40 | (- (void)setFrameSize:(NSSize)newSize is 41 | (super setFrameSize:newSize) 42 | (unless (self inLiveResize)) 43 | (self resizeAndRedrawPolynomialLayers)) 44 | 45 | (- (void)viewDidEndLiveResize is 46 | (self resizeAndRedrawPolynomialLayers)) 47 | 48 | (- (void)blastem:(id)sender is 49 | (NSAnimationContext beginGrouping) 50 | ((NSAnimationContext currentContext) setDuration:3.0) 51 | (set polynomialLayers ((self layer) sublayers)) 52 | (polynomialLayers each: 53 | (do (layer) 54 | (if @blasted 55 | (then (set p (list MARGIN MARGIN))) 56 | (else (set p (self randomOffViewPosition)))) 57 | (layer setPosition:p))) 58 | (NSAnimationContext endGrouping) 59 | (self willChangeValueForKey:"blasted") 60 | (set @blasted (not @blasted)) 61 | (self didChangeValueForKey:"blasted")) 62 | 63 | (- (NSPoint)randomOffViewPosition is 64 | (set bounds (self bounds)) 65 | (set radius (hypot (bounds third) (bounds fourth))) 66 | (set angle (* 2.0 M_PI (/ (% (random) 360) 360.0))) 67 | (list (* radius (cos angle)) (* radius (sin angle)))) 68 | 69 | (- (void)createNewPolynomial:(id)sender is 70 | (set p ((Polynomial alloc) init)) 71 | (@polynomials addObject:p) 72 | (set layer (CALayer layer)) 73 | (set b ((self layer) bounds)) 74 | (set b (CGRectInset b MARGIN MARGIN)) 75 | (layer setAnchorPoint:'(0 0)) 76 | (layer setFrame:b) 77 | (layer setDelegate:p) 78 | (layer setCornerRadius:12) 79 | (layer setBorderColor:(p color)) 80 | (layer setBorderWidth:3.5) 81 | ((self layer) addSublayer:layer) 82 | (layer display) 83 | (set anim (CABasicAnimation animationWithKeyPath:"position")) 84 | (anim setFromValue:(NSValue valueWithPoint:(self randomOffViewPosition))) 85 | (anim setToValue:(NSValue valueWithPoint:(list MARGIN MARGIN))) 86 | (anim setDuration:1.0) 87 | (set f (CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear)) 88 | (anim setTimingFunction:f) 89 | (layer addAnimation:anim forKey:"whatever")) 90 | 91 | (- (void)deleteRandomPolynomial:(id)sender is 92 | (set polynomialLayers ((self layer) sublayers)) 93 | (if (or (eq polynomialLayers nil) (eq (polynomialLayers count) 0)) 94 | (NSBeep) 95 | (return)) 96 | (set i (% (random) (polynomialLayers count))) 97 | (set toPoint (self randomOffViewPosition)) 98 | (set layerToPull (polynomialLayers objectAtIndex:i)) 99 | (set anim (CABasicAnimation animationWithKeyPath:"position")) 100 | (anim setValue:layerToPull forKey:"representedPolynomialLayer") 101 | (anim setFromValue:(NSValue valueWithPoint:(NSMakePoint MARGIN MARGIN))) 102 | (anim setToValue:(NSValue valueWithPoint:toPoint)) 103 | (anim setDuration:1.0) 104 | (set f (CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear)) 105 | (anim setTimingFunction:f) 106 | (anim setDelegate:self) 107 | (layerToPull addAnimation:anim forKey:"whatever") 108 | (layerToPull setPosition:toPoint)) 109 | 110 | (- (void)animationDidStop:(id)anim finished:(BOOL)flag is 111 | (NSLog "deleting polynomial") 112 | ;; FIXME: layer flashes at Position 0,0 before removal 113 | (set layerToPull (anim valueForKey:"representedPolynomialLayer")) 114 | (set p (layerToPull delegate)) 115 | (@polynomials removeObjectIdenticalTo:p) 116 | (layerToPull removeFromSuperlayer)) 117 | 118 | (- (void)drawRect:(NSRect)rect is 119 | (set bounds (self bounds)) 120 | ((NSColor whiteColor) set) 121 | (NSBezierPath fillRect:bounds))) 122 | 123 | (set SHOW_CONSOLE_AT_STARTUP nil) 124 | 125 | ;; @class ApplicationDelegate 126 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 127 | (class ApplicationDelegate is NSObject 128 | 129 | ;; This method is called after Cocoa has finished its basic application setup. 130 | ;; It instantiates application-specific components. 131 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 132 | (- (void) applicationDidFinishLaunching:(id) sender is 133 | (set $console ((NuConsoleWindowController alloc) init)) 134 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 135 | 136 | ;; install the delegate and keep a reference to it since the application won't retain it. 137 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 138 | 139 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 140 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 141 | 142 | ;; run the main Cocoa event loop 143 | (NSApplicationMain 0 nil) 144 | -------------------------------------------------------------------------------- /32_CoreAnimation/LayerPolynomials/Polynomial.h: -------------------------------------------------------------------------------- 1 | // 2 | // Polynomial.h 3 | // Polynomials 4 | // 5 | // Created by Aaron Hillegass on 11/27/07. 6 | // Copyright 2007 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface Polynomial : NSObject { 12 | __strong CGFloat * terms; 13 | int termCount; 14 | __strong CGColorRef color; 15 | } 16 | - (id)init; 17 | - (float)valueAt:(float)x; 18 | - (void)drawInRect:(CGRect)b 19 | inContext:(CGContextRef)ctx; 20 | - (CGColorRef)color; 21 | @end 22 | -------------------------------------------------------------------------------- /32_CoreAnimation/LayerPolynomials/Polynomial.m: -------------------------------------------------------------------------------- 1 | // 2 | // Polynomial.m 3 | // Polynomials 4 | // 5 | // Created by Aaron Hillegass on 11/27/07. 6 | // Copyright 2007 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "Polynomial.h" 10 | #import 11 | 12 | #define HOPS (100) 13 | #define RANDFLOAT() (random() % 128 / 128.0) 14 | 15 | static CGRect funcRect = {-20, -20, 40, 40}; 16 | 17 | @implementation Polynomial 18 | - (id)init 19 | { 20 | [super init]; 21 | termCount = (random() % 3) + 2; 22 | terms = NSAllocateCollectable(termCount * sizeof(CGFloat), NSScannedOption); 23 | color = CGColorCreateGenericRGB(RANDFLOAT(), RANDFLOAT(), RANDFLOAT(), 0.7); 24 | NSMakeCollectable(color); 25 | 26 | int i; 27 | for (i = 0; i < termCount; i++) { 28 | terms[i] = 5.0 - (random() % 100) / 10.0; 29 | } 30 | 31 | return self; 32 | } 33 | - (float)valueAt:(float)x 34 | { 35 | float result = 0; 36 | int i; 37 | for (i = 0; i < termCount; i++) { 38 | result = (result * x) + terms[i]; 39 | } 40 | return result; 41 | } 42 | 43 | - (void)drawInRect:(CGRect)b inContext:(CGContextRef)ctx 44 | { 45 | NSLog(@"drawing"); 46 | CGAffineTransform tf; 47 | tf = CGAffineTransformMake(b.size.width / funcRect.size.width, 0, 48 | 0, b.size.height / funcRect.size.height, 49 | b.size.width/2, b.size.height/2); 50 | CGContextSaveGState(ctx); 51 | CGContextConcatCTM(ctx, tf); 52 | CGContextSetStrokeColorWithColor(ctx, color); 53 | CGContextSetLineWidth(ctx, 0.4); 54 | float distance = funcRect.size.width / HOPS; 55 | float currentX = funcRect.origin.x; 56 | BOOL first = YES; 57 | while (currentX <= funcRect.origin.x + funcRect.size.width) { 58 | float currentY = [self valueAt:currentX]; 59 | if (first) { 60 | CGContextMoveToPoint(ctx, currentX, currentY); 61 | first = NO; 62 | } else { 63 | CGContextAddLineToPoint(ctx, currentX, currentY); 64 | } 65 | currentX += distance; 66 | } 67 | CGContextStrokePath(ctx); 68 | CGContextRestoreGState(ctx); 69 | 70 | } 71 | 72 | - (void)drawLayer:(CALayer *)layer 73 | inContext:(CGContextRef)ctx 74 | { 75 | CGRect cgb = [layer bounds]; 76 | [self drawInRect:cgb 77 | inContext:ctx]; 78 | } 79 | - (id)actionForLayer:(CALayer *)layer 80 | forKey:(NSString *)event 81 | { 82 | NSLog(@"action = %@", event); 83 | return nil; 84 | } 85 | 86 | 87 | - (CGColorRef)color 88 | { 89 | return color; 90 | } 91 | - (void)finalize 92 | { 93 | NSLog(@"finalizing"); 94 | [super finalize]; 95 | } 96 | 97 | @end 98 | -------------------------------------------------------------------------------- /32_CoreAnimation/LayerPolynomials/Polynomials_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'Polynomials' target in the 'Polynomials' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /32_CoreAnimation/LayerPolynomials/main.m: -------------------------------------------------------------------------------- 1 | /*! 2 | @file main.m 3 | @copyright Copyright (c) 2007 Neon Design Technology, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | int NuMain(int argc, const char *argv[]); 18 | 19 | int main(int argc, const char *argv[]) 20 | { 21 | return NuMain(argc, argv); 22 | } 23 | -------------------------------------------------------------------------------- /34_NSTask/ZIPspector/English.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /34_NSTask/ZIPspector/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/34_NSTask/ZIPspector/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /34_NSTask/ZIPspector/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/34_NSTask/ZIPspector/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /34_NSTask/ZIPspector/English.lproj/MyDocument.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/34_NSTask/ZIPspector/English.lproj/MyDocument.nib/keyedobjects.nib -------------------------------------------------------------------------------- /34_NSTask/ZIPspector/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeIconFile 11 | 12 | CFBundleTypeName 13 | ZipDocument 14 | CFBundleTypeRole 15 | Viewer 16 | LSItemContentTypes 17 | 18 | com.pkware.zip-archive 19 | 20 | NSDocumentClass 21 | MyDocument 22 | 23 | 24 | CFBundleExecutable 25 | ${EXECUTABLE_NAME} 26 | CFBundleIconFile 27 | 28 | CFBundleIdentifier 29 | com.bignerdranch.ZIPspector 30 | CFBundleInfoDictionaryVersion 31 | 6.0 32 | CFBundleName 33 | ${PRODUCT_NAME} 34 | CFBundlePackageType 35 | APPL 36 | CFBundleSignature 37 | ???? 38 | CFBundleVersion 39 | 1.0 40 | NSMainNibFile 41 | MainMenu 42 | NSPrincipalClass 43 | NSApplication 44 | 45 | 46 | -------------------------------------------------------------------------------- /34_NSTask/ZIPspector/ZIPspector_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'ZIPspector' target in the 'ZIPspector' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /34_NSTask/ZIPspector/main.m: -------------------------------------------------------------------------------- 1 | int NuMain(int argc, const char *argv[]); 2 | 3 | int main(int argc, const char *argv[]) 4 | { 5 | return NuMain(argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /34_NSTask/ZIPspector/nu/main.nu: -------------------------------------------------------------------------------- 1 | ;; file main.nu 2 | ;; discussion Entry point for a Nu program. 3 | ;; copyright Copyright (c) 2008 Tim Burks, Neon Design Technology, Inc. 4 | 5 | (import Cocoa) ;; bridgesupport 6 | (load "console") ;; interactive console 7 | 8 | (class MyDocument is NSDocument 9 | (ivar (id) tableView (id) filenames) 10 | 11 | (- (id)windowNibName is "MyDocument") 12 | 13 | (- (void)windowControllerDidLoadNib:(id) aController is 14 | (super windowControllerDidLoadNib:aController) 15 | (@tableView reloadData)) 16 | 17 | (- (BOOL)readFromURL:(id)absoluteURL ofType:(id)typeName error:(id *)outError is 18 | (set filename (absoluteURL path)) 19 | (set task ((NSTask alloc) init)) 20 | (task setLaunchPath:"/usr/bin/zipinfo") 21 | (task setArguments:(array "-1" filename)) 22 | (task setStandardOutput:(set outPipe ((NSPipe alloc) init))) 23 | (task launch) 24 | (set data ((outPipe fileHandleForReading) readDataToEndOfFile)) 25 | (task waitUntilExit) 26 | (set status (task terminationStatus)) 27 | (if (!= status 0) 28 | (unless (eq outError nil) 29 | (set eDict (dict NSLocalizedFailureReasonErrorKey "zipinfo exited abnormally")) 30 | (outError setValue:(NSError errorWithDomain:NSOSStatusErrorDomain code:0 userInfo:eDict))) 31 | (return NO)) 32 | ;; Convert to a string 33 | (set aString ((NSString alloc) initWithData:data encoding:NSUTF8StringEncoding)) 34 | ;; Break the string into lines 35 | (set @filenames (aString componentsSeparatedByString:"\n")) 36 | ;; In case of revert 37 | (@tableView reloadData) 38 | YES) 39 | 40 | (- (int)numberOfRowsInTableView:(id)tv is 41 | (@filenames count)) 42 | 43 | (- (id)tableView:(id)tv objectValueForTableColumn:(id)tc row:(int)row is 44 | (@filenames objectAtIndex:row))) 45 | 46 | (set SHOW_CONSOLE_AT_STARTUP nil) 47 | 48 | ;; @class ApplicationDelegate 49 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 50 | (class ApplicationDelegate is NSObject 51 | 52 | ;; This method is called after Cocoa has finished its basic application setup. 53 | ;; It instantiates application-specific components. 54 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 55 | (- (void) applicationDidFinishLaunching:(id) sender is 56 | (set $console ((NuConsoleWindowController alloc) init)) 57 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 58 | 59 | ;; install the delegate and keep a reference to it since the application won't retain it. 60 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 61 | 62 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 63 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 64 | 65 | ;; run the main Cocoa event loop 66 | (NSApplicationMain 0 nil) 67 | -------------------------------------------------------------------------------- /34_NSTask/iPing/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/34_NSTask/iPing/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /34_NSTask/iPing/English.lproj/MainMenu.nib/keyedobjects.nib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timburks/cocoa-programming-with-nu/bdbfd5bcadb09b65615037693fd1ef34cf3adbfe/34_NSTask/iPing/English.lproj/MainMenu.nib/keyedobjects.nib -------------------------------------------------------------------------------- /34_NSTask/iPing/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.yourcompany.iPing 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | NSMainNibFile 24 | MainMenu 25 | NSPrincipalClass 26 | NSApplication 27 | 28 | 29 | -------------------------------------------------------------------------------- /34_NSTask/iPing/iPing.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 44; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 2293DE100DE7BFB10020A69D /* main.nu in Resources */ = {isa = PBXBuildFile; fileRef = 2293DE0F0DE7BFB10020A69D /* main.nu */; }; 11 | 2293DE120DE7BFBE0020A69D /* Nu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2293DE110DE7BFBE0020A69D /* Nu.framework */; }; 12 | 8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; }; 13 | 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; }; 14 | 8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; }; 15 | 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; }; 20 | 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; 21 | 13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = ""; }; 22 | 2293DE0F0DE7BFB10020A69D /* main.nu */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.nu; path = nu/main.nu; sourceTree = ""; }; 23 | 2293DE110DE7BFBE0020A69D /* Nu.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nu.framework; path = /Library/Frameworks/Nu.framework; sourceTree = ""; }; 24 | 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 25 | 29B97319FDCFA39411CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MainMenu.nib; sourceTree = ""; }; 26 | 29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = ""; }; 27 | 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; 28 | 32CA4F630368D1EE00C91783 /* iPing_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iPing_Prefix.pch; sourceTree = ""; }; 29 | 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 8D1107320486CEB800E47090 /* iPing.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iPing.app; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | 8D11072E0486CEB800E47090 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */, 39 | 2293DE120DE7BFBE0020A69D /* Nu.framework in Frameworks */, 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXFrameworksBuildPhase section */ 44 | 45 | /* Begin PBXGroup section */ 46 | 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = { 47 | isa = PBXGroup; 48 | children = ( 49 | 2293DE110DE7BFBE0020A69D /* Nu.framework */, 50 | 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */, 51 | ); 52 | name = "Linked Frameworks"; 53 | sourceTree = ""; 54 | }; 55 | 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = { 56 | isa = PBXGroup; 57 | children = ( 58 | 29B97324FDCFA39411CA2CEA /* AppKit.framework */, 59 | 13E42FB307B3F0F600E4EEF1 /* CoreData.framework */, 60 | 29B97325FDCFA39411CA2CEA /* Foundation.framework */, 61 | ); 62 | name = "Other Frameworks"; 63 | sourceTree = ""; 64 | }; 65 | 19C28FACFE9D520D11CA2CBB /* Products */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | 8D1107320486CEB800E47090 /* iPing.app */, 69 | ); 70 | name = Products; 71 | sourceTree = ""; 72 | }; 73 | 2293DE0C0DE7BFA20020A69D /* Nu */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | 2293DE0F0DE7BFB10020A69D /* main.nu */, 77 | ); 78 | name = Nu; 79 | sourceTree = ""; 80 | }; 81 | 29B97314FDCFA39411CA2CEA /* iPing */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | 2293DE0C0DE7BFA20020A69D /* Nu */, 85 | 29B97315FDCFA39411CA2CEA /* Other Sources */, 86 | 29B97317FDCFA39411CA2CEA /* Resources */, 87 | 29B97323FDCFA39411CA2CEA /* Frameworks */, 88 | 19C28FACFE9D520D11CA2CBB /* Products */, 89 | ); 90 | name = iPing; 91 | sourceTree = ""; 92 | }; 93 | 29B97315FDCFA39411CA2CEA /* Other Sources */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | 32CA4F630368D1EE00C91783 /* iPing_Prefix.pch */, 97 | 29B97316FDCFA39411CA2CEA /* main.m */, 98 | ); 99 | name = "Other Sources"; 100 | sourceTree = ""; 101 | }; 102 | 29B97317FDCFA39411CA2CEA /* Resources */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | 8D1107310486CEB800E47090 /* Info.plist */, 106 | 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */, 107 | 29B97318FDCFA39411CA2CEA /* MainMenu.nib */, 108 | ); 109 | name = Resources; 110 | sourceTree = ""; 111 | }; 112 | 29B97323FDCFA39411CA2CEA /* Frameworks */ = { 113 | isa = PBXGroup; 114 | children = ( 115 | 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */, 116 | 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */, 117 | ); 118 | name = Frameworks; 119 | sourceTree = ""; 120 | }; 121 | /* End PBXGroup section */ 122 | 123 | /* Begin PBXNativeTarget section */ 124 | 8D1107260486CEB800E47090 /* iPing */ = { 125 | isa = PBXNativeTarget; 126 | buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "iPing" */; 127 | buildPhases = ( 128 | 8D1107290486CEB800E47090 /* Resources */, 129 | 8D11072C0486CEB800E47090 /* Sources */, 130 | 8D11072E0486CEB800E47090 /* Frameworks */, 131 | ); 132 | buildRules = ( 133 | ); 134 | dependencies = ( 135 | ); 136 | name = iPing; 137 | productInstallPath = "$(HOME)/Applications"; 138 | productName = iPing; 139 | productReference = 8D1107320486CEB800E47090 /* iPing.app */; 140 | productType = "com.apple.product-type.application"; 141 | }; 142 | /* End PBXNativeTarget section */ 143 | 144 | /* Begin PBXProject section */ 145 | 29B97313FDCFA39411CA2CEA /* Project object */ = { 146 | isa = PBXProject; 147 | buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "iPing" */; 148 | compatibilityVersion = "Xcode 3.0"; 149 | hasScannedForEncodings = 1; 150 | mainGroup = 29B97314FDCFA39411CA2CEA /* iPing */; 151 | projectDirPath = ""; 152 | projectRoot = ""; 153 | targets = ( 154 | 8D1107260486CEB800E47090 /* iPing */, 155 | ); 156 | }; 157 | /* End PBXProject section */ 158 | 159 | /* Begin PBXResourcesBuildPhase section */ 160 | 8D1107290486CEB800E47090 /* Resources */ = { 161 | isa = PBXResourcesBuildPhase; 162 | buildActionMask = 2147483647; 163 | files = ( 164 | 8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */, 165 | 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */, 166 | 2293DE100DE7BFB10020A69D /* main.nu in Resources */, 167 | ); 168 | runOnlyForDeploymentPostprocessing = 0; 169 | }; 170 | /* End PBXResourcesBuildPhase section */ 171 | 172 | /* Begin PBXSourcesBuildPhase section */ 173 | 8D11072C0486CEB800E47090 /* Sources */ = { 174 | isa = PBXSourcesBuildPhase; 175 | buildActionMask = 2147483647; 176 | files = ( 177 | 8D11072D0486CEB800E47090 /* main.m in Sources */, 178 | ); 179 | runOnlyForDeploymentPostprocessing = 0; 180 | }; 181 | /* End PBXSourcesBuildPhase section */ 182 | 183 | /* Begin PBXVariantGroup section */ 184 | 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */ = { 185 | isa = PBXVariantGroup; 186 | children = ( 187 | 089C165DFE840E0CC02AAC07 /* English */, 188 | ); 189 | name = InfoPlist.strings; 190 | sourceTree = ""; 191 | }; 192 | 29B97318FDCFA39411CA2CEA /* MainMenu.nib */ = { 193 | isa = PBXVariantGroup; 194 | children = ( 195 | 29B97319FDCFA39411CA2CEA /* English */, 196 | ); 197 | name = MainMenu.nib; 198 | sourceTree = ""; 199 | }; 200 | /* End PBXVariantGroup section */ 201 | 202 | /* Begin XCBuildConfiguration section */ 203 | C01FCF4B08A954540054247B /* Debug */ = { 204 | isa = XCBuildConfiguration; 205 | buildSettings = { 206 | COPY_PHASE_STRIP = NO; 207 | GCC_DYNAMIC_NO_PIC = NO; 208 | GCC_ENABLE_FIX_AND_CONTINUE = YES; 209 | GCC_MODEL_TUNING = G5; 210 | GCC_OPTIMIZATION_LEVEL = 0; 211 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 212 | GCC_PREFIX_HEADER = iPing_Prefix.pch; 213 | INFOPLIST_FILE = Info.plist; 214 | INSTALL_PATH = "$(HOME)/Applications"; 215 | PRODUCT_NAME = iPing; 216 | WRAPPER_EXTENSION = app; 217 | ZERO_LINK = YES; 218 | }; 219 | name = Debug; 220 | }; 221 | C01FCF4C08A954540054247B /* Release */ = { 222 | isa = XCBuildConfiguration; 223 | buildSettings = { 224 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 225 | GCC_MODEL_TUNING = G5; 226 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 227 | GCC_PREFIX_HEADER = iPing_Prefix.pch; 228 | INFOPLIST_FILE = Info.plist; 229 | INSTALL_PATH = "$(HOME)/Applications"; 230 | PRODUCT_NAME = iPing; 231 | WRAPPER_EXTENSION = app; 232 | }; 233 | name = Release; 234 | }; 235 | C01FCF4F08A954540054247B /* Debug */ = { 236 | isa = XCBuildConfiguration; 237 | buildSettings = { 238 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 239 | GCC_WARN_UNUSED_VARIABLE = YES; 240 | PREBINDING = NO; 241 | SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk"; 242 | }; 243 | name = Debug; 244 | }; 245 | C01FCF5008A954540054247B /* Release */ = { 246 | isa = XCBuildConfiguration; 247 | buildSettings = { 248 | ARCHS = ( 249 | ppc, 250 | i386, 251 | ); 252 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 253 | GCC_WARN_UNUSED_VARIABLE = YES; 254 | PREBINDING = NO; 255 | SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk"; 256 | }; 257 | name = Release; 258 | }; 259 | /* End XCBuildConfiguration section */ 260 | 261 | /* Begin XCConfigurationList section */ 262 | C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "iPing" */ = { 263 | isa = XCConfigurationList; 264 | buildConfigurations = ( 265 | C01FCF4B08A954540054247B /* Debug */, 266 | C01FCF4C08A954540054247B /* Release */, 267 | ); 268 | defaultConfigurationIsVisible = 0; 269 | defaultConfigurationName = Release; 270 | }; 271 | C01FCF4E08A954540054247B /* Build configuration list for PBXProject "iPing" */ = { 272 | isa = XCConfigurationList; 273 | buildConfigurations = ( 274 | C01FCF4F08A954540054247B /* Debug */, 275 | C01FCF5008A954540054247B /* Release */, 276 | ); 277 | defaultConfigurationIsVisible = 0; 278 | defaultConfigurationName = Release; 279 | }; 280 | /* End XCConfigurationList section */ 281 | }; 282 | rootObject = 29B97313FDCFA39411CA2CEA /* Project object */; 283 | } 284 | -------------------------------------------------------------------------------- /34_NSTask/iPing/iPing_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'iPing' target in the 'iPing' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /34_NSTask/iPing/main.m: -------------------------------------------------------------------------------- 1 | int NuMain(int argc, const char *argv[]); 2 | 3 | int main(int argc, const char *argv[]) 4 | { 5 | return NuMain(argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /34_NSTask/iPing/nu/main.nu: -------------------------------------------------------------------------------- 1 | ;; file main.nu 2 | ;; discussion Entry point for a Nu program. 3 | ;; copyright Copyright (c) 2008 Tim Burks, Neon Design Technology, Inc. 4 | 5 | (import Cocoa) ;; bridgesupport 6 | (load "console") ;; interactive console 7 | 8 | (class AppController is NSObject 9 | (ivar (id) outputView (id) hostField (id) startButton (id) task (id) pipe) 10 | 11 | (- (void)startStopPing:(id)sender is 12 | (if @task 13 | (then (@task interrupt)) 14 | (else (set @task ((NSTask alloc) init)) 15 | (@task setLaunchPath:"/sbin/ping") 16 | (@task setArguments:(array "-c10" (@hostField stringValue))) 17 | (set @pipe ((NSPipe alloc) init)) 18 | (@task setStandardOutput:@pipe) 19 | (set fh (@pipe fileHandleForReading)) 20 | (set nc (NSNotificationCenter defaultCenter)) 21 | (nc removeObserver:self) 22 | (nc addObserver:self 23 | selector:"dataReady:" 24 | name:NSFileHandleReadCompletionNotification 25 | object:fh) 26 | (nc addObserver:self 27 | selector:"taskTerminated:" 28 | name:NSTaskDidTerminateNotification 29 | object:@task) 30 | (@task launch) 31 | (@outputView setString:"") 32 | (fh readInBackgroundAndNotify)))) 33 | 34 | (- (void)appendData:(id)d is 35 | (set s ((NSString alloc) initWithData:d encoding:NSUTF8StringEncoding)) 36 | (set ts (@outputView textStorage)) 37 | (ts replaceCharactersInRange:(list (ts length) 0) withString:s)) 38 | 39 | (- (void)dataReady:(id)note is 40 | (set data ((note userInfo) valueForKey:NSFileHandleNotificationDataItem)) 41 | (NSLog "dataReady:#{(data length)}") 42 | (if (data length) 43 | (self appendData:data)) 44 | (if @task 45 | ((@pipe fileHandleForReading) readInBackgroundAndNotify))) 46 | 47 | (- (void)taskTerminated:(id)note is 48 | (NSLog "taskTerminated:") 49 | (set @task nil) 50 | (@startButton setState:0))) 51 | 52 | (set SHOW_CONSOLE_AT_STARTUP nil) 53 | 54 | ;; @class ApplicationDelegate 55 | ;; @discussion Methods of this class perform general-purpose tasks that are not appropriate methods of any other classes. 56 | (class ApplicationDelegate is NSObject 57 | 58 | ;; This method is called after Cocoa has finished its basic application setup. 59 | ;; It instantiates application-specific components. 60 | ;; In this case, it constructs an interactive Nu console that can be activated from the application's Window menu. 61 | (- (void) applicationDidFinishLaunching:(id) sender is 62 | (set $console ((NuConsoleWindowController alloc) init)) 63 | (if SHOW_CONSOLE_AT_STARTUP ($console toggleConsole:self)))) 64 | 65 | ;; install the delegate and keep a reference to it since the application won't retain it. 66 | ((NSApplication sharedApplication) setDelegate:(set $delegate ((ApplicationDelegate alloc) init))) 67 | 68 | ;; this makes the application window take focus when we've started it from the terminal (or with nuke) 69 | ((NSApplication sharedApplication) activateIgnoringOtherApps:YES) 70 | 71 | ;; run the main Cocoa event loop 72 | (NSApplicationMain 0 nil) 73 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | Cocoa Programming with Nu 3 | 4 | This project contains selected examples from the new Third Edition 5 | of Aaron Hillegass' Cocoa Programming for Mac OS X: 6 | 7 | http://www.amazon.com/gp/product/0321503619/ref=neontologycom-20 8 | 9 | Individual directories contain both Xcode projects and Nukefiles. 10 | All examples require Nu (http://programming.nu). 11 | 12 | Contributors, please follow the style used in 28_WebServices/AmaZone. 13 | 14 | Tim Burks 15 | tim@neontology.com 16 | --------------------------------------------------------------------------------