1 line
18 KiB
JSON
Raw Normal View History

{"kind":"article","variants":[{"paths":["\/documentation\/slothcreator\/gettingstarted"],"traits":[{"interfaceLanguage":"swift"}]}],"schemaVersion":{"major":0,"minor":3,"patch":0},"identifier":{"interfaceLanguage":"swift","url":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/GettingStarted"},"primaryContentSections":[{"kind":"content","content":[{"level":2,"type":"heading","text":"Overview","anchor":"Overview"},{"type":"paragraph","inlineContent":[{"type":"text","text":"Sloths are complex creatures that require careful creation and a suitable habitat. After creating a sloth, youre responsible for feeding them, providing fulfilling activities, and giving them opportunities to exercise and rest."}]},{"type":"paragraph","inlineContent":[{"type":"text","text":"Every sloth has a "},{"type":"reference","isActive":true,"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Sloth\/name"},{"type":"text","text":" and "},{"type":"reference","identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Sloth\/color-swift.property","isActive":true},{"text":". You can optionally provide a ","type":"text"},{"type":"reference","isActive":true,"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Sloth\/power-swift.property"},{"text":" if your sloth has special supernatural abilities.","type":"text"}]},{"type":"paragraph","inlineContent":[{"identifier":"slothPower.png","type":"image"}]},{"type":"heading","level":3,"anchor":"Create-a-Sloth","text":"Create a Sloth"},{"inlineContent":[{"text":"To create a standard sloth without any special supernatural powers, you initialize a new instance of the ","type":"text"},{"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Sloth","type":"reference","isActive":true},{"text":" structure, and supply a name and a color, as the following code shows:","type":"text"}],"type":"paragraph"},{"syntax":"swift","type":"codeListing","code":["var sloth = Sloth(name: \"Super Sloth\", color: .blue, power: .none)"]},{"type":"paragraph","inlineContent":[{"text":"If your sloth possesses one of the special powers of ","type":"text"},{"type":"codeVoice","code":"ice"},{"type":"text","text":", "},{"code":"fire","type":"codeVoice"},{"text":", ","type":"text"},{"code":"wind","type":"codeVoice"},{"text":", or ","type":"text"},{"type":"codeVoice","code":"lightning"},{"type":"text","text":", you can specify this at creation:"}]},{"code":["var superSloth = Sloth(name: \"Silly Sloth\", color: .green, power: .lightning)"],"type":"codeListing","syntax":"swift"},{"type":"paragraph","inlineContent":[{"text":"If youre creating a large number of sloths, you can define your own random name generator that conforms to the ","type":"text"},{"isActive":true,"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/NameGenerator","type":"reference"},{"type":"text","text":" protocol, and use it to generate names:"}]},{"type":"codeListing","syntax":"swift","code":["let slothNamer = MyCustomSlothNamer()","var sloths: [Sloth] = []","","for _ in 0...100 {"," let name = slothNamer.generateName(seed: 0)"," var sloth = Sloth(name: name, color: .green, power: .ice)"," "," sloths.append(sloth)","}"]},{"level":3,"text":"Provide a Habitat","type":"heading","anchor":"Provide-a-Habitat"},{"type":"paragraph","inlineContent":[{"text":"Sloths thrive in comfortable habitats. To create a sloth-friendly habitat, you specify whether its humid, warm, or both. The following listing creates a habitat thats humid and warm, which results in a high ","type":"text"},{"identifier":"doc:\/\/slothcreatorbuildingdoccdocumentationinxcode-2.SlothCreator\/documentation\/SlothCreator\/Habitat\/comfortLevel","isActive":true,"type":"reference"},{"type":"text","text":":"}]},{"code":["let lovelyHabitat = Habitat(isHumid: true, isWa