{"id":380571,"date":"2024-06-29T03:10:19","date_gmt":"2024-06-29T03:10:19","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=380571"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=380571","title":{"rendered":"<span>OptionSet \u0432 \u0434\u0435\u0442\u0430\u043b\u044f\u0445<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0439 \u0442\u0438\u043f <a href=\"https:\/\/developer.apple.com\/documentation\/Swift\/OptionSet-swift.protocol\">OptionSet<\/a> \u0432 Swift \u043a\u0440\u043e\u0435\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e. \u0427\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0434\u0435\u0442\u0430\u043b\u044f\u0445, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f OptionSet \u0432 Apple SDK \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 <code>animateWithDuration:<\/code> \u0443 UIView \u0435\u0441\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0442\u0438\u043f\u0430 <code>AnimationOptions<\/code> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d \u043f\u0443\u0441\u0442\u044b\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c.\u00a0<\/p>\n<pre><code class=\"swift\">func animate(     withDuration duration: TimeInterval,      delay: TimeInterval,      options: UIView.AnimationOptions = [],      animations: @escaping () -> Void,      completion: ((Bool) -> Void)? = nil )  UIView.animate(     withDuration: 0,     delay: 0,     options: [.allowUserInteraction, .autoreverse],     animations: {} )<\/code><\/pre>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0436\u0435 \u043d\u0430\u0431\u043e\u0440 \u043e\u043f\u0446\u0438\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c \u0430 \u043d\u0435 \u0441\u0435\u0442\u043e\u043c (Set) \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0432 \u044d\u0442\u043e\u043c!<\/p>\n<p><code>OptionSet<\/code> \u0432 Swift \u043d\u0435\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445, \u0435\u0433\u043e \u043f\u0440\u043e\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c Bool \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c <code>OptionSet<\/code> \u043e\u043f\u0446\u0438\u0439 \u0434\u043e\u0431\u0430\u0432\u043e\u043a \u043a \u043f\u0438\u0446\u0446\u0435:\u00a0<\/p>\n<ul>\n<li>\n<p>\u0414\u0432\u043e\u0439\u043d\u0430\u044f \u043f\u043e\u0440\u0446\u0438\u044f \u0441\u044b\u0440\u0430<\/p>\n<\/li>\n<li>\n<p>\u0421\u044b\u0440\u043d\u044b\u0439 \u0431\u043e\u0440\u0442\u0438\u043a<\/p>\n<\/li>\n<li>\n<p>\u0411\u0435\u043b\u044b\u0439 \u0441\u043e\u0443\u0441<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0443\u0441 \u0431\u0430\u0440\u0431\u0435\u043a\u044e<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 4 \u0431\u0438\u0442\u0430\u0445: <code>_ _ _ _<\/code> \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 1 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u043f\u0446\u0438\u0438, \u0430 0 \u0431\u0435\u0437 \u043e\u043f\u0446\u0438\u0438. \u041d\u0430\u0431\u043e\u0440 \u0431\u0438\u0442 <code>0 0 0 0<\/code> \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043f\u0438\u0446\u0446\u0435 \u0431\u0435\u0437 \u0434\u043e\u0431\u0430\u0432\u043e\u043a \u0430 <code>1 1 1 1<\/code> \u043f\u0438\u0446\u0446\u0435 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0434\u043e\u0431\u0430\u0432\u043a\u0430\u043c\u0438.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0437\u043d\u0430\u044f \u0434\u0432\u043e\u0438\u0447\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0434\u0432\u043e\u0439\u043a\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043a\u0438 \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438<\/p>\n<ul>\n<li>\n<p>\u0414\u0432\u043e\u0439\u043d\u0430\u044f \u043f\u043e\u0440\u0446\u0438\u044f \u0441\u044b\u0440\u0430 \/\/ 0001 == 1<\/p>\n<\/li>\n<li>\n<p>\u0421\u044b\u0440\u043d\u044b\u0439 \u0431\u043e\u0440\u0442\u0438\u043a.           \/\/ 0010 == 2<\/p>\n<\/li>\n<li>\n<p>\u0411\u0435\u043b\u044b\u0439 \u0441\u043e\u0443\u0441                    \/\/ 0100 == 4<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0443\u0441 \u0431\u0430\u0440\u0431\u0435\u043a\u044e               \/\/ 1000 == 8<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 Swift \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"swift\">struct PizzaOptions: OptionSet {     static let extraCheese = PizzaOptions(rawValue: 1) \/\/ 0001     static let cheeseSide = PizzaOptions(rawValue: 2)  \/\/ 0010     static let whiteSause = PizzaOptions(rawValue: 4)  \/\/ 0100     static let bbqSause = PizzaOptions(rawValue: 8)    \/\/ 1000      let rawValue: Int8 }<\/code><\/pre>\n<p>\u041d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u0434\u0432\u043e\u0439\u043a\u0438 \u043d\u0435 \u0443\u0434\u043e\u0431\u043d\u043e, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u0441\u043b\u0435 12-\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435\u0433\u0434\u0430 1 \u0438 \u201c\u0441\u0434\u0432\u0438\u0433\u0430\u0442\u044c\u201d \u0431\u0438\u0442\u044b \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>&lt;&lt;<\/code>.<\/p>\n<pre><code class=\"swift\">struct PizzaOptions: OptionSet {     static let extraCheese = PizzaOptions(rawValue: 1)     \/\/ 0001     static let cheeseSide = PizzaOptions(rawValue: 1 &lt;&lt; 1) \/\/ 0010     static let whiteSause = PizzaOptions(rawValue: 1 &lt;&lt; 2) \/\/ 0100     static let bbqSause = PizzaOptions(rawValue: 1 &lt;&lt; 3)   \/\/ 1000      let rawValue: Int8 }<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0431\u0438\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u043e\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"swift\">let one = 0b00000001 print(one == 1)      \/\/ true print(one &lt;&lt; 1 == 2) \/\/ true print(one &lt;&lt; 2 == 4) \/\/ true print(one &lt;&lt; 2 == 0b00000100) \/\/ true<\/code><\/pre>\n<p>\u041d\u043e \u043f\u043e\u043a\u0430 \u043c\u044b \u043d\u0435 \u043e\u0442\u0432\u0435\u0442\u0438\u043b\u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Option<strong>Set<\/strong>, \u0430 \u0434\u0435\u043b\u043e \u043a\u0440\u043e\u0435\u0442\u0441\u044f \u0432 \u043c\u0430\u0433\u0438\u0438 \u0430\u043b\u0433\u0435\u0431\u0440\u044b \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432. \u0427\u0442\u043e \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u0441 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f? \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u0434\u043e\u0431\u0430\u0432\u043a\u0438 \u0435\u0441\u0442\u044c \u0432 2 \u043f\u0438\u0446\u0446\u0430\u0445 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>union<\/code>:<\/p>\n<pre><code class=\"swift\">let first: PizzaOptions = .whiteSause let second: PizzaOptions = [.bbqSause, .extraCheese] print(first)  \/\/ 4 print(second) \/\/ 9 print(first.union(second))  \/\/ 13 print(first.intersection(second)) \/\/ 0<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u043a\u0430 \u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0435 \u043d\u0435 \u0441\u0442\u0430\u043b\u043e, \u044d\u0442\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e. \u041c\u044b \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438 \u0443\u0436\u0435 \u043e\u0442\u043a\u0443\u0434\u0430 4, \u043d\u043e \u043e\u0442\u043a\u0443\u0434\u0430 \u0432\u0437\u044f\u043b\u043e\u0441\u044c 9 \u0438 \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 13?<\/p>\n<p>\u0421\u0443\u0442\u044c \u0432 \u0431\u0438\u0442\u043e\u0432\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438:<\/p>\n<p><code>PizzaOptions.whiteSouse<\/code> \u044d\u0442\u043e 4 \u0438\u043b\u0438 \u0432 \u043d\u0430\u0448\u0435\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u043e\u0431\u0430\u0432\u043e\u043a \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0430 \u043e\u0434\u043d\u0430 \u044f\u0447\u0435\u0439\u043a\u0430 <code>0 1 0 0<\/code>\u00a0\u0432 \u0431\u0438\u0442\u043e\u0432\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438.<\/p>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u0438\u0446\u0446\u0435 \u0437\u0430\u043a\u0430\u0437\u0430\u043b\u0438 <code>.bbqSause<\/code> \u0438 <code>.extraCheese<\/code> \u0438\u043b\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0438\u043d\u0433\u0440\u0438\u0434\u0438\u0435\u043d\u0442\u044b. \u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c: <code>1 0 0 1<\/code>, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0432 \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u044d\u0442\u043e 9.<\/p>\n<p>\u0414\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u043f\u0435\u0440\u0432\u044b\u0439 <code>0 1 0 0<\/code> \u0438 \u0432\u0442\u043e\u0440\u043e\u0439 <code>1 0 0 1<\/code> \u043d\u0430\u0431\u043e\u0440 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f <code>1 1 0 1<\/code> \u0438 \u044d\u0442\u043e \u043a\u0430\u043a \u0440\u0430\u0437 13!<\/p>\n<h2>\u0412\u044b\u0432\u043e\u0434<\/h2>\n<p>\u041f\u043e\u0434\u0432\u043e\u0434\u044f \u0438\u0442\u043e\u0433\u0438, \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0447\u0442\u043e <code>OptionSet<\/code> \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0440\u0435\u0434\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043d\u0430\u0434\u0435\u044e\u0441\u044c \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u0432 \u043d\u0435\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c, \u0432\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435 \u0432\u0441\u0435 \u0435\u0433\u043e \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430. \u041e\u043d \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0441\u0436\u0430\u0442\u0438\u044f \u043f\u043e\u043b\u0435\u0439 \u0432 Json \u0430 \u0442\u0430\u043a \u0436\u0435 \u0434\u043b\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u0432\u0430\u0448\u0438\u0445 API \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0442.\u043a. \u043c\u043e\u0436\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u043c\u0438. \u041c\u0435\u0442\u043e\u0434\u044b <code>union<\/code>, <code>intersection<\/code>, <code>symmetricDifference<\/code>, <code>contains<\/code>, <code>insert<\/code>, <code>remove<\/code>, \u0432\u0441\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 <code>OptionSet<\/code> \u0442\u0430\u043a \u0436\u0435 \u043a\u0430\u043a \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 <code>Set<\/code>.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/750162\/\"> https:\/\/habr.com\/ru\/articles\/750162\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u044b\u0439 \u0442\u0438\u043f <a href=\"https:\/\/developer.apple.com\/documentation\/Swift\/OptionSet-swift.protocol\">OptionSet<\/a> \u0432 Swift \u043a\u0440\u043e\u0435\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e. \u0427\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0434\u0435\u0442\u0430\u043b\u044f\u0445, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f OptionSet \u0432 Apple SDK \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 <code>animateWithDuration:<\/code> \u0443 UIView \u0435\u0441\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0442\u0438\u043f\u0430 <code>AnimationOptions<\/code> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d \u043f\u0443\u0441\u0442\u044b\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c.\u00a0<\/p>\n<pre><code class=\"swift\">func animate(     withDuration duration: TimeInterval,      delay: TimeInterval,      options: UIView.AnimationOptions = [],      animations: @escaping () -> Void,      completion: ((Bool) -> Void)? = nil )  UIView.animate(     withDuration: 0,     delay: 0,     options: [.allowUserInteraction, .autoreverse],     animations: {} )<\/code><\/pre>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0436\u0435 \u043d\u0430\u0431\u043e\u0440 \u043e\u043f\u0446\u0438\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c \u0430 \u043d\u0435 \u0441\u0435\u0442\u043e\u043c (Set) \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0432 \u044d\u0442\u043e\u043c!<\/p>\n<p><code>OptionSet<\/code> \u0432 Swift \u043d\u0435\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445, \u0435\u0433\u043e \u043f\u0440\u043e\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c Bool \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c <code>OptionSet<\/code> \u043e\u043f\u0446\u0438\u0439 \u0434\u043e\u0431\u0430\u0432\u043e\u043a \u043a \u043f\u0438\u0446\u0446\u0435:\u00a0<\/p>\n<ul>\n<li>\n<p>\u0414\u0432\u043e\u0439\u043d\u0430\u044f \u043f\u043e\u0440\u0446\u0438\u044f \u0441\u044b\u0440\u0430<\/p>\n<\/li>\n<li>\n<p>\u0421\u044b\u0440\u043d\u044b\u0439 \u0431\u043e\u0440\u0442\u0438\u043a<\/p>\n<\/li>\n<li>\n<p>\u0411\u0435\u043b\u044b\u0439 \u0441\u043e\u0443\u0441<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0443\u0441 \u0431\u0430\u0440\u0431\u0435\u043a\u044e<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 4 \u0431\u0438\u0442\u0430\u0445: <code>_ _ _ _<\/code> \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 1 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u043f\u0446\u0438\u0438, \u0430 0 \u0431\u0435\u0437 \u043e\u043f\u0446\u0438\u0438. \u041d\u0430\u0431\u043e\u0440 \u0431\u0438\u0442 <code>0 0 0 0<\/code> \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043f\u0438\u0446\u0446\u0435 \u0431\u0435\u0437 \u0434\u043e\u0431\u0430\u0432\u043e\u043a \u0430 <code>1 1 1 1<\/code> \u043f\u0438\u0446\u0446\u0435 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0434\u043e\u0431\u0430\u0432\u043a\u0430\u043c\u0438.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0437\u043d\u0430\u044f \u0434\u0432\u043e\u0438\u0447\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0434\u0432\u043e\u0439\u043a\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043a\u0438 \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438<\/p>\n<ul>\n<li>\n<p>\u0414\u0432\u043e\u0439\u043d\u0430\u044f \u043f\u043e\u0440\u0446\u0438\u044f \u0441\u044b\u0440\u0430 \/\/ 0001 == 1<\/p>\n<\/li>\n<li>\n<p>\u0421\u044b\u0440\u043d\u044b\u0439 \u0431\u043e\u0440\u0442\u0438\u043a.           \/\/ 0010 == 2<\/p>\n<\/li>\n<li>\n<p>\u0411\u0435\u043b\u044b\u0439 \u0441\u043e\u0443\u0441                    \/\/ 0100 == 4<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0443\u0441 \u0431\u0430\u0440\u0431\u0435\u043a\u044e               \/\/ 1000 == 8<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 Swift \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"swift\">struct PizzaOptions: OptionSet {     static let extraCheese = PizzaOptions(rawValue: 1) \/\/ 0001     static let cheeseSide = PizzaOptions(rawValue: 2)  \/\/ 0010     static let whiteSause = PizzaOptions(rawValue: 4)  \/\/ 0100     static let bbqSause = PizzaOptions(rawValue: 8)    \/\/ 1000      let rawValue: Int8 }<\/code><\/pre>\n<p>\u041d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u0434\u0432\u043e\u0439\u043a\u0438 \u043d\u0435 \u0443\u0434\u043e\u0431\u043d\u043e, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u0441\u043b\u0435 12-\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435\u0433\u0434\u0430 1 \u0438 \u201c\u0441\u0434\u0432\u0438\u0433\u0430\u0442\u044c\u201d \u0431\u0438\u0442\u044b \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>&lt;&lt;<\/code>.<\/p>\n<pre><code class=\"swift\">struct PizzaOptions: OptionSet {     static let extraCheese = PizzaOptions(rawValue: 1)     \/\/ 0001     static let cheeseSide = PizzaOptions(rawValue: 1 &lt;&lt; 1) \/\/ 0010     static let whiteSause = PizzaOptions(rawValue: 1 &lt;&lt; 2) \/\/ 0100     static let bbqSause = PizzaOptions(rawValue: 1 &lt;&lt; 3)   \/\/ 1000      let rawValue: Int8 }<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0431\u0438\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u043e\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"swift\">let one = 0b00000001 print(one == 1)      \/\/ true print(one &lt;&lt; 1 == 2) \/\/ true print(one &lt;&lt; 2 == 4) \/\/ true print(one &lt;&lt; 2 == 0b00000100) \/\/ true<\/code><\/pre>\n<p>\u041d\u043e \u043f\u043e\u043a\u0430 \u043c\u044b \u043d\u0435 \u043e\u0442\u0432\u0435\u0442\u0438\u043b\u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Option<strong>Set<\/strong>, \u0430 \u0434\u0435\u043b\u043e \u043a\u0440\u043e\u0435\u0442\u0441\u044f \u0432 \u043c\u0430\u0433\u0438\u0438 \u0430\u043b\u0433\u0435\u0431\u0440\u044b \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432. \u0427\u0442\u043e \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u0441 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f? \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u0434\u043e\u0431\u0430\u0432\u043a\u0438 \u0435\u0441\u0442\u044c \u0432 2 \u043f\u0438\u0446\u0446\u0430\u0445 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>union<\/code>:<\/p>\n<pre><code class=\"swift\">let first: PizzaOptions = .whiteSause let second: PizzaOptions = [.bbqSause, .extraCheese] print(first)  \/\/ 4 print(second) \/\/ 9 print(first.union(second))  \/\/ 13 print(first.intersection(second)) \/\/ 0<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u043a\u0430 \u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0435 \u043d\u0435 \u0441\u0442\u0430\u043b\u043e, \u044d\u0442\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e. \u041c\u044b \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438 \u0443\u0436\u0435 \u043e\u0442\u043a\u0443\u0434\u0430 4, \u043d\u043e \u043e\u0442\u043a\u0443\u0434\u0430 \u0432\u0437\u044f\u043b\u043e\u0441\u044c 9 \u0438 \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 13?<\/p>\n<p>\u0421\u0443\u0442\u044c \u0432 \u0431\u0438\u0442\u043e\u0432\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438:<\/p>\n<p><code>PizzaOptions.whiteSouse<\/code> \u044d\u0442\u043e 4 \u0438\u043b\u0438 \u0432 \u043d\u0430\u0448\u0435\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u043e\u0431\u0430\u0432\u043e\u043a \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0430 \u043e\u0434\u043d\u0430 \u044f\u0447\u0435\u0439\u043a\u0430 <code>0 1 0 0<\/code>\u00a0\u0432 \u0431\u0438\u0442\u043e\u0432\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438.<\/p>\n<p>\u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u0438\u0446\u0446\u0435 \u0437\u0430\u043a\u0430\u0437\u0430\u043b\u0438 <code>.bbqSause<\/code> \u0438 <code>.extraCheese<\/code> \u0438\u043b\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0438\u043d\u0433\u0440\u0438\u0434\u0438\u0435\u043d\u0442\u044b. \u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c: <code>1 0 0 1<\/code>, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0432 \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u044d\u0442\u043e 9.<\/p>\n<p>\u0414\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u043f\u0435\u0440\u0432\u044b\u0439 <code>0 1 0 0<\/code> \u0438 \u0432\u0442\u043e\u0440\u043e\u0439 <code>1 0 0 1<\/code> \u043d\u0430\u0431\u043e\u0440 \u0438\u043d\u0433\u0440\u0435\u0434\u0438\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f <code>1 1 0 1<\/code> \u0438 \u044d\u0442\u043e \u043a\u0430\u043a \u0440\u0430\u0437 13!<\/p>\n<h2>\u0412\u044b\u0432\u043e\u0434<\/h2>\n<p>\u041f\u043e\u0434\u0432\u043e\u0434\u044f \u0438\u0442\u043e\u0433\u0438, \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0447\u0442\u043e <code>OptionSet<\/code> \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0440\u0435\u0434\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043d\u0430\u0434\u0435\u044e\u0441\u044c \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u0432 \u043d\u0435\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c, \u0432\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435 \u0432\u0441\u0435 \u0435\u0433\u043e \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430. \u041e\u043d \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0441\u0436\u0430\u0442\u0438\u044f \u043f\u043e\u043b\u0435\u0439 \u0432 Json \u0430 \u0442\u0430\u043a \u0436\u0435 \u0434\u043b\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u0432\u0430\u0448\u0438\u0445 API \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0442.\u043a. \u043c\u043e\u0436\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\u043c\u0438. \u041c\u0435\u0442\u043e\u0434\u044b <code>union<\/code>, <code>intersection<\/code>, <code>symmetricDifference<\/code>, <code>contains<\/code>, <code>insert<\/code>, <code>remove<\/code>, \u0432\u0441\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 <code>OptionSet<\/code> \u0442\u0430\u043a \u0436\u0435 \u043a\u0430\u043a \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 <code>Set<\/code>.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/750162\/\"> https:\/\/habr.com\/ru\/articles\/750162\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-380571","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/380571","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=380571"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/380571\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=380571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=380571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=380571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}