摘要:1#import"BigLetterView.h"234@implementationBigLetterView56-(id)initWithFrame:(NSRect)frameRect7{8if(![superinitWithFrame:frameRect])9{10returnnil;11}1213NSLog(@"initializingview");14bgColor=[[NSColoryellowColor]retain];15string=@"";16returnself;17}1819-(void)dealloc20{2
阅读全文
摘要:When you send an object an -autoreleasemessage, it is added to the currently activeNSAutoreleasePool instance. When thisinstance is destroyed, every object added to itis sent a -release message.The -autorelease message is a deferred-release message. You send it to an objectwhen you no longer need a.
阅读全文
摘要:You can leverage dynamic to create methods that are intended to be usedwith anonymous types. It’s a technique to be used sparingly, like strongspices. If you find yourself creating many methods using dynamic invocationthat are intended for use with anonymous types, that’s a strong indicationthat yo.
阅读全文
摘要:Cast<T>, like all generic methods, compiles with only limited knowledgeof its type parameters. That can lead to generic methods not working theway you’d expect. The root cause is almost always that the generic methodcould not be made aware of particular functionality in the type representingth
阅读全文
摘要:There are also performance costs with using dynamic and with buildingexpressions at runtime. Just like any dynamic type system, your programhas more work to do at runtime because the compiler did not performany of its usual type checking. The compiler must generate instructions toperform all those .
阅读全文
摘要:Exceptions are complicated in any algorithm. Parallel tasks create morecomplications. The Parallel Task Library uses the AggregateException classto hold any and all exceptions thrown somewhere in the depths of yourparallel algorithms. Once any of the background threads throws an exception,any other.
阅读全文
摘要:#import<Foundation/Foundation.h>int(^getCounter(void))(void){__blockintcounter;int(^block)(void)=^(void){returncounter++;};return_Block_copy(block);}intmain(void){int(^block)(void)=getCounter();block();block();NSCAssert(block()==2,@"Blockcountedincorrectly");int(^block2)(void)=getCou
阅读全文
摘要:The Parallel Task Library provides a series of methods that enable workingwith I/O bound operations as well as CPU bound partitions of work.Using the Task class, you can support a variety of asynchronous patternsthat work with I/O bound operations, or those that are a mixture of I/Oand CPU bound op.
阅读全文
摘要:1#import"StretchView.h"234@implementationStretchView56-(id)initWithFrame:(NSRect)rect7{8if(![superinitWithFrame:rect])9{10returnnil;11}1213srandom(time(NULL));1415path=[[NSBezierPathalloc]init];16[pathsetLineWidth:3.0];17NSPointp=[selfrandomPoint];18[pathmoveToPoint:p];19inti;20for(i=0;i&l
阅读全文
摘要:#import"StretchView.h"@implementationStretchView-(id)initWithFrame:(NSRect)rect{if(![superinitWithFrame:rect]){returnnil;}srandom(time(NULL));path=[[NSBezierPathalloc]init];[pathsetLineWidth:3.0];NSPointp=[selfrandomPoint];[pathmoveToPoint:p];inti;for(i=0;i<15;i++){p=[selfrandomPoint];[
阅读全文
摘要:Every parallel query begins with a partitioning step. PLINQ needs to partitionthe input elements and distribute those over the number of taskscreated to perform the query. Partitioning is one of the most importantaspects of PLINQ, so it is important to understand the differentapproaches, how PLINQ .
阅读全文
摘要:1usingSystem;2usingSystem.Collections.Generic;3usingSystem.Linq;4usingSystem.Text;56namespaceEffectiveCSharpItem347{8publicclassB2{}9publicclassD2:B2{}1011publicclassB12{13publicvoidFoo(D2parm)14{15Console.WriteLine("InB.Foo");16}17publicvoidBar(B2parm)18{19Console.WriteLine("InB.Bar&
阅读全文
摘要:Clearly, as you develop and localize many applications, you will develop a set of common translations. It would be handy to have an automated way to get the translated strings into a nib file. This is one of several uses for ibtool. The ibtoolcommand, which is run from the terminal, can list the cl.
阅读全文
摘要:The NSRunAlertPanel() function returns an intthat indicates which button the user clicked. There are global variables for these constants: NSAlertDefaultReturn, NSAlertAlternateReturn, and NSAlertOtherReturn. int NSRunAlertPanel(NSString *title, NSString *msg, NSString *defaultButton, NSString *alt.
阅读全文
摘要:PreferenceControllerCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1#import"PreferenceController.h"234@implementationPreferenceController56NSString*constBNRTableBgColorKey=@"TableBackgroundColor";7NSString*constBNREmptyDocKey=
阅读全文
摘要:codeCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1usingSystem;2usingSystem.Collections.Generic;3usingSystem.Linq;4usingSystem.Text;56namespaceEffectiveCSharpItem337{8classBase9{10publicvoidMagicMethod()11{12Console.WriteLine("magicmethodfr
阅读全文
摘要:The vector is intentionally made to look like a souped-up array, since it has array-styleindexing but also can expand dynamically. vector is so fundamentally useful that it wasintroduced in a very primitive way early in this book, and used quite regularly in previousexamples. This section will give.
阅读全文
摘要:Every application comes with a set of defaults from the factory. When a user edits his or her defaults, only the differences between the user's wishes and the factory defaults are stored in the user's defaults database. Thus, every time the application starts up, you need to remind it of the
阅读全文
摘要:ICloneable does have its use, but it is the exception rather than rule. It’s significantthat the .NET Framework did not add an ICloneable<T> when itwas updated with generic support. You should never add support forICloneable to value types; use the assignment operation instead. Youshould
阅读全文
摘要:IComparable and IComparer are the standard mechanisms for providingordering relations for your types. IComparable should be used for themost natural ordering. When you implement IComparable, you shouldoverload the comparison operators (<, >, <=, >=) consistently with ourIComparable order
阅读全文
摘要:PreferenceControllerCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1#import"PreferenceController.h"234@implementationPreferenceController56-(id)init7{8if(![superinitWithWindowNibName:@"Preferences"])9{10returnnil;11}1213returnself;14}1516-(void)w
阅读全文
摘要:When you have one function that handles one event in a derived class, theoverride is the better approach. It is easier to maintain, more likely to becorrect over time, and more efficient. Reserve the event handlers for otheruses. Prefer overriding the base class implementation to attaching an eventh
阅读全文
摘要:It certainly can get complicated describing exactly how covariance andcontravariance work. Thankfully, now the language supports decoratinggeneric interfaces and delegates with in (contravariant) and out (covariant)modifiers. You should decorate any interfaces and delegates you definewith the in or
阅读全文
摘要:The .NET Framework provides a simple, standard algorithm for serializingyour objects. If your type should be persisted, you should follow thestandard implementation. If you don’t support serialization in your types,other classes that use your type can’t support serialization, either. Mak
阅读全文
摘要:You built the interfaceto your class, and you want users to follow it. You don’t want users to accessor modify the internal state of your objects without your knowledge.You’ve got four different strategies for protecting your internal data structuresfrom unintended modifications: value t
阅读全文
摘要:Events provide a standard syntax for notifying listeners. The .NET EventPattern follows the event syntax to implement the Observer Pattern. Anynumber of clients can attach handlers to the events and process them.Those clients need not be known at compile time. Events don’t need subscribersfor
阅读全文
摘要:Apple decided to make this type of application extremely easy to write: NSArrayControllerwill hold on to an array of objects. Bindings will eliminate much of the glue code that would be necessary to keep the model objects in sync with the views. NSManagedObjectContextwill observe the instance v
阅读全文
摘要:The key() function returns a node-set from the document, using the index specified by an <xsl:key> element.cdcatalog.xmlCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1<?xmlversion="1.0"encoding="ISO-8859-1"?>2<!--EditedbyXMLSpy®
阅读全文
摘要:One protocol is NSCoding. If your class implements NSCoding, it promises to implement the following methods: An NSCoderis an abstraction of a stream of bytes. You can write your data to a coder or read your data from a coder. TheinitWithCoder:method in your object will read data from the coder a
阅读全文
摘要:DocumentCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1//2//MyDocument.m3//RaiseMan4//5//Createdbyb1mobileon2/14/11.6//Copyright2011__MyCompanyName__.Allrightsreserved.7//89#import"MyDocument.h"10#import"Person.h"1112@implementationMyDocument1314-(
阅读全文
摘要:Delegates provide the best way to utilize callbacks at runtime, with simplerrequirements on client classes. You can configure delegate targets at runtime.You can support multiple client targets. Client callbacks should beimplemented using delegates in .NET.
阅读全文
摘要:codeCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1usingSystem;2usingSystem.Collections.Generic;3usingSystem.Linq;4usingSystem.Text;56namespaceEffectiveCSharpItem237{8interfaceIMsg9{10voidMessage();11}1213publicclassMyClass:IMsg14{15publicvoidMessa
阅读全文
摘要:PersonCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1#import"Person.h"234@implementationPerson56-(id)init7{8[superinit];9expectedRaise=5.0;10personName=@"NewPerson";11returnself;12}1314-(void)dealloc15{16[personNamerelease];1
阅读全文
摘要:Base classes describe and implement common behaviors across relatedconcrete types. Interfaces describe atomic pieces of functionality that unrelatedconcrete types can implement. Both have their place. Classes definethe types you create. Interfaces describe the behavior of those types aspieces of fun
阅读全文
摘要:codeCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1importsys2importstring34CHAR_MAP=dict(zip(string.ascii_lowercase,string.ascii_lowercase[13:26]+5string.ascii_lowercase[0:13]))67defrotate13_letter(letter):8"""9Returnthe13-charrot
阅读全文
摘要:Those classes and interfaces that you expose publicly to the outside worldare your contract: You must live up to them. The more cluttered that interfaceis, the more constrained your future direction is. The fewer publictypes you expose, the more options you have to extend and modify anyimplementatio
阅读全文
摘要:Immutable types are simpler to code and easier to maintain. Don’t blindly create get and set accessors for every property in your type. Your first choice for types that store data should be immutable, atomic value types. You easily can build more complicated structures from these entities.
阅读全文
摘要:To invoke a template by name, two things have to happen: • The template you want to invoke has to have a name. • You use the <xsl:call-template> element to invoke the named template. The XSLT <xsl:template> element has a mode attribute that lets you pr
阅读全文
摘要:[代码]AppController.mCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1#import"AppController.h"23@implementationAppController45-(id)init6{7[superinit];8[selfsetValue:[NSNumbernumberWithInt:5]forKey:@"fido"];9NSNumber*n=[selfvalueF
阅读全文
摘要:The system initializes all instances of value types to 0. There is no way toprevent users from creating instances of value types that are all 0s. If possible,make the all 0 case the natural default. As a special case, enums usedas flags should ensure that 0 is the absence of all flags.
阅读全文
摘要:The Garbage Collector does an efficient job of managing the memory thatyour application uses. But remember that creating and destroying heapobjects still takes time. Avoid creating excessive objects; don’t create whatyou don’t need. Also avoid creating multiple objects of referen
阅读全文